Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 mojo::InterfaceRequest<leveldb::LevelDBService> request) | |
| 17 : base::Thread("profile/LevelDBThread"), | |
| 18 parent_thread_message_loop_ref_(std::move(message_loop_ref)), | |
| 19 initial_leveldb_request_(std::move(request)) { | |
| 20 base::Thread::Options options; | |
| 21 options.message_pump_factory = | |
| 22 base::Bind(&mojo::common::MessagePumpMojo::Create); | |
|
Ben Goodger (Google)
2016/03/11 23:21:37
I don't believe you have to do this anymore.
Elliot Glaysher
2016/03/14 20:33:20
If I don't do this, I get:
Check failed: GetTh
Ben Goodger (Google)
2016/03/14 22:25:57
I think you should use another MessagePump type th
Elliot Glaysher
2016/03/14 23:14:53
Done. (There's a weird interaction where Threads u
| |
| 23 StartWithOptions(options); | |
| 24 } | |
| 25 | |
| 26 LevelDBThread::~LevelDBThread() {} | |
| 27 | |
| 28 void LevelDBThread::OnServiceError() { | |
| 29 if (leveldb_bindings_->empty()) { | |
| 30 // We have released the last leveldb service holding on to our reference; | |
| 31 // release our service and bindings. We need to do this on connection error | |
| 32 // so that it happens on our db thread and not our parent thread. | |
| 33 leveldb_service_.reset(); | |
| 34 leveldb_bindings_.reset(); | |
|
Ben Goodger (Google)
2016/03/11 23:21:37
rather than use a scoped_ptr<mojo::BindingSet<>>,
Elliot Glaysher
2016/03/14 20:33:20
I can not do that without getting CalledOnValidThr
Ben Goodger (Google)
2016/03/14 22:25:57
What thread is this called on and what thread are
Elliot Glaysher
2016/03/14 23:14:53
This base::Thread is started up, and in LevelDBThr
| |
| 35 } | |
| 36 } | |
| 37 | |
| 38 void LevelDBThread::BindNewRequest( | |
| 39 mojo::InterfaceRequest<leveldb::LevelDBService> request) { | |
| 40 DCHECK_NE(GetThreadId(), base::PlatformThread::CurrentId()); | |
| 41 task_runner()->PostTask( | |
| 42 FROM_HERE, base::Bind(&LevelDBThread::BindNewRequestImpl, this, | |
| 43 base::Passed(&request))); | |
| 44 } | |
| 45 | |
| 46 void LevelDBThread::BindNewRequestImpl( | |
| 47 mojo::InterfaceRequest<leveldb::LevelDBService> request) { | |
|
Ben Goodger (Google)
2016/03/11 23:21:38
nit: here, and elsewhere, the new hotness is to us
| |
| 48 DCHECK_EQ(GetThreadId(), base::PlatformThread::CurrentId()); | |
| 49 DCHECK(leveldb_service_); | |
| 50 leveldb_bindings_->AddBinding(leveldb_service_.get(), std::move(request)); | |
| 51 } | |
| 52 | |
| 53 void LevelDBThread::Init() { | |
| 54 leveldb_service_.reset(new leveldb::LevelDBServiceImpl( | |
| 55 thread_message_loop_ref_.CreateRef())); | |
| 56 leveldb_bindings_.reset(new mojo::BindingSet<leveldb::LevelDBService>); | |
| 57 leveldb_bindings_->set_connection_error_handler( | |
| 58 base::Bind(&LevelDBThread::OnServiceError, base::Unretained(this))); | |
| 59 leveldb_bindings_->AddBinding(leveldb_service_.get(), | |
| 60 std::move(initial_leveldb_request_)); | |
| 61 } | |
| 62 | |
| 63 void LevelDBThread::CleanUp() { | |
| 64 parent_thread_message_loop_ref_.reset(); | |
|
michaeln
2016/03/16 03:11:12
Maybe cleanup long lived objects with thread affin
| |
| 65 } | |
| 66 | |
| 67 } // namespace profile | |
| OLD | NEW |