Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "components/profile_service/profile_app.h" | 5 #include "components/profile_service/profile_app.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "components/leveldb/leveldb_service_impl.h" | 8 #include "components/leveldb/leveldb_service_impl.h" |
| 9 #include "components/profile_service/leveldb_thread.h" | |
| 9 #include "components/profile_service/profile_service_impl.h" | 10 #include "components/profile_service/profile_service_impl.h" |
| 10 #include "mojo/shell/public/cpp/connection.h" | 11 #include "mojo/shell/public/cpp/connection.h" |
| 11 | 12 |
| 12 namespace profile { | 13 namespace profile { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 base::LazyInstance<std::map<std::string, base::FilePath>> | 17 base::LazyInstance<std::map<std::string, base::FilePath>> |
| 17 g_user_id_to_data_dir = LAZY_INSTANCE_INITIALIZER; | 18 g_user_id_to_data_dir = LAZY_INSTANCE_INITIALIZER; |
| 18 | 19 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 32 void ProfileApp::AssociateMojoUserIDWithProfileDir( | 33 void ProfileApp::AssociateMojoUserIDWithProfileDir( |
| 33 const std::string& user_id, | 34 const std::string& user_id, |
| 34 const base::FilePath& profile_data_dir) { | 35 const base::FilePath& profile_data_dir) { |
| 35 g_user_id_to_data_dir.Get()[user_id] = profile_data_dir; | 36 g_user_id_to_data_dir.Get()[user_id] = profile_data_dir; |
| 36 } | 37 } |
| 37 | 38 |
| 38 void ProfileApp::Initialize(mojo::Connector* connector, | 39 void ProfileApp::Initialize(mojo::Connector* connector, |
| 39 const mojo::Identity& identity, | 40 const mojo::Identity& identity, |
| 40 uint32_t id) { | 41 uint32_t id) { |
| 41 tracing_.Initialize(connector, identity.name()); | 42 tracing_.Initialize(connector, identity.name()); |
| 42 leveldb_service_.reset(new leveldb::LevelDBServiceImpl); | |
| 43 | 43 |
| 44 auto it = g_user_id_to_data_dir.Get().find(identity.user_id()); | 44 auto it = g_user_id_to_data_dir.Get().find(identity.user_id()); |
| 45 DCHECK(it != g_user_id_to_data_dir.Get().end()); | 45 DCHECK(it != g_user_id_to_data_dir.Get().end()); |
| 46 profile_data_dir_ = it->second; | 46 profile_data_dir_ = it->second; |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool ProfileApp::AcceptConnection(mojo::Connection* connection) { | 49 bool ProfileApp::AcceptConnection(mojo::Connection* connection) { |
| 50 connection->AddInterface<leveldb::LevelDBService>(this); | 50 connection->AddInterface<leveldb::LevelDBService>(this); |
| 51 connection->AddInterface<ProfileService>(this); | 51 connection->AddInterface<ProfileService>(this); |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void ProfileApp::Create(mojo::Connection* connection, | 55 void ProfileApp::Create(mojo::Connection* connection, |
| 56 ProfileServiceRequest request) { | 56 ProfileServiceRequest request) { |
| 57 // No, we need one of these per connection. | 57 // No, we need one of these per connection. |
| 58 new ProfileServiceImpl(connection, | 58 new ProfileServiceImpl(connection, |
| 59 std::move(request), | 59 std::move(request), |
| 60 ref_factory_.CreateRef(), | |
| 60 profile_data_dir_, | 61 profile_data_dir_, |
| 61 lock_table_.get()); | 62 lock_table_.get()); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void ProfileApp::Create(mojo::Connection* connection, | 65 void ProfileApp::Create( |
| 65 leveldb::LevelDBServiceRequest request) { | 66 mojo::Connection* connection, |
|
Ben Goodger (Google)
2016/03/11 23:21:38
up to prev line
michaeln
2016/03/16 03:11:12
what is |connection| used for in this method?
Elliot Glaysher
2016/03/17 19:29:44
Nothing, but it's part of the virtual interface si
| |
| 66 leveldb_bindings_.AddBinding(leveldb_service_.get(), std::move(request)); | 67 leveldb::LevelDBServiceRequest request) { |
|
Ben Goodger (Google)
2016/03/11 23:21:38
indent over
| |
| 68 if (!leveldb_thread_) { | |
|
michaeln
2016/03/16 03:11:12
if OnServiceError() with empty bindings had alread
| |
| 69 leveldb_thread_ = new LevelDBThread( | |
| 70 ref_factory_.CreateRef(), | |
| 71 std::move(request)); | |
| 72 } else { | |
| 73 // We need to pass this binding to the leveldb thread. | |
| 74 leveldb_thread_->BindNewRequest(std::move(request)); | |
| 75 } | |
| 67 } | 76 } |
| 68 | 77 |
| 69 } // namespace profile | 78 } // namespace profile |
| OLD | NEW |