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 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 17 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
18 #include "content/browser/indexed_db/indexed_db_database.h" | 18 #include "content/browser/indexed_db/indexed_db_database.h" |
19 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 19 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 class URLRequestContext; | 24 class URLRequestContext; |
25 } | 25 } |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 class IndexedDBBackingStore; | 29 class IndexedDBBackingStore; |
30 class IndexedDBContextImpl; | |
31 struct IndexedDBPendingConnection; | 30 struct IndexedDBPendingConnection; |
32 | 31 |
33 class CONTENT_EXPORT IndexedDBFactory | 32 class CONTENT_EXPORT IndexedDBFactory |
34 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) { | 33 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) { |
jochen (gone - plz use gerrit)
2014/07/15 11:44:46
an interface shouldn't inherit from something else
cmumford
2014/07/15 16:11:47
Then maybe I shouldn't use the word "interface" in
| |
35 public: | 34 public: |
36 typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap; | 35 typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap; |
37 typedef OriginDBMap::const_iterator OriginDBMapIterator; | 36 typedef OriginDBMap::const_iterator OriginDBMapIterator; |
38 | 37 |
39 explicit IndexedDBFactory(IndexedDBContextImpl* context); | 38 virtual void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, |
39 bool forcedClose) = 0; | |
40 | 40 |
41 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, | 41 virtual void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, |
42 bool forcedClose); | 42 const GURL& origin_url, |
43 const base::FilePath& data_directory, | |
44 net::URLRequestContext* request_context) = 0; | |
45 virtual void Open(const base::string16& name, | |
46 const IndexedDBPendingConnection& connection, | |
47 net::URLRequestContext* request_context, | |
48 const GURL& origin_url, | |
49 const base::FilePath& data_directory) = 0; | |
43 | 50 |
44 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, | 51 virtual void DeleteDatabase(const base::string16& name, |
45 const GURL& origin_url, | 52 net::URLRequestContext* request_context, |
46 const base::FilePath& data_directory, | 53 scoped_refptr<IndexedDBCallbacks> callbacks, |
47 net::URLRequestContext* request_context); | 54 const GURL& origin_url, |
48 void Open(const base::string16& name, | 55 const base::FilePath& data_directory) = 0; |
49 const IndexedDBPendingConnection& connection, | |
50 net::URLRequestContext* request_context, | |
51 const GURL& origin_url, | |
52 const base::FilePath& data_directory); | |
53 | 56 |
54 void DeleteDatabase(const base::string16& name, | 57 virtual void HandleBackingStoreFailure(const GURL& origin_url) = 0; |
55 net::URLRequestContext* request_context, | 58 virtual void HandleBackingStoreCorruption( |
56 scoped_refptr<IndexedDBCallbacks> callbacks, | 59 const GURL& origin_url, |
57 const GURL& origin_url, | 60 const IndexedDBDatabaseError& error) = 0; |
58 const base::FilePath& data_directory); | |
59 | 61 |
60 void HandleBackingStoreFailure(const GURL& origin_url); | 62 virtual std::pair<OriginDBMapIterator, OriginDBMapIterator> |
61 void HandleBackingStoreCorruption(const GURL& origin_url, | 63 GetOpenDatabasesForOrigin(const GURL& origin_url) const = 0; |
62 const IndexedDBDatabaseError& error); | |
63 | 64 |
64 std::pair<OriginDBMapIterator, OriginDBMapIterator> GetOpenDatabasesForOrigin( | 65 virtual void ForceClose(const GURL& origin_url) = 0; |
65 const GURL& origin_url) const; | |
66 | |
67 void ForceClose(const GURL& origin_url); | |
68 | 66 |
69 // Called by the IndexedDBContext destructor so the factory can do cleanup. | 67 // Called by the IndexedDBContext destructor so the factory can do cleanup. |
70 void ContextDestroyed(); | 68 virtual void ContextDestroyed() = 0; |
71 | 69 |
72 // Called by the IndexedDBActiveBlobRegistry. | 70 // Called by the IndexedDBActiveBlobRegistry. |
73 virtual void ReportOutstandingBlobs(const GURL& origin_url, | 71 virtual void ReportOutstandingBlobs(const GURL& origin_url, |
74 bool blobs_outstanding); | 72 bool blobs_outstanding) = 0; |
75 | 73 |
76 // Called by an IndexedDBDatabase when it is actually deleted. | 74 // Called by an IndexedDBDatabase when it is actually deleted. |
77 void DatabaseDeleted(const IndexedDBDatabase::Identifier& identifier); | 75 virtual void DatabaseDeleted( |
76 const IndexedDBDatabase::Identifier& identifier) = 0; | |
78 | 77 |
79 size_t GetConnectionCount(const GURL& origin_url) const; | 78 virtual size_t GetConnectionCount(const GURL& origin_url) const = 0; |
80 | 79 |
81 protected: | 80 protected: |
82 friend class base::RefCountedThreadSafe<IndexedDBFactory>; | 81 friend class base::RefCountedThreadSafe<IndexedDBFactory>; |
83 | 82 |
84 virtual ~IndexedDBFactory(); | 83 IndexedDBFactory() {} |
jochen (gone - plz use gerrit)
2014/07/15 11:44:46
no need for a ctor on an interface
cmumford
2014/07/15 16:11:47
W/o it I get this error:
error: constructor for '
| |
84 virtual ~IndexedDBFactory() {} | |
jochen (gone - plz use gerrit)
2014/07/15 11:44:46
the dtor can be public as well
cmumford
2014/07/15 16:11:47
I think that describing as not an interface satisf
| |
85 | 85 |
86 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( | 86 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( |
87 const GURL& origin_url, | 87 const GURL& origin_url, |
88 const base::FilePath& data_directory, | 88 const base::FilePath& data_directory, |
89 net::URLRequestContext* request_context, | 89 net::URLRequestContext* request_context, |
90 blink::WebIDBDataLoss* data_loss, | 90 blink::WebIDBDataLoss* data_loss, |
91 std::string* data_loss_reason, | 91 std::string* data_loss_reason, |
92 bool* disk_full); | 92 bool* disk_full) = 0; |
93 | 93 |
94 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( | 94 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( |
95 const GURL& origin_url, | 95 const GURL& origin_url, |
96 const base::FilePath& data_directory, | 96 const base::FilePath& data_directory, |
97 net::URLRequestContext* request_context, | 97 net::URLRequestContext* request_context, |
98 blink::WebIDBDataLoss* data_loss, | 98 blink::WebIDBDataLoss* data_loss, |
99 std::string* data_loss_message, | 99 std::string* data_loss_message, |
100 bool* disk_full, | 100 bool* disk_full, |
101 bool first_time); | 101 bool first_time) = 0; |
102 | |
103 void ReleaseBackingStore(const GURL& origin_url, bool immediate); | |
104 void CloseBackingStore(const GURL& origin_url); | |
105 IndexedDBContextImpl* context() const { return context_; } | |
106 | 102 |
107 private: | 103 private: |
108 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | |
109 BackingStoreReleasedOnForcedClose); | |
110 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | |
111 BackingStoreReleaseDelayedOnClose); | |
112 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen); | |
113 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | |
114 DeleteDatabaseClosesBackingStore); | |
115 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | |
116 ForceCloseReleasesBackingStore); | |
117 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, | |
118 GetDatabaseNamesClosesBackingStore); | |
119 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, | 104 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, |
120 ForceCloseOpenDatabasesOnCommitFailure); | 105 ForceCloseOpenDatabasesOnCommitFailure); |
121 | 106 |
122 // Called internally after a database is closed, with some delay. If this | 107 virtual bool IsBackingStoreOpen(const GURL& origin_url) const = 0; |
123 // factory has the last reference, it will be released. | |
124 void MaybeCloseBackingStore(const GURL& origin_url); | |
125 bool HasLastBackingStoreReference(const GURL& origin_url) const; | |
126 | |
127 // Testing helpers, so unit tests don't need to grovel through internal state. | |
128 bool IsDatabaseOpen(const GURL& origin_url, | |
129 const base::string16& name) const; | |
130 bool IsBackingStoreOpen(const GURL& origin_url) const; | |
131 bool IsBackingStorePendingClose(const GURL& origin_url) const; | |
132 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier); | |
133 | |
134 IndexedDBContextImpl* context_; | |
135 | |
136 typedef std::map<IndexedDBDatabase::Identifier, | |
137 IndexedDBDatabase*> IndexedDBDatabaseMap; | |
138 IndexedDBDatabaseMap database_map_; | |
139 OriginDBMap origin_dbs_; | |
140 | |
141 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> > | |
142 IndexedDBBackingStoreMap; | |
143 IndexedDBBackingStoreMap backing_store_map_; | |
144 | |
145 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; | |
146 IndexedDBBackingStoreMap backing_stores_with_active_blobs_; | |
147 std::set<GURL> backends_opened_since_boot_; | |
148 | 108 |
149 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory); | 109 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory); |
150 }; | 110 }; |
151 | 111 |
152 } // namespace content | 112 } // namespace content |
153 | 113 |
154 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ | 114 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ |
OLD | NEW |