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

Unified Diff: content/browser/dom_storage/dom_storage_context_wrapper.cc

Issue 1737933002: mojo leveldb: Get profile and leveldb connected to DOMStorageContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp-ify all the tracing stuff. Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/dom_storage/dom_storage_context_wrapper.cc
diff --git a/content/browser/dom_storage/dom_storage_context_wrapper.cc b/content/browser/dom_storage/dom_storage_context_wrapper.cc
index e58187f628324ffc62f5148167d983412489e9ed..6201c087f724f10f43ca6f5b6ec0a06d0aac15e8 100644
--- a/content/browser/dom_storage/dom_storage_context_wrapper.cc
+++ b/content/browser/dom_storage/dom_storage_context_wrapper.cc
@@ -13,6 +13,7 @@
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
+#include "components/filesystem/public/interfaces/file_system.mojom.h"
#include "content/browser/dom_storage/dom_storage_area.h"
#include "content/browser/dom_storage/dom_storage_context_impl.h"
#include "content/browser/dom_storage/dom_storage_task_runner.h"
@@ -20,7 +21,9 @@
#include "content/browser/level_db_wrapper_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/local_storage_usage_info.h"
+#include "content/public/browser/mojo_app_connection.h"
#include "content/public/browser/session_storage_usage_info.h"
+#include "mojo/util/capture_util.h"
namespace content {
namespace {
@@ -68,7 +71,9 @@ void GetSessionStorageUsageHelper(
DOMStorageContextWrapper::DOMStorageContextWrapper(
const base::FilePath& data_path,
- storage::SpecialStoragePolicy* special_storage_policy) {
+ storage::SpecialStoragePolicy* special_storage_policy)
+ : connection_state_(NO_CONNECTION),
+ weak_ptr_factory_(this) {
base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool();
context_ = new DOMStorageContextImpl(
data_path.empty() ? data_path
@@ -171,25 +176,73 @@ void DOMStorageContextWrapper::OpenLocalStorage(
const mojo::String& origin,
LevelDBObserverPtr observer,
mojo::InterfaceRequest<LevelDBWrapper> request) {
+ // If we don't have a filesystem_connection_, we'll need to establish one.
+ if (connection_state_ == NO_CONNECTION) {
+ file_system_connection_ = content::MojoAppConnection::Create(
+ GURL("mojo:filesystem"), GURL(content::kBrowserMojoAppUrl));
michaeln 2016/02/26 21:59:25 is there a way to provide the root_directory path
Elliot Glaysher 2016/03/02 23:06:19 This was the big reason I went off and did the Pro
+ file_system_connection_->GetInterface(&file_system_);
+
+ file_system_->OpenTempDirectory(
+ GetProxy(&directory_),
+ base::Bind(&DOMStorageContextWrapper::OnDirectoryOpened,
+ weak_ptr_factory_.GetWeakPtr()));
+ connection_state_ = CONNECITON_IN_PROGRESS;
+ }
+
+ if (connection_state_ == CONNECITON_IN_PROGRESS) {
+ // Queue this OpenLocalStorage call for when we have a level db pointer.
+ on_database_opened_callbacks_.push_back(
+ base::Bind(&DOMStorageContextWrapper::BindLocalStorage,
+ weak_ptr_factory_.GetWeakPtr(),
+ origin,
+ base::Passed(&observer),
+ base::Passed(&request)));
+ return;
+ }
+
+ BindLocalStorage(origin, std::move(observer), std::move(request));
+}
+
+void DOMStorageContextWrapper::LevelDBWrapperImplHasNoBindings(
+ const std::string& origin) {
+ // The DCHECK here broke on chrome-extensions.
+ level_db_wrappers_.erase(origin);
+}
+
+void DOMStorageContextWrapper::OnDirectoryOpened(filesystem::FileError err) {
michaeln 2016/02/26 21:59:25 what about err checking
+ // Now that we have a directory, connect to the LevelDB service and get our
+ // database.
+ leveldb_connection_ = content::MojoAppConnection::Create(
michaeln 2016/02/26 21:59:24 This ends up invoking the CreateLevelDbApp() funct
Elliot Glaysher 2016/03/02 23:06:19 I believe so. We connect to leveldb here, and then
+ GURL("mojo:leveldb"), GURL(content::kBrowserMojoAppUrl));
+ leveldb_connection_->GetInterface(&leveldb_);
+
+ leveldb_->Open(std::move(directory_), "dom_storage", GetProxy(&database_),
+ base::Bind(&DOMStorageContextWrapper::OnDatabaseOpened,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void DOMStorageContextWrapper::OnDatabaseOpened(leveldb::DatabaseError status) {
michaeln 2016/02/26 21:59:25 what about status checking?
+ // |database_| should be valid now. Run our delayed bindings.
+ connection_state_ = CONNECTED;
+ for (size_t i = 0; i < on_database_opened_callbacks_.size(); ++i)
+ on_database_opened_callbacks_[i].Run();
+ on_database_opened_callbacks_.clear();
+}
+
+void DOMStorageContextWrapper::BindLocalStorage(
+ const mojo::String& origin,
+ LevelDBObserverPtr observer,
+ mojo::InterfaceRequest<LevelDBWrapper> request) {
if (level_db_wrappers_.find(origin) == level_db_wrappers_.end()) {
level_db_wrappers_[origin] = make_scoped_ptr(new LevelDBWrapperImpl(
+ database_.get(),
origin,
base::Bind(&DOMStorageContextWrapper::LevelDBWrapperImplHasNoBindings,
base::Unretained(this),
origin.get())));
}
- // TODO(jam): call LevelDB service (once per this object) to open the database
- // for LocalStorage and keep a pointer to it in this class. Then keep a map
- // from origins to LevelDBWrapper object. Each call here for the same origin
- // should use the same LevelDBWrapper object.
level_db_wrappers_[origin]->Bind(std::move(request), std::move(observer));
}
-void DOMStorageContextWrapper::LevelDBWrapperImplHasNoBindings(
- const std::string& origin) {
- DCHECK(level_db_wrappers_.find(origin) != level_db_wrappers_.end());
- level_db_wrappers_.erase(origin);
-}
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698