| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "content/browser/indexed_db/indexed_db_factory.h" | 16 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 17 | 17 |
| 18 namespace url { |
| 19 class Origin; |
| 20 } |
| 21 |
| 18 namespace content { | 22 namespace content { |
| 19 | 23 |
| 20 class IndexedDBContextImpl; | 24 class IndexedDBContextImpl; |
| 21 | 25 |
| 22 class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory { | 26 class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory { |
| 23 public: | 27 public: |
| 24 explicit IndexedDBFactoryImpl(IndexedDBContextImpl* context); | 28 explicit IndexedDBFactoryImpl(IndexedDBContextImpl* context); |
| 25 | 29 |
| 26 // content::IndexedDBFactory overrides: | 30 // content::IndexedDBFactory overrides: |
| 27 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, | 31 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, |
| 28 bool forced_close) override; | 32 bool forced_close) override; |
| 29 | 33 |
| 30 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, | 34 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 31 const url::Origin& origin, | 35 const url::Origin& origin, |
| 32 const base::FilePath& data_directory, | 36 const base::FilePath& data_directory, |
| 33 net::URLRequestContext* request_context) override; | 37 net::URLRequestContext* request_context) override; |
| 34 void Open(const base::string16& name, | 38 void Open(const base::string16& name, |
| 35 const IndexedDBPendingConnection& connection, | 39 const IndexedDBPendingConnection& connection, |
| 36 net::URLRequestContext* request_context, | 40 net::URLRequestContext* request_context, |
| 37 const url::Origin& origin, | 41 const url::Origin& origin, |
| 38 const base::FilePath& data_directory) override; | 42 const base::FilePath& data_directory) override; |
| 39 | 43 |
| 40 void DeleteDatabase(const base::string16& name, | 44 void DeleteDatabase(const base::string16& name, |
| 41 net::URLRequestContext* request_context, | 45 net::URLRequestContext* request_context, |
| 42 scoped_refptr<IndexedDBCallbacks> callbacks, | 46 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 43 const url::Origin& origin, | 47 const url::Origin& origin, |
| 44 const base::FilePath& data_directory) override; | 48 const base::FilePath& data_directory) override; |
| 45 | 49 |
| 46 void HandleBackingStoreFailure(const GURL& origin_url) override; | 50 void HandleBackingStoreFailure(const url::Origin& origin) override; |
| 47 void HandleBackingStoreCorruption( | 51 void HandleBackingStoreCorruption( |
| 48 const GURL& origin_url, | 52 const url::Origin& origin, |
| 49 const IndexedDBDatabaseError& error) override; | 53 const IndexedDBDatabaseError& error) override; |
| 50 | 54 |
| 51 OriginDBs GetOpenDatabasesForOrigin(const GURL& origin_url) const override; | 55 OriginDBs GetOpenDatabasesForOrigin(const url::Origin& origin) const override; |
| 52 | 56 |
| 53 void ForceClose(const GURL& origin_url) override; | 57 void ForceClose(const url::Origin& origin) override; |
| 54 | 58 |
| 55 // Called by the IndexedDBContext destructor so the factory can do cleanup. | 59 // Called by the IndexedDBContext destructor so the factory can do cleanup. |
| 56 void ContextDestroyed() override; | 60 void ContextDestroyed() override; |
| 57 | 61 |
| 58 // Called by the IndexedDBActiveBlobRegistry. | 62 // Called by the IndexedDBActiveBlobRegistry. |
| 59 void ReportOutstandingBlobs(const GURL& origin_url, | 63 void ReportOutstandingBlobs(const url::Origin& origin, |
| 60 bool blobs_outstanding) override; | 64 bool blobs_outstanding) override; |
| 61 | 65 |
| 62 // Called by an IndexedDBDatabase when it is actually deleted. | 66 // Called by an IndexedDBDatabase when it is actually deleted. |
| 63 void DatabaseDeleted( | 67 void DatabaseDeleted( |
| 64 const IndexedDBDatabase::Identifier& identifier) override; | 68 const IndexedDBDatabase::Identifier& identifier) override; |
| 65 | 69 |
| 66 size_t GetConnectionCount(const GURL& origin_url) const override; | 70 size_t GetConnectionCount(const url::Origin& origin) const override; |
| 67 | 71 |
| 68 protected: | 72 protected: |
| 69 ~IndexedDBFactoryImpl() override; | 73 ~IndexedDBFactoryImpl() override; |
| 70 | 74 |
| 71 scoped_refptr<IndexedDBBackingStore> OpenBackingStore( | 75 scoped_refptr<IndexedDBBackingStore> OpenBackingStore( |
| 72 const GURL& origin_url, | 76 const url::Origin& origin, |
| 73 const base::FilePath& data_directory, | 77 const base::FilePath& data_directory, |
| 74 net::URLRequestContext* request_context, | 78 net::URLRequestContext* request_context, |
| 75 blink::WebIDBDataLoss* data_loss, | 79 blink::WebIDBDataLoss* data_loss, |
| 76 std::string* data_loss_reason, | 80 std::string* data_loss_reason, |
| 77 bool* disk_full, | 81 bool* disk_full, |
| 78 leveldb::Status* s) override; | 82 leveldb::Status* s) override; |
| 79 | 83 |
| 80 scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( | 84 scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( |
| 81 const GURL& origin_url, | 85 const url::Origin& origin, |
| 82 const base::FilePath& data_directory, | 86 const base::FilePath& data_directory, |
| 83 net::URLRequestContext* request_context, | 87 net::URLRequestContext* request_context, |
| 84 blink::WebIDBDataLoss* data_loss, | 88 blink::WebIDBDataLoss* data_loss, |
| 85 std::string* data_loss_message, | 89 std::string* data_loss_message, |
| 86 bool* disk_full, | 90 bool* disk_full, |
| 87 bool first_time, | 91 bool first_time, |
| 88 leveldb::Status* s) override; | 92 leveldb::Status* s) override; |
| 89 | 93 |
| 90 void ReleaseBackingStore(const GURL& origin_url, bool immediate); | 94 void ReleaseBackingStore(const url::Origin& origin, bool immediate); |
| 91 void CloseBackingStore(const GURL& origin_url); | 95 void CloseBackingStore(const url::Origin& origin); |
| 92 IndexedDBContextImpl* context() const { return context_; } | 96 IndexedDBContextImpl* context() const { return context_; } |
| 93 | 97 |
| 94 private: | 98 private: |
| 95 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | 99 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, |
| 96 BackingStoreReleasedOnForcedClose); | 100 BackingStoreReleasedOnForcedClose); |
| 97 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | 101 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, |
| 98 BackingStoreReleaseDelayedOnClose); | 102 BackingStoreReleaseDelayedOnClose); |
| 99 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen); | 103 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen); |
| 100 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | 104 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, |
| 101 DeleteDatabaseClosesBackingStore); | 105 DeleteDatabaseClosesBackingStore); |
| 102 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | 106 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, |
| 103 ForceCloseReleasesBackingStore); | 107 ForceCloseReleasesBackingStore); |
| 104 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | 108 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, |
| 105 GetDatabaseNamesClosesBackingStore); | 109 GetDatabaseNamesClosesBackingStore); |
| 106 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, | 110 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, |
| 107 ForceCloseOpenDatabasesOnCommitFailure); | 111 ForceCloseOpenDatabasesOnCommitFailure); |
| 108 | 112 |
| 109 typedef std::map<IndexedDBDatabase::Identifier, IndexedDBDatabase*> | 113 typedef std::map<IndexedDBDatabase::Identifier, IndexedDBDatabase*> |
| 110 IndexedDBDatabaseMap; | 114 IndexedDBDatabaseMap; |
| 111 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> > | 115 typedef std::map<url::Origin, scoped_refptr<IndexedDBBackingStore>> |
| 112 IndexedDBBackingStoreMap; | 116 IndexedDBBackingStoreMap; |
| 113 | 117 |
| 114 // Called internally after a database is closed, with some delay. If this | 118 // Called internally after a database is closed, with some delay. If this |
| 115 // factory has the last reference, it will be released. | 119 // factory has the last reference, it will be released. |
| 116 void MaybeCloseBackingStore(const GURL& origin_url); | 120 void MaybeCloseBackingStore(const url::Origin& origin); |
| 117 bool HasLastBackingStoreReference(const GURL& origin_url) const; | 121 bool HasLastBackingStoreReference(const url::Origin& origin) const; |
| 118 | 122 |
| 119 // Testing helpers, so unit tests don't need to grovel through internal state. | 123 // Testing helpers, so unit tests don't need to grovel through internal state. |
| 120 bool IsDatabaseOpen(const GURL& origin_url, const base::string16& name) const; | 124 bool IsDatabaseOpen(const url::Origin& origin, |
| 121 bool IsBackingStoreOpen(const GURL& origin_url) const; | 125 const base::string16& name) const; |
| 122 bool IsBackingStorePendingClose(const GURL& origin_url) const; | 126 bool IsBackingStoreOpen(const url::Origin& origin) const; |
| 127 bool IsBackingStorePendingClose(const url::Origin& origin) const; |
| 123 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier); | 128 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier); |
| 124 | 129 |
| 125 IndexedDBContextImpl* context_; | 130 IndexedDBContextImpl* context_; |
| 126 | 131 |
| 127 IndexedDBDatabaseMap database_map_; | 132 IndexedDBDatabaseMap database_map_; |
| 128 OriginDBMap origin_dbs_; | 133 OriginDBMap origin_dbs_; |
| 129 IndexedDBBackingStoreMap backing_store_map_; | 134 IndexedDBBackingStoreMap backing_store_map_; |
| 130 | 135 |
| 131 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; | 136 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; |
| 132 IndexedDBBackingStoreMap backing_stores_with_active_blobs_; | 137 IndexedDBBackingStoreMap backing_stores_with_active_blobs_; |
| 133 std::set<GURL> backends_opened_since_boot_; | 138 std::set<url::Origin> backends_opened_since_boot_; |
| 134 | 139 |
| 135 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryImpl); | 140 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryImpl); |
| 136 }; | 141 }; |
| 137 | 142 |
| 138 } // namespace content | 143 } // namespace content |
| 139 | 144 |
| 140 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_ | 145 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_ |
| OLD | NEW |