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

Side by Side Diff: content/browser/dom_storage/dom_storage_context_wrapper.cc

Issue 1879233002: Move components\profile_service to services\user (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move3
Patch Set: . Created 4 years, 8 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
« no previous file with comments | « content/browser/browser_context.cc ('k') | content/browser/mojo/mojo_shell_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" 5 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
19 #include "components/filesystem/public/interfaces/directory.mojom.h" 19 #include "components/filesystem/public/interfaces/directory.mojom.h"
20 #include "components/leveldb/public/interfaces/leveldb.mojom.h" 20 #include "components/leveldb/public/interfaces/leveldb.mojom.h"
21 #include "components/profile_service/public/cpp/constants.h"
22 #include "components/profile_service/public/interfaces/profile.mojom.h"
23 #include "content/browser/dom_storage/dom_storage_area.h" 21 #include "content/browser/dom_storage/dom_storage_area.h"
24 #include "content/browser/dom_storage/dom_storage_context_impl.h" 22 #include "content/browser/dom_storage/dom_storage_context_impl.h"
25 #include "content/browser/dom_storage/dom_storage_task_runner.h" 23 #include "content/browser/dom_storage/dom_storage_task_runner.h"
26 #include "content/browser/dom_storage/session_storage_namespace_impl.h" 24 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
27 #include "content/browser/leveldb_wrapper_impl.h" 25 #include "content/browser/leveldb_wrapper_impl.h"
28 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/local_storage_usage_info.h" 27 #include "content/public/browser/local_storage_usage_info.h"
30 #include "content/public/browser/session_storage_usage_info.h" 28 #include "content/public/browser/session_storage_usage_info.h"
31 #include "mojo/common/common_type_converters.h" 29 #include "mojo/common/common_type_converters.h"
32 #include "services/shell/public/cpp/connection.h" 30 #include "services/shell/public/cpp/connection.h"
33 #include "services/shell/public/cpp/connector.h" 31 #include "services/shell/public/cpp/connector.h"
32 #include "services/user/public/cpp/constants.h"
33 #include "services/user/public/interfaces/user_service.mojom.h"
34 34
35 namespace content { 35 namespace content {
36 namespace { 36 namespace {
37 37
38 const char kLocalStorageDirectory[] = "Local Storage"; 38 const char kLocalStorageDirectory[] = "Local Storage";
39 const char kSessionStorageDirectory[] = "Session Storage"; 39 const char kSessionStorageDirectory[] = "Session Storage";
40 40
41 void InvokeLocalStorageUsageCallbackHelper( 41 void InvokeLocalStorageUsageCallbackHelper(
42 const DOMStorageContext::GetLocalStorageUsageCallback& callback, 42 const DOMStorageContext::GetLocalStorageUsageCallback& callback,
43 const std::vector<LocalStorageUsageInfo>* infos) { 43 const std::vector<LocalStorageUsageInfo>* infos) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 mojo::Connector* const connector_; 112 mojo::Connector* const connector_;
113 const base::FilePath subdirectory_; 113 const base::FilePath subdirectory_;
114 114
115 enum ConnectionState { 115 enum ConnectionState {
116 NO_CONNECTION, 116 NO_CONNECTION,
117 CONNECTION_IN_PROGRESS, 117 CONNECTION_IN_PROGRESS,
118 CONNECTION_FINISHED 118 CONNECTION_FINISHED
119 } connection_state_; 119 } connection_state_;
120 120
121 std::unique_ptr<mojo::Connection> profile_app_connection_; 121 std::unique_ptr<mojo::Connection> user_service_connection_;
122 122
123 profile::ProfileServicePtr profile_service_; 123 user_service::mojom::UserServicePtr user_service_;
124 filesystem::DirectoryPtr directory_; 124 filesystem::DirectoryPtr directory_;
125 125
126 leveldb::LevelDBServicePtr leveldb_service_; 126 leveldb::LevelDBServicePtr leveldb_service_;
127 leveldb::LevelDBDatabasePtr database_; 127 leveldb::LevelDBDatabasePtr database_;
128 128
129 std::vector<base::Closure> on_database_opened_callbacks_; 129 std::vector<base::Closure> on_database_opened_callbacks_;
130 130
131 base::WeakPtrFactory<MojoState> weak_ptr_factory_; 131 base::WeakPtrFactory<MojoState> weak_ptr_factory_;
132 }; 132 };
133 133
134 void DOMStorageContextWrapper::MojoState::OpenLocalStorage( 134 void DOMStorageContextWrapper::MojoState::OpenLocalStorage(
135 const url::Origin& origin, 135 const url::Origin& origin,
136 mojom::LevelDBObserverPtr observer, 136 mojom::LevelDBObserverPtr observer,
137 mojom::LevelDBWrapperRequest request) { 137 mojom::LevelDBWrapperRequest request) {
138 // If we don't have a filesystem_connection_, we'll need to establish one. 138 // If we don't have a filesystem_connection_, we'll need to establish one.
139 if (connection_state_ == NO_CONNECTION) { 139 if (connection_state_ == NO_CONNECTION) {
140 CHECK(connector_); 140 CHECK(connector_);
141 profile_app_connection_ = 141 user_service_connection_ =
142 connector_->Connect(profile::kProfileMojoApplicationName); 142 connector_->Connect(user_service::kUserServiceName);
143 connection_state_ = CONNECTION_IN_PROGRESS; 143 connection_state_ = CONNECTION_IN_PROGRESS;
144 144
145 if (!subdirectory_.empty()) { 145 if (!subdirectory_.empty()) {
146 // We were given a subdirectory to write to. Get it and use a disk backed 146 // We were given a subdirectory to write to. Get it and use a disk backed
147 // database. 147 // database.
148 profile_app_connection_->GetInterface(&profile_service_); 148 user_service_connection_->GetInterface(&user_service_);
149 profile_service_->GetSubDirectory( 149 user_service_->GetSubDirectory(
150 mojo::String::From(subdirectory_.AsUTF8Unsafe()), 150 mojo::String::From(subdirectory_.AsUTF8Unsafe()),
151 GetProxy(&directory_), 151 GetProxy(&directory_),
152 base::Bind(&MojoState::OnDirectoryOpened, 152 base::Bind(&MojoState::OnDirectoryOpened,
153 weak_ptr_factory_.GetWeakPtr())); 153 weak_ptr_factory_.GetWeakPtr()));
154 } else { 154 } else {
155 // We were not given a subdirectory. Use a memory backed database. 155 // We were not given a subdirectory. Use a memory backed database.
156 profile_app_connection_->GetInterface(&leveldb_service_); 156 user_service_connection_->GetInterface(&leveldb_service_);
157 leveldb_service_->OpenInMemory( 157 leveldb_service_->OpenInMemory(
158 GetProxy(&database_), 158 GetProxy(&database_),
159 base::Bind(&MojoState::OnDatabaseOpened, 159 base::Bind(&MojoState::OnDatabaseOpened,
160 weak_ptr_factory_.GetWeakPtr())); 160 weak_ptr_factory_.GetWeakPtr()));
161 } 161 }
162 } 162 }
163 163
164 if (connection_state_ == CONNECTION_IN_PROGRESS) { 164 if (connection_state_ == CONNECTION_IN_PROGRESS) {
165 // Queue this OpenLocalStorage call for when we have a level db pointer. 165 // Queue this OpenLocalStorage call for when we have a level db pointer.
166 on_database_opened_callbacks_.push_back( 166 on_database_opened_callbacks_.push_back(
167 base::Bind(&MojoState::BindLocalStorage, weak_ptr_factory_.GetWeakPtr(), 167 base::Bind(&MojoState::BindLocalStorage, weak_ptr_factory_.GetWeakPtr(),
168 origin, base::Passed(&observer), base::Passed(&request))); 168 origin, base::Passed(&observer), base::Passed(&request)));
169 return; 169 return;
170 } 170 }
171 171
172 BindLocalStorage(origin, std::move(observer), std::move(request)); 172 BindLocalStorage(origin, std::move(observer), std::move(request));
173 } 173 }
174 174
175 void DOMStorageContextWrapper::MojoState::OnDirectoryOpened( 175 void DOMStorageContextWrapper::MojoState::OnDirectoryOpened(
176 filesystem::FileError err) { 176 filesystem::FileError err) {
177 if (err != filesystem::FileError::OK) { 177 if (err != filesystem::FileError::OK) {
178 // We failed to open the directory; continue with startup so that we create 178 // We failed to open the directory; continue with startup so that we create
179 // the |level_db_wrappers_|. 179 // the |level_db_wrappers_|.
180 OnDatabaseOpened(leveldb::DatabaseError::IO_ERROR); 180 OnDatabaseOpened(leveldb::DatabaseError::IO_ERROR);
181 return; 181 return;
182 } 182 }
183 183
184 // Now that we have a directory, connect to the LevelDB service and get our 184 // Now that we have a directory, connect to the LevelDB service and get our
185 // database. 185 // database.
186 profile_app_connection_->GetInterface(&leveldb_service_); 186 user_service_connection_->GetInterface(&leveldb_service_);
187 187
188 leveldb_service_->Open( 188 leveldb_service_->Open(
189 std::move(directory_), "leveldb", GetProxy(&database_), 189 std::move(directory_), "leveldb", GetProxy(&database_),
190 base::Bind(&MojoState::OnDatabaseOpened, weak_ptr_factory_.GetWeakPtr())); 190 base::Bind(&MojoState::OnDatabaseOpened, weak_ptr_factory_.GetWeakPtr()));
191 } 191 }
192 192
193 void DOMStorageContextWrapper::MojoState::OnDatabaseOpened( 193 void DOMStorageContextWrapper::MojoState::OnDatabaseOpened(
194 leveldb::DatabaseError status) { 194 leveldb::DatabaseError status) {
195 if (status != leveldb::DatabaseError::OK) { 195 if (status != leveldb::DatabaseError::OK) {
196 // If we failed to open the database, reset the service object so we pass 196 // If we failed to open the database, reset the service object so we pass
197 // null pointers to our wrappers. 197 // null pointers to our wrappers.
198 database_.reset(); 198 database_.reset();
199 leveldb_service_.reset(); 199 leveldb_service_.reset();
200 } 200 }
201 201
202 // We no longer need the profile service; we've either transferred 202 // We no longer need the user service; we've either transferred
203 // |directory_| to the leveldb service, or we got a file error and no more is 203 // |directory_| to the leveldb service, or we got a file error and no more is
204 // possible. 204 // possible.
205 directory_.reset(); 205 directory_.reset();
206 profile_service_.reset(); 206 user_service_.reset();
207 207
208 // |leveldb_| should be known to either be valid or invalid by now. Run our 208 // |leveldb_| should be known to either be valid or invalid by now. Run our
209 // delayed bindings. 209 // delayed bindings.
210 connection_state_ = CONNECTION_FINISHED; 210 connection_state_ = CONNECTION_FINISHED;
211 for (size_t i = 0; i < on_database_opened_callbacks_.size(); ++i) 211 for (size_t i = 0; i < on_database_opened_callbacks_.size(); ++i)
212 on_database_opened_callbacks_[i].Run(); 212 on_database_opened_callbacks_[i].Run();
213 on_database_opened_callbacks_.clear(); 213 on_database_opened_callbacks_.clear();
214 } 214 }
215 215
216 void DOMStorageContextWrapper::MojoState::BindLocalStorage( 216 void DOMStorageContextWrapper::MojoState::BindLocalStorage(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 346
347 void DOMStorageContextWrapper::OpenLocalStorage( 347 void DOMStorageContextWrapper::OpenLocalStorage(
348 const url::Origin& origin, 348 const url::Origin& origin,
349 mojom::LevelDBObserverPtr observer, 349 mojom::LevelDBObserverPtr observer,
350 mojom::LevelDBWrapperRequest request) { 350 mojom::LevelDBWrapperRequest request) {
351 mojo_state_->OpenLocalStorage( 351 mojo_state_->OpenLocalStorage(
352 origin, std::move(observer), std::move(request)); 352 origin, std::move(observer), std::move(request));
353 } 353 }
354 354
355 } // namespace content 355 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_context.cc ('k') | content/browser/mojo/mojo_shell_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698