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

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

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring after Passing URLRequestContextGetter. Created 4 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_CONTEXT_IMPL_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "Source/modules/indexeddb/indexed_db.mojom.h"
17 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
18 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
19 #include "base/gtest_prod_util.h" 20 #include "base/gtest_prod_util.h"
20 #include "base/macros.h" 21 #include "base/macros.h"
21 #include "content/browser/browser_main_loop.h" 22 #include "content/browser/browser_main_loop.h"
22 #include "content/browser/indexed_db/indexed_db_factory.h" 23 #include "content/browser/indexed_db/indexed_db_factory.h"
23 #include "content/public/browser/indexed_db_context.h" 24 #include "content/public/browser/indexed_db_context.h"
24 #include "storage/common/quota/quota_types.h" 25 #include "storage/common/quota/quota_types.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 27
27 namespace base { 28 namespace base {
28 class ListValue; 29 class ListValue;
29 class FilePath; 30 class FilePath;
30 class SequencedTaskRunner; 31 class SingleThreadTaskRunner;
31 } 32 }
32 33
33 namespace storage { 34 namespace storage {
34 class QuotaManagerProxy; 35 class QuotaManagerProxy;
35 class SpecialStoragePolicy; 36 class SpecialStoragePolicy;
36 } 37 }
37 38
38 namespace url { 39 namespace url {
39 class Origin; 40 class Origin;
40 } 41 }
41 42
42 namespace content { 43 namespace content {
43 44
45 class BrowserContext;
46 class DatabaseFactoryImpl;
44 class IndexedDBConnection; 47 class IndexedDBConnection;
48 class DatabaseFactoryImpl;
45 49
46 class CONTENT_EXPORT IndexedDBContextImpl 50 class CONTENT_EXPORT IndexedDBContextImpl
47 : NON_EXPORTED_BASE(public IndexedDBContext) { 51 : NON_EXPORTED_BASE(public IndexedDBContext) {
48 public: 52 public:
49 // Recorded in histograms, so append only. 53 // Recorded in histograms, so append only.
50 enum ForceCloseReason { 54 enum ForceCloseReason {
51 FORCE_CLOSE_DELETE_ORIGIN = 0, 55 FORCE_CLOSE_DELETE_ORIGIN = 0,
52 FORCE_CLOSE_BACKING_STORE_FAILURE, 56 FORCE_CLOSE_BACKING_STORE_FAILURE,
53 FORCE_CLOSE_INTERNALS_PAGE, 57 FORCE_CLOSE_INTERNALS_PAGE,
54 FORCE_CLOSE_COPY_ORIGIN, 58 FORCE_CLOSE_COPY_ORIGIN,
55 FORCE_CLOSE_REASON_MAX 59 FORCE_CLOSE_REASON_MAX
56 }; 60 };
57 61
58 // The indexed db directory. 62 // The indexed db directory.
59 static const base::FilePath::CharType kIndexedDBDirectory[]; 63 static const base::FilePath::CharType kIndexedDBDirectory[];
60 64
61 // If |data_path| is empty, nothing will be saved to disk. 65 // If |data_path| is empty, nothing will be saved to disk.
62 IndexedDBContextImpl(const base::FilePath& data_path, 66 IndexedDBContextImpl(const base::FilePath& data_path,
63 storage::SpecialStoragePolicy* special_storage_policy, 67 storage::SpecialStoragePolicy* special_storage_policy,
64 storage::QuotaManagerProxy* quota_manager_proxy, 68 storage::QuotaManagerProxy* quota_manager_proxy,
65 base::SequencedTaskRunner* task_runner); 69 base::SingleThreadTaskRunner* task_runner);
66 70
67 IndexedDBFactory* GetIDBFactory(); 71 IndexedDBFactory* GetIDBFactory();
68 72
69 // Disables the exit-time deletion of session-only data. 73 // Disables the exit-time deletion of session-only data.
70 void SetForceKeepSessionState() { force_keep_session_state_ = true; } 74 void SetForceKeepSessionState() { force_keep_session_state_ = true; }
71 75
72 // IndexedDBContext implementation: 76 // IndexedDBContext implementation:
73 base::SequencedTaskRunner* TaskRunner() const override; 77 base::SingleThreadTaskRunner* TaskRunner() const override;
74 std::vector<IndexedDBInfo> GetAllOriginsInfo() override; 78 std::vector<IndexedDBInfo> GetAllOriginsInfo() override;
75 int64_t GetOriginDiskUsage(const GURL& origin_url) override; 79 int64_t GetOriginDiskUsage(const GURL& origin_url) override;
76 void DeleteForOrigin(const GURL& origin_url) override; 80 void DeleteForOrigin(const GURL& origin_url) override;
77 void CopyOriginData(const GURL& origin_url, 81 void CopyOriginData(const GURL& origin_url,
78 IndexedDBContext* dest_context) override; 82 IndexedDBContext* dest_context) override;
79 base::FilePath GetFilePathForTesting(const GURL& origin_url) const override; 83 base::FilePath GetFilePathForTesting(const GURL& origin_url) const override;
80 void SetTaskRunnerForTesting(base::SequencedTaskRunner* task_runner) override; 84 void SetTaskRunnerForTesting(
85 base::SingleThreadTaskRunner* task_runner) override;
86 void TransactionComplete(const url::Origin& origin) override;
81 87
82 // TODO(jsbell): Replace IndexedDBContext members with these. 88 // TODO(jsbell): Replace IndexedDBContext members with these.
83 int64_t GetOriginDiskUsage(const url::Origin& origin); 89 int64_t GetOriginDiskUsage(const url::Origin& origin);
84 void DeleteForOrigin(const url::Origin& origin); 90 void DeleteForOrigin(const url::Origin& origin);
85 void CopyOriginData(const url::Origin& origin, 91 void CopyOriginData(const url::Origin& origin,
86 IndexedDBContext* dest_context); 92 IndexedDBContext* dest_context);
87 base::FilePath GetFilePathForTesting(const url::Origin& origin) const; 93 base::FilePath GetFilePathForTesting(const url::Origin& origin) const;
88 94
89 // Methods called by IndexedDBDispatcherHost for quota support. 95 // Methods called by IndexedDBDispatcherHost for quota support.
90 void ConnectionOpened(const url::Origin& origin, IndexedDBConnection* db); 96 void ConnectionOpened(const url::Origin& origin, IndexedDBConnection* db);
91 void ConnectionClosed(const url::Origin& origin, IndexedDBConnection* db); 97 void ConnectionClosed(const url::Origin& origin, IndexedDBConnection* db);
92 void TransactionComplete(const url::Origin& origin);
93 void DatabaseDeleted(const url::Origin& origin); 98 void DatabaseDeleted(const url::Origin& origin);
94 99
95 static base::FilePath GetBlobStoreFileName(const url::Origin& origin); 100 static base::FilePath GetBlobStoreFileName(const url::Origin& origin);
96 static base::FilePath GetLevelDBFileName(const url::Origin& origin); 101 static base::FilePath GetLevelDBFileName(const url::Origin& origin);
97 102
98 // Will be null in unit tests. 103 // Will be null in unit tests.
99 storage::QuotaManagerProxy* quota_manager_proxy() const { 104 storage::QuotaManagerProxy* quota_manager_proxy() const override;
100 return quota_manager_proxy_.get();
101 }
102 105
103 // Returns a list of all origins with backing stores. 106 // Returns a list of all origins with backing stores.
104 std::vector<url::Origin> GetAllOrigins(); 107 std::vector<url::Origin> GetAllOrigins();
105 bool HasOrigin(const url::Origin& origin); 108 bool HasOrigin(const url::Origin& origin);
106 109
107 // Used by IndexedDBInternalsUI to populate internals page. 110 // Used by IndexedDBInternalsUI to populate internals page.
111 #if 0
108 base::ListValue* GetAllOriginsDetails(); 112 base::ListValue* GetAllOriginsDetails();
113 #endif
109 114
110 // ForceClose takes a value rather than a reference since it may release the 115 // ForceClose takes a value rather than a reference since it may release the
111 // owning object. 116 // owning object.
112 void ForceClose(const url::Origin origin, ForceCloseReason reason); 117 void ForceClose(const url::Origin origin, ForceCloseReason reason);
113 // GetStoragePaths returns all paths owned by this database, in arbitrary 118 // GetStoragePaths returns all paths owned by this database, in arbitrary
114 // order. 119 // order.
115 std::vector<base::FilePath> GetStoragePaths(const url::Origin& origin) const; 120 std::vector<base::FilePath> GetStoragePaths(const url::Origin& origin) const;
116 121
117 base::FilePath data_path() const { return data_path_; } 122 base::FilePath data_path() const { return data_path_; }
118 size_t GetConnectionCount(const url::Origin& origin); 123 size_t GetConnectionCount(const url::Origin& origin);
119 int GetOriginBlobFileCount(const url::Origin& origin); 124 int GetOriginBlobFileCount(const url::Origin& origin);
120 125
121 // For unit tests allow to override the |data_path_|. 126 // For unit tests allow to override the |data_path_|.
122 void set_data_path_for_testing(const base::FilePath& data_path) { 127 void set_data_path_for_testing(const base::FilePath& data_path) {
123 data_path_ = data_path; 128 data_path_ = data_path;
124 } 129 }
125 130
126 bool is_incognito() const { return data_path_.empty(); } 131 bool is_incognito() const { return data_path_.empty(); }
127 132
133 void Bind(
134 mojo::InterfaceRequest<::indexed_db::mojom::DatabaseFactory> request);
135
128 protected: 136 protected:
129 ~IndexedDBContextImpl() override; 137 ~IndexedDBContextImpl() override;
130 138
131 private: 139 private:
132 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ClearLocalState); 140 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ClearLocalState);
133 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ClearSessionOnlyDatabases); 141 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ClearSessionOnlyDatabases);
134 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, SetForceKeepSessionState); 142 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, SetForceKeepSessionState);
135 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ForceCloseOpenDatabasesOnDelete); 143 FRIEND_TEST_ALL_PREFIXES(IndexedDBTest, ForceCloseOpenDatabasesOnDelete);
136 friend class IndexedDBQuotaClientTest; 144 friend class IndexedDBQuotaClientTest;
137 145
(...skipping 12 matching lines...) Expand all
150 return GetOriginSet()->insert(origin).second; 158 return GetOriginSet()->insert(origin).second;
151 } 159 }
152 void RemoveFromOriginSet(const url::Origin& origin) { 160 void RemoveFromOriginSet(const url::Origin& origin) {
153 GetOriginSet()->erase(origin); 161 GetOriginSet()->erase(origin);
154 } 162 }
155 163
156 // Only for testing. 164 // Only for testing.
157 void ResetCaches(); 165 void ResetCaches();
158 166
159 scoped_refptr<IndexedDBFactory> factory_; 167 scoped_refptr<IndexedDBFactory> factory_;
168 DatabaseFactoryImpl* mojo_factory_;
160 base::FilePath data_path_; 169 base::FilePath data_path_;
161 // If true, nothing (not even session-only data) should be deleted on exit. 170 // If true, nothing (not even session-only data) should be deleted on exit.
162 bool force_keep_session_state_; 171 bool force_keep_session_state_;
163 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; 172 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
164 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; 173 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
165 scoped_refptr<base::SequencedTaskRunner> task_runner_; 174 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
166 std::unique_ptr<std::set<url::Origin>> origin_set_; 175 std::unique_ptr<std::set<url::Origin>> origin_set_;
167 std::map<url::Origin, int64_t> origin_size_map_; 176 std::map<url::Origin, int64_t> origin_size_map_;
168 177
169 DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl); 178 DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl);
170 }; 179 };
171 180
172 } // namespace content 181 } // namespace content
173 182
174 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_ 183 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CONTEXT_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_connection.cc ('k') | content/browser/indexed_db/indexed_db_context_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698