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

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: Created 6 years, 6 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 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 net { 21 namespace net {
22 class URLRequestContext; 22 class URLRequestContext;
23 } 23 }
24 24
25 namespace content { 25 namespace content {
26 26
27 class IndexedDBBackingStore; 27 class IndexedDBBackingStore;
28 class IndexedDBContextImpl;
29 struct IndexedDBPendingConnection; 28 struct IndexedDBPendingConnection;
30 29
31 class CONTENT_EXPORT IndexedDBFactory 30 class CONTENT_EXPORT IndexedDBFactory
32 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) { 31 : NON_EXPORTED_BASE(public base::RefCountedThreadSafe<IndexedDBFactory>) {
33 public: 32 public:
34 typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap; 33 typedef std::multimap<GURL, IndexedDBDatabase*> OriginDBMap;
35 typedef OriginDBMap::const_iterator OriginDBMapIterator; 34 typedef OriginDBMap::const_iterator OriginDBMapIterator;
36 35
37 explicit IndexedDBFactory(IndexedDBContextImpl* context); 36 virtual void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier,
37 bool forcedClose) = 0;
38 38
39 void ReleaseDatabase(const IndexedDBDatabase::Identifier& identifier, 39 virtual void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks,
40 bool forcedClose); 40 const GURL& origin_url,
41 const base::FilePath& data_directory,
42 net::URLRequestContext* request_context) = 0;
43 virtual void Open(const base::string16& name,
44 const IndexedDBPendingConnection& connection,
45 net::URLRequestContext* request_context,
46 const GURL& origin_url,
47 const base::FilePath& data_directory) = 0;
41 48
42 void GetDatabaseNames(scoped_refptr<IndexedDBCallbacks> callbacks, 49 virtual void DeleteDatabase(const base::string16& name,
43 const GURL& origin_url, 50 net::URLRequestContext* request_context,
44 const base::FilePath& data_directory, 51 scoped_refptr<IndexedDBCallbacks> callbacks,
45 net::URLRequestContext* request_context); 52 const GURL& origin_url,
46 void Open(const base::string16& name, 53 const base::FilePath& data_directory) = 0;
47 const IndexedDBPendingConnection& connection,
48 net::URLRequestContext* request_context,
49 const GURL& origin_url,
50 const base::FilePath& data_directory);
51 54
52 void DeleteDatabase(const base::string16& name, 55 virtual void HandleBackingStoreFailure(const GURL& origin_url) = 0;
53 net::URLRequestContext* request_context, 56 virtual void HandleBackingStoreCorruption(
54 scoped_refptr<IndexedDBCallbacks> callbacks, 57 const GURL& origin_url,
55 const GURL& origin_url, 58 const IndexedDBDatabaseError& error) = 0;
56 const base::FilePath& data_directory);
57 59
58 void HandleBackingStoreFailure(const GURL& origin_url); 60 virtual std::pair<OriginDBMapIterator, OriginDBMapIterator>
59 void HandleBackingStoreCorruption(const GURL& origin_url, 61 GetOpenDatabasesForOrigin(const GURL& origin_url) const = 0;
60 const IndexedDBDatabaseError& error);
61 62
62 std::pair<OriginDBMapIterator, OriginDBMapIterator> GetOpenDatabasesForOrigin( 63 virtual void ForceClose(const GURL& origin_url) = 0;
63 const GURL& origin_url) const;
64
65 void ForceClose(const GURL& origin_url);
66 64
67 // Called by the IndexedDBContext destructor so the factory can do cleanup. 65 // Called by the IndexedDBContext destructor so the factory can do cleanup.
68 void ContextDestroyed(); 66 virtual void ContextDestroyed() = 0;
69 67
70 // Called by the IndexedDBActiveBlobRegistry. 68 // Called by the IndexedDBActiveBlobRegistry.
71 virtual void ReportOutstandingBlobs(const GURL& origin_url, 69 virtual void ReportOutstandingBlobs(const GURL& origin_url,
72 bool blobs_outstanding); 70 bool blobs_outstanding) = 0;
73 71
74 // Called by an IndexedDBDatabase when it is actually deleted. 72 // Called by an IndexedDBDatabase when it is actually deleted.
75 void DatabaseDeleted(const IndexedDBDatabase::Identifier& identifier); 73 virtual void DatabaseDeleted(
74 const IndexedDBDatabase::Identifier& identifier) = 0;
76 75
77 size_t GetConnectionCount(const GURL& origin_url) const; 76 virtual size_t GetConnectionCount(const GURL& origin_url) const = 0;
78 77
79 protected: 78 protected:
80 friend class base::RefCountedThreadSafe<IndexedDBFactory>; 79 friend class base::RefCountedThreadSafe<IndexedDBFactory>;
81 80
82 virtual ~IndexedDBFactory(); 81 virtual ~IndexedDBFactory() {}
83 82
84 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore( 83 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStore(
85 const GURL& origin_url, 84 const GURL& origin_url,
86 const base::FilePath& data_directory, 85 const base::FilePath& data_directory,
87 net::URLRequestContext* request_context, 86 net::URLRequestContext* request_context,
88 blink::WebIDBDataLoss* data_loss, 87 blink::WebIDBDataLoss* data_loss,
89 std::string* data_loss_reason, 88 std::string* data_loss_reason,
90 bool* disk_full); 89 bool* disk_full) = 0;
91 90
92 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( 91 virtual scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
93 const GURL& origin_url, 92 const GURL& origin_url,
94 const base::FilePath& data_directory, 93 const base::FilePath& data_directory,
95 net::URLRequestContext* request_context, 94 net::URLRequestContext* request_context,
96 blink::WebIDBDataLoss* data_loss, 95 blink::WebIDBDataLoss* data_loss,
97 std::string* data_loss_message, 96 std::string* data_loss_message,
98 bool* disk_full, 97 bool* disk_full,
99 bool first_time); 98 bool first_time) = 0;
100
101 void ReleaseBackingStore(const GURL& origin_url, bool immediate);
102 void CloseBackingStore(const GURL& origin_url);
103 IndexedDBContextImpl* context() const { return context_; }
104 99
105 private: 100 private:
106 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
107 BackingStoreReleasedOnForcedClose);
108 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
109 BackingStoreReleaseDelayedOnClose);
110 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest, DatabaseFailedOpen);
111 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
112 DeleteDatabaseClosesBackingStore);
113 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
114 ForceCloseReleasesBackingStore);
115 FRIEND_TEST_ALL_PREFIXES(IndexedDBFactoryTest,
116 GetDatabaseNamesClosesBackingStore);
117 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, 101 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest,
118 ForceCloseOpenDatabasesOnCommitFailure); 102 ForceCloseOpenDatabasesOnCommitFailure);
119 103
120 // Called internally after a database is closed, with some delay. If this 104 virtual bool IsBackingStoreOpen(const GURL& origin_url) const = 0;
jsbell 2014/07/17 18:45:46 Since this is an impl detail, not part of the inte
cmumford 2014/07/17 20:11:52 Yeah, I'm not a fan of downcasting like this, but
121 // factory has the last reference, it will be released.
122 void MaybeCloseBackingStore(const GURL& origin_url);
123 bool HasLastBackingStoreReference(const GURL& origin_url) const;
124
125 // Testing helpers, so unit tests don't need to grovel through internal state.
126 bool IsDatabaseOpen(const GURL& origin_url,
127 const base::string16& name) const;
128 bool IsBackingStoreOpen(const GURL& origin_url) const;
129 bool IsBackingStorePendingClose(const GURL& origin_url) const;
130 void RemoveDatabaseFromMaps(const IndexedDBDatabase::Identifier& identifier);
131
132 IndexedDBContextImpl* context_;
133
134 typedef std::map<IndexedDBDatabase::Identifier,
135 IndexedDBDatabase*> IndexedDBDatabaseMap;
136 IndexedDBDatabaseMap database_map_;
137 OriginDBMap origin_dbs_;
138
139 typedef std::map<GURL, scoped_refptr<IndexedDBBackingStore> >
140 IndexedDBBackingStoreMap;
141 IndexedDBBackingStoreMap backing_store_map_;
142
143 std::set<scoped_refptr<IndexedDBBackingStore> > session_only_backing_stores_;
144 IndexedDBBackingStoreMap backing_stores_with_active_blobs_;
145 std::set<GURL> backends_opened_since_boot_;
146 }; 105 };
147 106
148 } // namespace content 107 } // namespace content
149 108
150 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_FACTORY_H_ 109 #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