OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_IMPL_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <map> |
| 10 #include <vector> |
| 11 |
| 12 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" |
| 13 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 14 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
| 15 #include "content/browser/indexed_db/list_set.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 class IndexedDBBackingStore; |
| 20 class IndexedDBDatabase; |
| 21 class IndexedDBFactoryImpl; |
| 22 class IndexedDBTransaction; |
| 23 |
| 24 class IndexedDBDatabaseImpl : public IndexedDBDatabase { |
| 25 public: |
| 26 static scoped_refptr<IndexedDBDatabaseImpl> Create( |
| 27 const string16& name, |
| 28 IndexedDBBackingStore* database, |
| 29 IndexedDBFactoryImpl*, |
| 30 const string16& unique_identifier); |
| 31 scoped_refptr<IndexedDBBackingStore> BackingStore() const; |
| 32 |
| 33 static const int64_t kInvalidId = 0; |
| 34 int64_t id() const { return metadata_.id; } |
| 35 void AddObjectStore(const IndexedDBObjectStoreMetadata&, |
| 36 int64_t new_max_object_store_id); |
| 37 void RemoveObjectStore(int64_t object_store_id); |
| 38 void AddIndex(int64_t object_store_id, |
| 39 const IndexedDBIndexMetadata&, |
| 40 int64_t new_max_index_id); |
| 41 void RemoveIndex(int64_t object_store_id, int64_t index_id); |
| 42 |
| 43 void OpenConnection(scoped_refptr<IndexedDBCallbacksWrapper>, |
| 44 scoped_refptr<IndexedDBDatabaseCallbacksWrapper>, |
| 45 int64_t transaction_id, |
| 46 int64_t version); |
| 47 void DeleteDatabase(scoped_refptr<IndexedDBCallbacksWrapper>); |
| 48 const IndexedDBDatabaseMetadata& metadata() const { return metadata_; } |
| 49 |
| 50 // IndexedDBDatabase |
| 51 virtual void CreateObjectStore(int64_t transaction_id, |
| 52 int64_t object_store_id, |
| 53 const string16& name, |
| 54 const IndexedDBKeyPath&, |
| 55 bool auto_increment) OVERRIDE; |
| 56 virtual void DeleteObjectStore(int64_t transaction_id, |
| 57 int64_t object_store_id) OVERRIDE; |
| 58 virtual void CreateTransaction( |
| 59 int64_t transaction_id, |
| 60 scoped_refptr<IndexedDBDatabaseCallbacksWrapper>, |
| 61 const std::vector<int64_t>& object_store_ids, |
| 62 unsigned short mode) OVERRIDE; |
| 63 virtual void Close(scoped_refptr<IndexedDBDatabaseCallbacksWrapper>) OVERRIDE; |
| 64 |
| 65 virtual void Commit(int64_t transaction_id) OVERRIDE; |
| 66 virtual void Abort(int64_t transaction_id) OVERRIDE; |
| 67 virtual void Abort(int64_t transaction_id, |
| 68 scoped_refptr<IndexedDBDatabaseError>) OVERRIDE; |
| 69 |
| 70 virtual void CreateIndex(int64_t transaction_id, |
| 71 int64_t object_store_id, |
| 72 int64_t index_id, |
| 73 const string16& name, |
| 74 const IndexedDBKeyPath&, |
| 75 bool unique, |
| 76 bool multi_entry) OVERRIDE; |
| 77 virtual void DeleteIndex(int64_t transaction_id, |
| 78 int64_t object_store_id, |
| 79 int64_t index_id) OVERRIDE; |
| 80 |
| 81 IndexedDBTransactionCoordinator& transaction_coordinator() { |
| 82 return transaction_coordinator_; |
| 83 } |
| 84 |
| 85 void TransactionStarted(IndexedDBTransaction* transaction); |
| 86 void TransactionFinished(IndexedDBTransaction* transaction); |
| 87 void TransactionFinishedAndCompleteFired(IndexedDBTransaction* transaction); |
| 88 void TransactionFinishedAndAbortFired(IndexedDBTransaction* transaction); |
| 89 |
| 90 virtual void Get(int64_t transaction_id, |
| 91 int64_t object_store_id, |
| 92 int64_t index_id, |
| 93 scoped_ptr<IndexedDBKeyRange>, |
| 94 bool key_only, |
| 95 scoped_refptr<IndexedDBCallbacksWrapper>) OVERRIDE; |
| 96 virtual void Put(int64_t transaction_id, |
| 97 int64_t object_store_id, |
| 98 std::vector<char>* value, |
| 99 scoped_ptr<IndexedDBKey>, |
| 100 PutMode, |
| 101 scoped_refptr<IndexedDBCallbacksWrapper>, |
| 102 const std::vector<int64_t>& index_ids, |
| 103 const std::vector<IndexKeys>&) OVERRIDE; |
| 104 virtual void SetIndexKeys(int64_t transaction_id, |
| 105 int64_t object_store_id, |
| 106 scoped_ptr<IndexedDBKey> primary_key, |
| 107 const std::vector<int64_t>& index_ids, |
| 108 const std::vector<IndexKeys>&) OVERRIDE; |
| 109 virtual void SetIndexesReady(int64_t transaction_id, |
| 110 int64_t object_store_id, |
| 111 const std::vector<int64_t>& index_ids) OVERRIDE; |
| 112 virtual void OpenCursor(int64_t transaction_id, |
| 113 int64_t object_store_id, |
| 114 int64_t index_id, |
| 115 scoped_ptr<IndexedDBKeyRange>, |
| 116 indexed_db::CursorDirection, |
| 117 bool key_only, |
| 118 TaskType, |
| 119 scoped_refptr<IndexedDBCallbacksWrapper>) OVERRIDE; |
| 120 virtual void Count(int64_t transaction_id, |
| 121 int64_t object_store_id, |
| 122 int64_t index_id, |
| 123 scoped_ptr<IndexedDBKeyRange>, |
| 124 scoped_refptr<IndexedDBCallbacksWrapper>) OVERRIDE; |
| 125 virtual void DeleteRange(int64_t transaction_id, |
| 126 int64_t object_store_id, |
| 127 scoped_ptr<IndexedDBKeyRange>, |
| 128 scoped_refptr<IndexedDBCallbacksWrapper>) OVERRIDE; |
| 129 virtual void Clear(int64_t transaction_id, |
| 130 int64_t object_store_id, |
| 131 scoped_refptr<IndexedDBCallbacksWrapper>) OVERRIDE; |
| 132 |
| 133 private: |
| 134 IndexedDBDatabaseImpl(const string16& name, |
| 135 IndexedDBBackingStore* database, |
| 136 IndexedDBFactoryImpl*, |
| 137 const string16& unique_identifier); |
| 138 virtual ~IndexedDBDatabaseImpl(); |
| 139 |
| 140 bool IsOpenConnectionBlocked() const; |
| 141 bool OpenInternal(); |
| 142 void RunVersionChangeTransaction( |
| 143 scoped_refptr<IndexedDBCallbacksWrapper>, |
| 144 scoped_refptr<IndexedDBDatabaseCallbacksWrapper>, |
| 145 int64_t transaction_id, |
| 146 int64_t requested_version); |
| 147 void RunVersionChangeTransactionFinal( |
| 148 scoped_refptr<IndexedDBCallbacksWrapper>, |
| 149 scoped_refptr<IndexedDBDatabaseCallbacksWrapper>, |
| 150 int64_t transaction_id, |
| 151 int64_t requested_version); |
| 152 size_t ConnectionCount() const; |
| 153 void ProcessPendingCalls(); |
| 154 |
| 155 bool IsDeleteDatabaseBlocked() const; |
| 156 void DeleteDatabaseFinal(scoped_refptr<IndexedDBCallbacksWrapper>); |
| 157 |
| 158 class VersionChangeOperation; |
| 159 |
| 160 // When a "versionchange" transaction aborts, these restore the back-end |
| 161 // object hierarchy. |
| 162 class VersionChangeAbortOperation; |
| 163 |
| 164 scoped_refptr<IndexedDBBackingStore> backing_store_; |
| 165 IndexedDBDatabaseMetadata metadata_; |
| 166 |
| 167 string16 identifier_; |
| 168 // This might not need to be a scoped_refptr since the factory's lifetime is |
| 169 // that of the page group, but it's better to be conservitive than sorry. |
| 170 scoped_refptr<IndexedDBFactoryImpl> factory_; |
| 171 |
| 172 IndexedDBTransactionCoordinator transaction_coordinator_; |
| 173 IndexedDBTransaction* running_version_change_transaction_; |
| 174 |
| 175 typedef std::map<int64_t, IndexedDBTransaction*> TransactionMap; |
| 176 TransactionMap transactions_; |
| 177 |
| 178 class PendingOpenCall; |
| 179 typedef std::list<PendingOpenCall*> PendingOpenCallList; |
| 180 PendingOpenCallList pending_open_calls_; |
| 181 scoped_ptr<PendingOpenCall> pending_run_version_change_transaction_call_; |
| 182 scoped_ptr<PendingOpenCall> pending_second_half_open_; |
| 183 |
| 184 class PendingDeleteCall; |
| 185 typedef std::list<PendingDeleteCall*> PendingDeleteCallList; |
| 186 PendingDeleteCallList pending_delete_calls_; |
| 187 |
| 188 typedef list_set<scoped_refptr<IndexedDBDatabaseCallbacksWrapper> > |
| 189 DatabaseCallbacksSet; |
| 190 DatabaseCallbacksSet database_callbacks_set_; |
| 191 |
| 192 bool closing_connection_; |
| 193 }; |
| 194 |
| 195 } // namespace content |
| 196 |
| 197 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DATABASE_IMPL_H_ |
OLD | NEW |