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

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

Issue 1823813002: mojo leveldb: Add support to use in memory database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add memory read write unittest Created 4 years, 9 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 | « components/leveldb/public/interfaces/leveldb.mojom ('k') | no next file » | 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"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 base::WeakPtrFactory<MojoState> weak_ptr_factory_; 125 base::WeakPtrFactory<MojoState> weak_ptr_factory_;
126 }; 126 };
127 127
128 void DOMStorageContextWrapper::MojoState::OpenLocalStorage( 128 void DOMStorageContextWrapper::MojoState::OpenLocalStorage(
129 const url::Origin& origin, 129 const url::Origin& origin,
130 LevelDBWrapperRequest request) { 130 LevelDBWrapperRequest request) {
131 // If we don't have a specific subdirectory where we want to put our data 131 // If we don't have a specific subdirectory where we want to put our data
132 // (ie, we're in incognito mode), just bind the storage with a null leveldb_ 132 // (ie, we're in incognito mode), just bind the storage with a null leveldb_
133 // database. 133 // database.
134 if (subdirectory_.empty()) { 134 if (subdirectory_.empty()) {
michaeln 2016/03/22 21:15:10 did you mean to delete this block now so we always
135 BindLocalStorage(origin, std::move(request)); 135 BindLocalStorage(origin, std::move(request));
136 return; 136 return;
137 } 137 }
138 138
139 // If we don't have a filesystem_connection_, we'll need to establish one. 139 // If we don't have a filesystem_connection_, we'll need to establish one.
140 if (connection_state_ == NO_CONNECTION) { 140 if (connection_state_ == NO_CONNECTION) {
141 profile_app_connection_ = MojoAppConnection::Create( 141 profile_app_connection_ = MojoAppConnection::Create(
142 mojo_user_id_, "mojo:profile", kBrowserMojoAppUrl); 142 mojo_user_id_, "mojo:profile", kBrowserMojoAppUrl);
143 profile_app_connection_->GetInterface(&profile_service_);
144 143
145 profile_service_->GetSubDirectory(
146 mojo::String::From(subdirectory_.AsUTF8Unsafe()),
147 GetProxy(&directory_),
148 base::Bind(&MojoState::OnDirectoryOpened,
149 weak_ptr_factory_.GetWeakPtr()));
150 connection_state_ = CONNECTION_IN_PROGRESS; 144 connection_state_ = CONNECTION_IN_PROGRESS;
145
146 if (!subdirectory_.empty()) {
147 // We were given a subdirectory to write to. Get it and use a disk backed
148 // database.
149 profile_app_connection_->GetInterface(&profile_service_);
150 profile_service_->GetSubDirectory(
151 mojo::String::From(subdirectory_.AsUTF8Unsafe()),
152 GetProxy(&directory_),
153 base::Bind(&MojoState::OnDirectoryOpened,
154 weak_ptr_factory_.GetWeakPtr()));
155 } else {
156 // We were not given a subdirectory. Use a memory backed database.
157 profile_app_connection_->GetInterface(&leveldb_service_);
158 leveldb_service_->OpenInMemory(
159 GetProxy(&database_),
160 base::Bind(&MojoState::OnDatabaseOpened,
161 weak_ptr_factory_.GetWeakPtr()));
162 }
151 } 163 }
152 164
153 if (connection_state_ == CONNECTION_IN_PROGRESS) { 165 if (connection_state_ == CONNECTION_IN_PROGRESS) {
154 // Queue this OpenLocalStorage call for when we have a level db pointer. 166 // Queue this OpenLocalStorage call for when we have a level db pointer.
155 on_database_opened_callbacks_.push_back( 167 on_database_opened_callbacks_.push_back(
156 base::Bind(&MojoState::BindLocalStorage, weak_ptr_factory_.GetWeakPtr(), 168 base::Bind(&MojoState::BindLocalStorage, weak_ptr_factory_.GetWeakPtr(),
157 origin, base::Passed(&request))); 169 origin, base::Passed(&request)));
158 return; 170 return;
159 } 171 }
160 172
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, 341 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
330 base::Bind(&DOMStorageContextImpl::Flush, context_)); 342 base::Bind(&DOMStorageContextImpl::Flush, context_));
331 } 343 }
332 344
333 void DOMStorageContextWrapper::OpenLocalStorage(const url::Origin& origin, 345 void DOMStorageContextWrapper::OpenLocalStorage(const url::Origin& origin,
334 LevelDBWrapperRequest request) { 346 LevelDBWrapperRequest request) {
335 mojo_state_->OpenLocalStorage(origin, std::move(request)); 347 mojo_state_->OpenLocalStorage(origin, std::move(request));
336 } 348 }
337 349
338 } // namespace content 350 } // namespace content
OLDNEW
« no previous file with comments | « components/leveldb/public/interfaces/leveldb.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698