| 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" | |
| 9 #include "components/profile_service/profile_service_impl.h" | 8 #include "components/profile_service/profile_service_impl.h" |
| 10 #include "mojo/shell/public/cpp/connection.h" | 9 #include "mojo/shell/public/cpp/connection.h" |
| 11 | 10 |
| 12 namespace profile { | 11 namespace profile { |
| 13 | 12 |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 base::LazyInstance<std::map<uint32_t, base::FilePath>> g_user_id_to_data_dir = | 15 base::LazyInstance<std::map<uint32_t, base::FilePath>> g_user_id_to_data_dir = |
| 17 LAZY_INSTANCE_INITIALIZER; | 16 LAZY_INSTANCE_INITIALIZER; |
| 18 | 17 |
| 19 } // namespace | 18 } // namespace |
| 20 | 19 |
| 21 scoped_ptr<mojo::ShellClient> CreateProfileApp() { | 20 scoped_ptr<mojo::ShellClient> CreateProfileApp() { |
| 22 return make_scoped_ptr(new ProfileApp); | 21 return make_scoped_ptr(new ProfileApp); |
| 23 } | 22 } |
| 24 | 23 |
| 25 ProfileApp::ProfileApp() | 24 ProfileApp::ProfileApp() |
| 26 : lock_table_(new filesystem::LockTable) { | 25 : lock_table_(new filesystem::LockTable) { |
| 27 } | 26 } |
| 28 | 27 |
| 29 ProfileApp::~ProfileApp() {} | 28 ProfileApp::~ProfileApp() {} |
| 30 | 29 |
| 31 // static | 30 // static |
| 32 void ProfileApp::AssociateMojoUserIDWithProfileDir( | 31 void ProfileApp::AssociateMojoUserIDWithProfileDir( |
| 33 uint32_t user_id, | 32 uint32_t user_id, |
| 34 const base::FilePath& profile_data_dir) { | 33 const base::FilePath& profile_data_dir) { |
| 34 LOG(ERROR) << "Registering user_id " << user_id << " to " |
| 35 << profile_data_dir.value(); |
| 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 std::string& url, | 40 const std::string& url, |
| 40 uint32_t id, | 41 uint32_t id, |
| 41 uint32_t user_id) { | 42 uint32_t user_id) { |
| 42 tracing_.Initialize(connector, url); | 43 tracing_.Initialize(connector, url); |
| 43 leveldb_service_.reset(new leveldb::LevelDBServiceImpl); | |
| 44 | 44 |
| 45 LOG(ERROR) << "Received connection from " << user_id; |
| 45 auto it = g_user_id_to_data_dir.Get().find(user_id); | 46 auto it = g_user_id_to_data_dir.Get().find(user_id); |
| 46 DCHECK(it != g_user_id_to_data_dir.Get().end()); | 47 DCHECK(it != g_user_id_to_data_dir.Get().end()); |
| 47 profile_data_dir_ = it->second; | 48 profile_data_dir_ = it->second; |
| 48 } | 49 } |
| 49 | 50 |
| 50 bool ProfileApp::AcceptConnection(mojo::Connection* connection) { | 51 bool ProfileApp::AcceptConnection(mojo::Connection* connection) { |
| 51 connection->AddInterface<leveldb::LevelDBService>(this); | |
| 52 connection->AddInterface<ProfileService>(this); | 52 connection->AddInterface<ProfileService>(this); |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ProfileApp::Create(mojo::Connection* connection, | 56 void ProfileApp::Create(mojo::Connection* connection, |
| 57 mojo::InterfaceRequest<ProfileService> request) { | 57 mojo::InterfaceRequest<ProfileService> request) { |
| 58 // No, we need one of these per connection. | 58 // No, we need one of these per connection. |
| 59 new ProfileServiceImpl(connection, | 59 new ProfileServiceImpl(connection, |
| 60 std::move(request), | 60 std::move(request), |
| 61 profile_data_dir_, | 61 profile_data_dir_, |
| 62 lock_table_.get()); | 62 lock_table_.get()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void ProfileApp::Create( | |
| 66 mojo::Connection* connection, | |
| 67 mojo::InterfaceRequest<leveldb::LevelDBService> request) { | |
| 68 leveldb_bindings_.AddBinding(leveldb_service_.get(), std::move(request)); | |
| 69 } | |
| 70 | |
| 71 } // namespace profile | 65 } // namespace profile |
| OLD | NEW |