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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/profile_service/leveldb_thread.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "components/leveldb/leveldb_service_impl.h"
10 #include "mojo/message_pump/message_pump_mojo.h"
11
12 namespace profile {
13
14 LevelDBThread::LevelDBThread(
15 scoped_ptr<mojo::MessageLoopRef> message_loop_ref,
16 leveldb::LevelDBServiceRequest request)
17 : base::Thread("profile/LevelDBThread"),
18 profile_service_message_loop_ref_(std::move(message_loop_ref)),
19 initial_leveldb_request_(std::move(request)) {
20 Start();
21 }
22
23 LevelDBThread::~LevelDBThread() {
24 Stop();
25 }
26
27 void LevelDBThread::OnServiceError() {
28 if (leveldb_bindings_->empty()) {
29 // We have released the last leveldb service holding on to our reference;
30 // release our service and bindings. We need to do this on connection error
31 // so that it happens on our db thread and not our parent thread.
32 leveldb_service_.reset();
michaeln 2016/03/16 03:11:13 Does this cause the threadmsg loop ref to drop to
33 leveldb_bindings_.reset();
34 }
35 }
36
37 void LevelDBThread::BindNewRequest(leveldb::LevelDBServiceRequest request) {
38 DCHECK_NE(GetThreadId(), base::PlatformThread::CurrentId());
39 task_runner()->PostTask(
40 FROM_HERE, base::Bind(&LevelDBThread::BindNewRequestImpl, this,
41 base::Passed(&request)));
42 }
43
44 void LevelDBThread::BindNewRequestImpl(leveldb::LevelDBServiceRequest request) {
45 DCHECK_EQ(GetThreadId(), base::PlatformThread::CurrentId());
46 DCHECK(leveldb_service_);
michaeln 2016/03/16 03:11:13 Is this racey? What guarantees levelddb_service a
47 leveldb_bindings_->AddBinding(leveldb_service_.get(), std::move(request));
48 }
49
50 void LevelDBThread::Init() {
51 leveldb_service_.reset(new leveldb::LevelDBServiceImpl(
52 thread_message_loop_ref_.CreateRef()));
53 leveldb_bindings_.reset(new mojo::BindingSet<leveldb::LevelDBService>);
54 leveldb_bindings_->set_connection_error_handler(
55 base::Bind(&LevelDBThread::OnServiceError, base::Unretained(this)));
56 leveldb_bindings_->AddBinding(leveldb_service_.get(),
57 std::move(initial_leveldb_request_));
58 }
59
60 void LevelDBThread::CleanUp() {
61 SetThreadWasQuitProperly(true);
62 profile_service_message_loop_ref_.reset();
63 }
64
65 } // namespace profile
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698