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

Unified Diff: components/profile_service/leveldb_thread.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: ben comments 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 side-by-side diff with in-line comments
Download patch
Index: components/profile_service/leveldb_thread.cc
diff --git a/components/profile_service/leveldb_thread.cc b/components/profile_service/leveldb_thread.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e4f60d959761d19ad97a762b6dde4151025c33fa
--- /dev/null
+++ b/components/profile_service/leveldb_thread.cc
@@ -0,0 +1,65 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/profile_service/leveldb_thread.h"
+
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+#include "components/leveldb/leveldb_service_impl.h"
+#include "mojo/message_pump/message_pump_mojo.h"
+
+namespace profile {
+
+LevelDBThread::LevelDBThread(
+ scoped_ptr<mojo::MessageLoopRef> message_loop_ref,
+ leveldb::LevelDBServiceRequest request)
+ : base::Thread("profile/LevelDBThread"),
+ profile_service_message_loop_ref_(std::move(message_loop_ref)),
+ initial_leveldb_request_(std::move(request)) {
+ Start();
+}
+
+LevelDBThread::~LevelDBThread() {
+ Stop();
+}
+
+void LevelDBThread::OnServiceError() {
+ if (leveldb_bindings_->empty()) {
+ // We have released the last leveldb service holding on to our reference;
+ // release our service and bindings. We need to do this on connection error
+ // so that it happens on our db thread and not our parent thread.
+ leveldb_service_.reset();
michaeln 2016/03/16 03:11:13 Does this cause the threadmsg loop ref to drop to
+ leveldb_bindings_.reset();
+ }
+}
+
+void LevelDBThread::BindNewRequest(leveldb::LevelDBServiceRequest request) {
+ DCHECK_NE(GetThreadId(), base::PlatformThread::CurrentId());
+ task_runner()->PostTask(
+ FROM_HERE, base::Bind(&LevelDBThread::BindNewRequestImpl, this,
+ base::Passed(&request)));
+}
+
+void LevelDBThread::BindNewRequestImpl(leveldb::LevelDBServiceRequest request) {
+ DCHECK_EQ(GetThreadId(), base::PlatformThread::CurrentId());
+ DCHECK(leveldb_service_);
michaeln 2016/03/16 03:11:13 Is this racey? What guarantees levelddb_service a
+ leveldb_bindings_->AddBinding(leveldb_service_.get(), std::move(request));
+}
+
+void LevelDBThread::Init() {
+ leveldb_service_.reset(new leveldb::LevelDBServiceImpl(
+ thread_message_loop_ref_.CreateRef()));
+ leveldb_bindings_.reset(new mojo::BindingSet<leveldb::LevelDBService>);
+ leveldb_bindings_->set_connection_error_handler(
+ base::Bind(&LevelDBThread::OnServiceError, base::Unretained(this)));
+ leveldb_bindings_->AddBinding(leveldb_service_.get(),
+ std::move(initial_leveldb_request_));
+}
+
+void LevelDBThread::CleanUp() {
+ SetThreadWasQuitProperly(true);
+ profile_service_message_loop_ref_.reset();
+}
+
+} // namespace profile

Powered by Google App Engine
This is Rietveld 408576698