Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: content/browser/indexed_db/indexed_db_factory_impl.h

Issue 313883003: Split IndexedDBFactory into virtual base + impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved indexed_db_factory_impl.h and relocated IsBackingStoreOpen. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 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_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_
7 7
8 #include <map> 8 #include "content/browser/indexed_db/indexed_db_factory.h"
9 #include <set>
10 #include <string>
11 #include <utility>
12
13 #include "base/basictypes.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/strings/string16.h"
17 #include "content/browser/indexed_db/indexed_db_callbacks.h"
18 #include "content/browser/indexed_db/indexed_db_database.h"
19 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
20 #include "content/common/content_export.h"
21 #include "url/gurl.h"
22
23 namespace net {
24 class URLRequestContext;
25 }
26 9
27 namespace content { 10 namespace content {
28 11
29 class IndexedDBBackingStore;
30 class IndexedDBContextImpl; 12 class IndexedDBContextImpl;
31 struct IndexedDBPendingConnection;
32 13
33 class CONTENT_EXPORT IndexedDBFactory 14 class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory {
34 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) {
35 public: 15 public:
36 typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap; 16 explicit IndexedDBFactoryImpl(IndexedDBContextImpl* context);
37 typedef OriginDBMap::const_iterator OriginDBMapIterator;
38 17
39 explicit IndexedDBFactory(IndexedDBContextImpl* context); 18 // content::IndexedDBFactory overrides:
19 virtual void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier,
20 bool forcedClose) OVERRIDE;
40 21
41 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, 22 virtual void GetDatabaseNames(
42 bool forcedClose); 23 scoped_refptr<IndexedDBCallbacks> callbacks,
24 const GURL& origin_url,
25 const base::FilePath& data_directory,
26 net::URLRequestContext* request_context) OVERRIDE;
27 virtual void Open(const base::string16& name,
28 const IndexedDBPendingConnection& connection,
29 net::URLRequestContext* request_context,
30 const GURL& origin_url,
31 const base::FilePath& data_directory) OVERRIDE;
43 32
44 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, 33 virtual void DeleteDatabase(const base::string16& name,
45 const GURL& origin_url, 34 net::URLRequestContext* request_context,
46 const base::FilePath& data_directory, 35 scoped_refptr<IndexedDBCallbacks> callbacks,
47 net::URLRequestContext* request_context); 36 const GURL& origin_url,
48 void Open(const base::string16& name, 37 const base::FilePath& data_directory) OVERRIDE;
49 const IndexedDBPendingConnection& connection,
50 net::URLRequestContext* request_context,
51 const GURL& origin_url,
52 const base::FilePath& data_directory);
53 38
54 void DeleteDatabase(const base::string16& name, 39 virtual void HandleBackingStoreFailure(const GURL& origin_url) OVERRIDE;
55 net::URLRequestContext* request_context, 40 virtual void HandleBackingStoreCorruption(
56 scoped_refptr<IndexedDBCallbacks> callbacks, 41 const GURL& origin_url,
57 const GURL& origin_url, 42 const IndexedDBDatabaseError& error) OVERRIDE;
58 const base::FilePath& data_directory);
59 43
60 void HandleBackingStoreFailure(const GURL& origin_url); 44 virtual std::pair<OriginDBMapIterator, OriginDBMapIterator>
61 void HandleBackingStoreCorruption(const GURL& origin_url, 45 GetOpenDatabasesForOrigin(const GURL& origin_url) const OVERRIDE;
62 const IndexedDBDatabaseError& error);
63 46
64 std::pair<OriginDBMapIterator, OriginDBMapIterator> GetOpenDatabasesForOrigin( 47 virtual void ForceClose(const GURL& origin_url) OVERRIDE;
65 const GURL& origin_url) const;
66
67 void ForceClose(const GURL& origin_url);
68 48
69 // Called by the IndexedDBContext destructor so the factory can do cleanup. 49 // Called by the IndexedDBContext destructor so the factory can do cleanup.
70 void ContextDestroyed(); 50 virtual void ContextDestroyed() OVERRIDE;
71 51
72 // Called by the IndexedDBActiveBlobRegistry. 52 // Called by the IndexedDBActiveBlobRegistry.
73 virtual void ReportOutstandingBlobs(const GURL& origin_url, 53 virtual void ReportOutstandingBlobs(const GURL& origin_url,
74 bool blobs_outstanding); 54 bool blobs_outstanding) OVERRIDE;
75 55
76 // Called by an IndexedDBDatabase when it is actually deleted. 56 // Called by an IndexedDBDatabase when it is actually deleted.
77 void DatabaseDeleted(const IndexedDBDatabase::Identifier& identifier); 57 virtual void DatabaseDeleted(
58 const IndexedDBDatabase::Identifier& identifier) OVERRIDE;
78 59
79 size_t GetConnectionCount(const GURL& origin_url) const; 60 virtual size_t GetConnectionCount(const GURL& origin_url) const OVERRIDE;
80 61
81 protected: 62 protected:
82 friend class base::RefCountedThreadSafe<IndexedDBFactory>; 63 virtual ~IndexedDBFactoryImpl();
83
84 virtual ~IndexedDBFactory();
85 64
86 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( 65 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
87 const GURL& origin_url, 66 const GURL& origin_url,
88 const base::FilePath& data_directory, 67 const base::FilePath& data_directory,
89 net::URLRequestContext* request_context, 68 net::URLRequestContext* request_context,
90 blink::WebIDBDataLoss* data_loss, 69 blink::WebIDBDataLoss* data_loss,
91 std::string* data_loss_reason, 70 std::string* data_loss_reason,
92 bool* disk_full, 71 bool* disk_full,
93 leveldb::Status* status); 72 leveldb::Status* s) OVERRIDE;
94 73
95 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( 74 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
96 const GURL& origin_url, 75 const GURL& origin_url,
97 const base::FilePath& data_directory, 76 const base::FilePath& data_directory,
98 net::URLRequestContext* request_context, 77 net::URLRequestContext* request_context,
99 blink::WebIDBDataLoss* data_loss, 78 blink::WebIDBDataLoss* data_loss,
100 std::string* data_loss_message, 79 std::string* data_loss_message,
101 bool* disk_full, 80 bool* disk_full,
102 bool first_time, 81 bool first_time,
103 leveldb::Status* status); 82 leveldb::Status* s) OVERRIDE;
104 83
105 void ReleaseBackingStore(const GURL& origin_url, bool immediate); 84 void ReleaseBackingStore(const GURL& origin_url, bool immediate);
106 void CloseBackingStore(const GURL& origin_url); 85 void CloseBackingStore(const GURL& origin_url);
107 IndexedDBContextImpl* context() const { return context_; } 86 IndexedDBContextImpl* context() const { return context_; }
108 87
109 private: 88 private:
110 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, 89 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
111 BackingStoreReleasedOnForcedClose); 90 BackingStoreReleasedOnForcedClose);
112 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, 91 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
113 BackingStoreReleaseDelayedOnClose); 92 BackingStoreReleaseDelayedOnClose);
114 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen); 93 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen);
115 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, 94 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
116 DeleteDatabaseClosesBackingStore); 95 DeleteDatabaseClosesBackingStore);
117 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, 96 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
118 ForceCloseReleasesBackingStore); 97 ForceCloseReleasesBackingStore);
119 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, 98 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
120 GetDatabaseNamesClosesBackingStore); 99 GetDatabaseNamesClosesBackingStore);
121 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, 100 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest,
122 ForceCloseOpenDatabasesOnCommitFailure); 101 ForceCloseOpenDatabasesOnCommitFailure);
123 102
124 // Called internally after a database is closed, with some delay. If this 103 // Called internally after a database is closed, with some delay. If this
125 // factory has the last reference, it will be released. 104 // factory has the last reference, it will be released.
126 void MaybeCloseBackingStore(const GURL& origin_url); 105 void MaybeCloseBackingStore(const GURL& origin_url);
127 bool HasLastBackingStoreReference(const GURL& origin_url) const; 106 bool HasLastBackingStoreReference(const GURL& origin_url) const;
128 107
129 // Testing helpers, so unit tests don't need to grovel through internal state. 108 // Testing helpers, so unit tests don't need to grovel through internal state.
130 bool IsDatabaseOpen(const GURL& origin_url, 109 bool IsDatabaseOpen(const GURL& origin_url, const base::string16& name) const;
131 const base::string16& name) const;
132 bool IsBackingStoreOpen(const GURL& origin_url) const; 110 bool IsBackingStoreOpen(const GURL& origin_url) const;
133 bool IsBackingStorePendingClose(const GURL& origin_url) const; 111 bool IsBackingStorePendingClose(const GURL& origin_url) const;
134 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier); 112 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier);
135 113
136 IndexedDBContextImpl* context_; 114 IndexedDBContextImpl* context_;
137 115
138 typedef std::map<IndexedDBDatabase::Identifier, 116 typedef std::map<IndexedDBDatabase::Identifier, IndexedDBDatabase*>
139 IndexedDBDatabase*> IndexedDBDatabaseMap; 117 IndexedDBDatabaseMap;
140 IndexedDBDatabaseMap database_map_; 118 IndexedDBDatabaseMap database_map_;
141 OriginDBMap origin_dbs_; 119 OriginDBMap origin_dbs_;
142 120
143 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> > 121 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> >
144 IndexedDBBackingStoreMap; 122 IndexedDBBackingStoreMap;
145 IndexedDBBackingStoreMap backing_store_map_; 123 IndexedDBBackingStoreMap backing_store_map_;
146 124
147 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_; 125 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_;
148 IndexedDBBackingStoreMap backing_stores_with_active_blobs_; 126 IndexedDBBackingStoreMap backing_stores_with_active_blobs_;
149 std::set<GURL> backends_opened_since_boot_; 127 std::set<GURL> backends_opened_since_boot_;
150 128
151 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory); 129 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryImpl);
152 }; 130 };
153 131
154 } // namespace content 132 } // namespace content
155 133
156 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ 134 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory.cc ('k') | content/browser/indexed_db/indexed_db_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698