| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 15 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database.h" | 16 #include "content/browser/indexed_db/indexed_db_database.h" |
| 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 class IndexedDBBackingStore; | 23 class IndexedDBBackingStore; |
| 24 class IndexedDBContextImpl; | 24 class IndexedDBContextImpl; |
| 25 | 25 |
| 26 class CONTENT_EXPORT IndexedDBFactory | 26 class CONTENT_EXPORT IndexedDBFactory |
| 27 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) { | 27 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) { |
| 28 public: | 28 public: |
| 29 typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap; |
| 30 typedef OriginDBMap::const_iterator OriginDBMapIterator; |
| 31 |
| 29 explicit IndexedDBFactory(IndexedDBContextImpl* context); | 32 explicit IndexedDBFactory(IndexedDBContextImpl* context); |
| 30 | 33 |
| 31 // Notifications from weak pointers. | 34 // Notifications from weak pointers. |
| 32 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, | 35 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, |
| 33 bool forcedClose); | 36 bool forcedClose); |
| 34 | 37 |
| 35 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, | 38 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, |
| 36 const GURL& origin_url, | 39 const GURL& origin_url, |
| 37 const base::FilePath& data_directory); | 40 const base::FilePath& data_directory); |
| 38 void Open(const base::string16& name, | 41 void Open(const base::string16& name, |
| 39 int64 version, | 42 int64 version, |
| 40 int64 transaction_id, | 43 int64 transaction_id, |
| 41 scoped_refptr<IndexedDBCallbacks> callbacks, | 44 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 42 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 45 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 43 const GURL& origin_url, | 46 const GURL& origin_url, |
| 44 const base::FilePath& data_directory); | 47 const base::FilePath& data_directory); |
| 45 | 48 |
| 46 void DeleteDatabase(const base::string16& name, | 49 void DeleteDatabase(const base::string16& name, |
| 47 scoped_refptr<IndexedDBCallbacks> callbacks, | 50 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 48 const GURL& origin_url, | 51 const GURL& origin_url, |
| 49 const base::FilePath& data_directory); | 52 const base::FilePath& data_directory); |
| 50 | 53 |
| 51 void HandleBackingStoreFailure(const GURL& origin_url); | 54 void HandleBackingStoreFailure(const GURL& origin_url); |
| 52 | 55 |
| 53 // Iterates over all databases; for diagnostics only. | 56 std::pair<OriginDBMapIterator, OriginDBMapIterator> GetOpenDatabasesForOrigin( |
| 54 std::vector<IndexedDBDatabase*> GetOpenDatabasesForOrigin( | |
| 55 const GURL& origin_url) const; | 57 const GURL& origin_url) const; |
| 56 | 58 |
| 57 // Called by IndexedDBContext after all connections are closed, to | 59 // Called by IndexedDBContext after all connections are closed, to |
| 58 // ensure the backing store closed immediately. | 60 // ensure the backing store closed immediately. |
| 59 void ForceClose(const GURL& origin_url); | 61 void ForceClose(const GURL& origin_url); |
| 60 | 62 |
| 61 // Called by the IndexedDBContext destructor so the factory can do cleanup. | 63 // Called by the IndexedDBContext destructor so the factory can do cleanup. |
| 62 void ContextDestroyed(); | 64 void ContextDestroyed(); |
| 63 | 65 |
| 64 // Called by an IndexedDBDatabase when it is actually deleted. | 66 // Called by an IndexedDBDatabase when it is actually deleted. |
| 65 void DatabaseDeleted(const IndexedDBDatabase::Identifier& identifier); | 67 void DatabaseDeleted(const IndexedDBDatabase::Identifier& identifier); |
| 66 | 68 |
| 69 size_t GetConnectionCount(const GURL& origin_url) const; |
| 70 |
| 67 protected: | 71 protected: |
| 68 friend class base::RefCountedThreadSafe<IndexedDBFactory>; | 72 friend class base::RefCountedThreadSafe<IndexedDBFactory>; |
| 69 | 73 |
| 70 virtual ~IndexedDBFactory(); | 74 virtual ~IndexedDBFactory(); |
| 71 | 75 |
| 72 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( | 76 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( |
| 73 const GURL& origin_url, | 77 const GURL& origin_url, |
| 74 const base::FilePath& data_directory, | 78 const base::FilePath& data_directory, |
| 75 blink::WebIDBDataLoss* data_loss, | 79 blink::WebIDBDataLoss* data_loss, |
| 76 std::string* data_loss_reason, | 80 std::string* data_loss_reason, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 97 // Called internally after a database is closed, with some delay. If this | 101 // Called internally after a database is closed, with some delay. If this |
| 98 // factory has the last reference, it will be released. | 102 // factory has the last reference, it will be released. |
| 99 void MaybeCloseBackingStore(const GURL& origin_url); | 103 void MaybeCloseBackingStore(const GURL& origin_url); |
| 100 bool HasLastBackingStoreReference(const GURL& origin_url) const; | 104 bool HasLastBackingStoreReference(const GURL& origin_url) const; |
| 101 | 105 |
| 102 // Testing helpers, so unit tests don't need to grovel through internal state. | 106 // Testing helpers, so unit tests don't need to grovel through internal state. |
| 103 bool IsDatabaseOpen(const GURL& origin_url, | 107 bool IsDatabaseOpen(const GURL& origin_url, |
| 104 const base::string16& name) const; | 108 const base::string16& name) const; |
| 105 bool IsBackingStoreOpen(const GURL& origin_url) const; | 109 bool IsBackingStoreOpen(const GURL& origin_url) const; |
| 106 bool IsBackingStorePendingClose(const GURL& origin_url) const; | 110 bool IsBackingStorePendingClose(const GURL& origin_url) const; |
| 111 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier); |
| 107 | 112 |
| 108 IndexedDBContextImpl* context_; | 113 IndexedDBContextImpl* context_; |
| 109 | 114 |
| 110 typedef std::map<IndexedDBDatabase::Identifier, | 115 typedef std::map<IndexedDBDatabase::Identifier, |
| 111 IndexedDBDatabase*> IndexedDBDatabaseMap; | 116 IndexedDBDatabase*> IndexedDBDatabaseMap; |
| 112 IndexedDBDatabaseMap database_map_; | 117 IndexedDBDatabaseMap database_map_; |
| 118 OriginDBMap origin_dbs_; |
| 113 | 119 |
| 114 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> > | 120 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> > |
| 115 IndexedDBBackingStoreMap; | 121 IndexedDBBackingStoreMap; |
| 116 IndexedDBBackingStoreMap backing_store_map_; | 122 IndexedDBBackingStoreMap backing_store_map_; |
| 117 | 123 |
| 118 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; | 124 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; |
| 119 }; | 125 }; |
| 120 | 126 |
| 121 } // namespace content | 127 } // namespace content |
| 122 | 128 |
| 123 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ | 129 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |
| OLD | NEW |