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

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: how did i miss that... 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 leveldb::LevelDBDatabasePtr database_; 121 leveldb::LevelDBDatabasePtr database_;
122 122
123 std::vector<base::Closure> on_database_opened_callbacks_; 123 std::vector<base::Closure> on_database_opened_callbacks_;
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
132 // (ie, we're in incognito mode), just bind the storage with a null leveldb_
133 // database.
134 if (subdirectory_.empty()) {
135 BindLocalStorage(origin, std::move(request));
136 return;
137 }
138
139 // If we don't have a filesystem_connection_, we'll need to establish one. 131 // If we don't have a filesystem_connection_, we'll need to establish one.
140 if (connection_state_ == NO_CONNECTION) { 132 if (connection_state_ == NO_CONNECTION) {
141 profile_app_connection_ = MojoAppConnection::Create( 133 profile_app_connection_ = MojoAppConnection::Create(
142 mojo_user_id_, "mojo:profile", kBrowserMojoAppUrl); 134 mojo_user_id_, "mojo:profile", kBrowserMojoAppUrl);
143 profile_app_connection_->GetInterface(&profile_service_);
144 135
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; 136 connection_state_ = CONNECTION_IN_PROGRESS;
137
138 if (!subdirectory_.empty()) {
139 // We were given a subdirectory to write to. Get it and use a disk backed
140 // database.
141 profile_app_connection_->GetInterface(&profile_service_);
142 profile_service_->GetSubDirectory(
143 mojo::String::From(subdirectory_.AsUTF8Unsafe()),
144 GetProxy(&directory_),
145 base::Bind(&MojoState::OnDirectoryOpened,
146 weak_ptr_factory_.GetWeakPtr()));
147 } else {
148 // We were not given a subdirectory. Use a memory backed database.
149 profile_app_connection_->GetInterface(&leveldb_service_);
150 leveldb_service_->OpenInMemory(
151 GetProxy(&database_),
152 base::Bind(&MojoState::OnDatabaseOpened,
153 weak_ptr_factory_.GetWeakPtr()));
154 }
151 } 155 }
152 156
153 if (connection_state_ == CONNECTION_IN_PROGRESS) { 157 if (connection_state_ == CONNECTION_IN_PROGRESS) {
154 // Queue this OpenLocalStorage call for when we have a level db pointer. 158 // Queue this OpenLocalStorage call for when we have a level db pointer.
155 on_database_opened_callbacks_.push_back( 159 on_database_opened_callbacks_.push_back(
156 base::Bind(&MojoState::BindLocalStorage, weak_ptr_factory_.GetWeakPtr(), 160 base::Bind(&MojoState::BindLocalStorage, weak_ptr_factory_.GetWeakPtr(),
157 origin, base::Passed(&request))); 161 origin, base::Passed(&request)));
158 return; 162 return;
159 } 163 }
160 164
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, 333 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
330 base::Bind(&DOMStorageContextImpl::Flush, context_)); 334 base::Bind(&DOMStorageContextImpl::Flush, context_));
331 } 335 }
332 336
333 void DOMStorageContextWrapper::OpenLocalStorage(const url::Origin& origin, 337 void DOMStorageContextWrapper::OpenLocalStorage(const url::Origin& origin,
334 LevelDBWrapperRequest request) { 338 LevelDBWrapperRequest request) {
335 mojo_state_->OpenLocalStorage(origin, std::move(request)); 339 mojo_state_->OpenLocalStorage(origin, std::move(request));
336 } 340 }
337 341
338 } // namespace content 342 } // 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