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