Shaka Player Embedded
transaction.h
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_JS_IDB_TRANSACTION_H_
16 #define SHAKA_EMBEDDED_JS_IDB_TRANSACTION_H_
17 
18 #include <list>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "src/core/member.h"
24 #include "src/core/ref_ptr.h"
26 #include "src/js/idb/sqlite.h"
28 #include "src/mapping/enum.h"
30 
31 namespace shaka {
32 namespace js {
33 
34 namespace dom {
35 class DOMException;
36 } // namespace dom
37 
38 namespace idb {
39 
40 class IDBDatabase;
41 class IDBObjectStore;
42 class IDBRequest;
43 
44 enum class IDBTransactionMode {
45  READ_ONLY,
46  READ_WRITE,
48 };
49 
52 
53  public:
55  const std::vector<std::string>& scope);
56 
57  void Trace(memory::HeapTracer* tracer) const override;
58 
59  ExceptionOr<RefPtr<IDBObjectStore>> ObjectStore(const std::string name);
60  ExceptionOr<void> Abort();
61 
62  RefPtr<IDBRequest> AddRequest(RefPtr<IDBRequest> request);
63 
69  void DoCommit(SqliteConnection* connection);
70  void DoCommit(SqliteTransaction* transaction);
71 
72  void AddObjectStore(const std::string& name);
73  void DeleteObjectStore(const std::string& name);
74 
78 
82  bool aborted;
83  bool active;
84  bool done;
85 
86  // If this is a version change transaction, this is the stored transaction
87  // object. This is only valid while the transaction is "active".
89 
90  private:
91  // This must be a list to ensure existing iterators aren't invalidated when
92  // inserting.
93  std::list<Member<IDBRequest>> requests_;
94 
95  std::unordered_map<std::string, Member<IDBObjectStore>> scope_;
96 };
97 
99  : public BackingObjectFactory<IDBTransaction, events::EventTarget> {
100  public:
102 };
103 
104 } // namespace idb
105 } // namespace js
106 } // namespace shaka
107 
109  AddMapping(Enum::READ_ONLY, "readonly");
110  AddMapping(Enum::READ_WRITE, "readwrite");
111  AddMapping(Enum::VERSION_CHANGE, "versionchange");
112 }
113 
114 #endif // SHAKA_EMBEDDED_JS_IDB_TRANSACTION_H_
const char * name
SqliteTransaction * sqlite_transaction
Definition: transaction.h:88
Member< dom::DOMException > error
Definition: transaction.h:80
const Member< IDBDatabase > db
Definition: transaction.h:79
#define DECLARE_TYPE_INFO(type)
const IDBTransactionMode mode
Definition: transaction.h:81
DEFINE_ENUM_MAPPING(shaka::js::idb, IDBTransactionMode)
Definition: transaction.h:108