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

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

Issue 313883003: Split IndexedDBFactory into virtual base + impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved DISALLOW_COPY_AND_ASSIGN down and added comment 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) 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>) {
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() {}
84 virtual ~IndexedDBFactory() {}
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,
93 leveldb::Status* status); 93 leveldb::Status* status) = 0;
94 94
95 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( 95 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
96 const GURL& origin_url, 96 const GURL& origin_url,
97 const base::FilePath& data_directory, 97 const base::FilePath& data_directory,
98 net::URLRequestContext* request_context, 98 net::URLRequestContext* request_context,
99 blink::WebIDBDataLoss* data_loss, 99 blink::WebIDBDataLoss* data_loss,
100 std::string* data_loss_message, 100 std::string* data_loss_message,
101 bool* disk_full, 101 bool* disk_full,
102 bool first_time, 102 bool first_time,
103 leveldb::Status* status); 103 leveldb::Status* status) = 0;
104 104
105 void ReleaseBackingStore(const GURL& origin_url, bool immediate); 105 void ReleaseBackingStore(const GURL& origin_url, bool immediate);
jochen (gone - plz use gerrit) 2014/07/17 09:22:00 delete this and the next line
cmumford 2014/07/17 18:19:46 Done - thx for catching that.
106 void CloseBackingStore(const GURL& origin_url); 106 void CloseBackingStore(const GURL& origin_url);
107 IndexedDBContextImpl* context() const { return context_; }
108 107
109 private: 108 private:
110 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
111 BackingStoreReleasedOnForcedClose);
112 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
113 BackingStoreReleaseDelayedOnClose);
114 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen);
115 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
116 DeleteDatabaseClosesBackingStore);
117 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
118 ForceCloseReleasesBackingStore);
119 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
120 GetDatabaseNamesClosesBackingStore);
121 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, 109 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest,
122 ForceCloseOpenDatabasesOnCommitFailure); 110 ForceCloseOpenDatabasesOnCommitFailure);
jochen (gone - plz use gerrit) 2014/07/17 09:22:00 should not be required
cmumford 2014/07/17 18:19:46 If you mean the FRIEND_TEST... then it's there bec
123 111
124 // Called internally after a database is closed, with some delay. If this 112 virtual bool IsBackingStoreOpen(const GURL& origin_url) const = 0;
125 // factory has the last reference, it will be released.
126 void MaybeCloseBackingStore(const GURL& origin_url);
127 bool HasLastBackingStoreReference(const GURL& origin_url) const;
128
129 // Testing helpers, so unit tests don't need to grovel through internal state.
130 bool IsDatabaseOpen(const GURL& origin_url,
131 const base::string16& name) const;
132 bool IsBackingStoreOpen(const GURL& origin_url) const;
133 bool IsBackingStorePendingClose(const GURL& origin_url) const;
134 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier);
135
136 IndexedDBContextImpl* context_;
137
138 typedef std::map<IndexedDBDatabase::Identifier,
139 IndexedDBDatabase*> IndexedDBDatabaseMap;
140 IndexedDBDatabaseMap database_map_;
141 OriginDBMap origin_dbs_;
142
143 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> >
144 IndexedDBBackingStoreMap;
145 IndexedDBBackingStoreMap backing_store_map_;
146
147 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_;
148 IndexedDBBackingStoreMap backing_stores_with_active_blobs_;
149 std::set<GURL> backends_opened_since_boot_;
150 113
151 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory); 114 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactory);
152 }; 115 };
153 116
154 } // namespace content 117 } // namespace content
155 118
156 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ 119 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_context_impl.cc ('k') | content/browser/indexed_db/indexed_db_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698