| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "components/filesystem/lock_table.h" | 9 #include "components/filesystem/lock_table.h" |
| 10 #include "components/leveldb/leveldb_service_impl.h" | 10 #include "components/leveldb/leveldb_service_impl.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 scoped_refptr<filesystem::LockTable> lock_table_; | 40 scoped_refptr<filesystem::LockTable> lock_table_; |
| 41 base::FilePath profile_data_dir_; | 41 base::FilePath profile_data_dir_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(ProfileServiceObjects); | 43 DISALLOW_COPY_AND_ASSIGN(ProfileServiceObjects); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class ProfileApp::LevelDBServiceObjects | 46 class ProfileApp::LevelDBServiceObjects |
| 47 : public base::SupportsWeakPtr<LevelDBServiceObjects> { | 47 : public base::SupportsWeakPtr<LevelDBServiceObjects> { |
| 48 public: | 48 public: |
| 49 // Created on the main thread. | 49 // Created on the main thread. |
| 50 LevelDBServiceObjects() {} | 50 LevelDBServiceObjects(scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 51 : task_runner_(std::move(task_runner)) {} |
| 51 | 52 |
| 52 // Destroyed on the |leveldb_service_runner_|. | 53 // Destroyed on the |leveldb_service_runner_|. |
| 53 ~LevelDBServiceObjects() {} | 54 ~LevelDBServiceObjects() {} |
| 54 | 55 |
| 55 // Called on the |leveldb_service_runner_|. | 56 // Called on the |leveldb_service_runner_|. |
| 56 void OnLevelDBServiceRequest(mojo::Connection* connection, | 57 void OnLevelDBServiceRequest(mojo::Connection* connection, |
| 57 leveldb::LevelDBServiceRequest request) { | 58 leveldb::LevelDBServiceRequest request) { |
| 58 if (!leveldb_service_) | 59 if (!leveldb_service_) |
| 59 leveldb_service_.reset(new leveldb::LevelDBServiceImpl); | 60 leveldb_service_.reset(new leveldb::LevelDBServiceImpl(task_runner_)); |
| 60 leveldb_bindings_.AddBinding(leveldb_service_.get(), std::move(request)); | 61 leveldb_bindings_.AddBinding(leveldb_service_.get(), std::move(request)); |
| 61 } | 62 } |
| 62 | 63 |
| 63 private: | 64 private: |
| 65 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 66 |
| 64 // Variables that are only accessible on the |leveldb_service_runner_| thread. | 67 // Variables that are only accessible on the |leveldb_service_runner_| thread. |
| 65 scoped_ptr<leveldb::LevelDBService> leveldb_service_; | 68 scoped_ptr<leveldb::LevelDBService> leveldb_service_; |
| 66 mojo::BindingSet<leveldb::LevelDBService> leveldb_bindings_; | 69 mojo::BindingSet<leveldb::LevelDBService> leveldb_bindings_; |
| 67 | 70 |
| 68 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceObjects); | 71 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceObjects); |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 scoped_ptr<mojo::ShellClient> CreateProfileApp( | 74 scoped_ptr<mojo::ShellClient> CreateProfileApp( |
| 72 scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner, | 75 scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner, |
| 73 scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) { | 76 scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 profile_service_runner_->DeleteSoon(FROM_HERE, profile_objects_.release()); | 89 profile_service_runner_->DeleteSoon(FROM_HERE, profile_objects_.release()); |
| 87 leveldb_service_runner_->DeleteSoon(FROM_HERE, leveldb_objects_.release()); | 90 leveldb_service_runner_->DeleteSoon(FROM_HERE, leveldb_objects_.release()); |
| 88 } | 91 } |
| 89 | 92 |
| 90 void ProfileApp::Initialize(mojo::Connector* connector, | 93 void ProfileApp::Initialize(mojo::Connector* connector, |
| 91 const mojo::Identity& identity, | 94 const mojo::Identity& identity, |
| 92 uint32_t id) { | 95 uint32_t id) { |
| 93 tracing_.Initialize(connector, identity.name()); | 96 tracing_.Initialize(connector, identity.name()); |
| 94 profile_objects_.reset(new ProfileApp::ProfileServiceObjects( | 97 profile_objects_.reset(new ProfileApp::ProfileServiceObjects( |
| 95 GetProfileDirForUserID(identity.user_id()))); | 98 GetProfileDirForUserID(identity.user_id()))); |
| 96 leveldb_objects_.reset(new ProfileApp::LevelDBServiceObjects); | 99 leveldb_objects_.reset( |
| 100 new ProfileApp::LevelDBServiceObjects(leveldb_service_runner_)); |
| 97 } | 101 } |
| 98 | 102 |
| 99 bool ProfileApp::AcceptConnection(mojo::Connection* connection) { | 103 bool ProfileApp::AcceptConnection(mojo::Connection* connection) { |
| 100 connection->AddInterface<leveldb::LevelDBService>(this); | 104 connection->AddInterface<leveldb::LevelDBService>(this); |
| 101 connection->AddInterface<ProfileService>(this); | 105 connection->AddInterface<ProfileService>(this); |
| 102 return true; | 106 return true; |
| 103 } | 107 } |
| 104 | 108 |
| 105 void ProfileApp::Create(mojo::Connection* connection, | 109 void ProfileApp::Create(mojo::Connection* connection, |
| 106 ProfileServiceRequest request) { | 110 ProfileServiceRequest request) { |
| 107 profile_service_runner_->PostTask( | 111 profile_service_runner_->PostTask( |
| 108 FROM_HERE, | 112 FROM_HERE, |
| 109 base::Bind(&ProfileApp::ProfileServiceObjects::OnProfileServiceRequest, | 113 base::Bind(&ProfileApp::ProfileServiceObjects::OnProfileServiceRequest, |
| 110 profile_objects_->AsWeakPtr(), connection, | 114 profile_objects_->AsWeakPtr(), connection, |
| 111 base::Passed(&request))); | 115 base::Passed(&request))); |
| 112 } | 116 } |
| 113 | 117 |
| 114 void ProfileApp::Create(mojo::Connection* connection, | 118 void ProfileApp::Create(mojo::Connection* connection, |
| 115 leveldb::LevelDBServiceRequest request) { | 119 leveldb::LevelDBServiceRequest request) { |
| 116 leveldb_service_runner_->PostTask( | 120 leveldb_service_runner_->PostTask( |
| 117 FROM_HERE, | 121 FROM_HERE, |
| 118 base::Bind(&ProfileApp::LevelDBServiceObjects::OnLevelDBServiceRequest, | 122 base::Bind(&ProfileApp::LevelDBServiceObjects::OnLevelDBServiceRequest, |
| 119 leveldb_objects_->AsWeakPtr(), connection, | 123 leveldb_objects_->AsWeakPtr(), connection, |
| 120 base::Passed(&request))); | 124 base::Passed(&request))); |
| 121 } | 125 } |
| 122 | 126 |
| 123 } // namespace profile | 127 } // namespace profile |
| OLD | NEW |