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

Side by Side Diff: components/profile_service/profile_app.cc

Issue 1879233002: Move components\profile_service to services\user (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move3
Patch Set: . Created 4 years, 8 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/profile_app.h"
6
7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h"
9 #include "components/filesystem/lock_table.h"
10 #include "components/leveldb/leveldb_service_impl.h"
11 #include "components/profile_service/profile_service_impl.h"
12 #include "components/profile_service/user_id_map.h"
13 #include "mojo/public/cpp/bindings/callback.h"
14 #include "services/shell/public/cpp/connection.h"
15
16 namespace profile {
17
18 class ProfileApp::ProfileServiceObjects
19 : public base::SupportsWeakPtr<ProfileServiceObjects> {
20 public:
21 // Created on the main thread.
22 ProfileServiceObjects(base::FilePath profile_data_dir)
23 : profile_data_dir_(profile_data_dir) {}
24
25 // Destroyed on the |profile_service_runner_|.
26 ~ProfileServiceObjects() {}
27
28 // Called on the |profile_service_runner_|.
29 void OnProfileServiceRequest(mojo::Connection* connection,
30 ProfileServiceRequest request) {
31 if (!lock_table_)
32 lock_table_ = new filesystem::LockTable;
33 profile_service_bindings_.AddBinding(
34 new ProfileServiceImpl(profile_data_dir_, lock_table_),
35 std::move(request));
36 }
37
38 private:
39 mojo::BindingSet<ProfileService> profile_service_bindings_;
40 scoped_refptr<filesystem::LockTable> lock_table_;
41 base::FilePath profile_data_dir_;
42
43 DISALLOW_COPY_AND_ASSIGN(ProfileServiceObjects);
44 };
45
46 class ProfileApp::LevelDBServiceObjects
47 : public base::SupportsWeakPtr<LevelDBServiceObjects> {
48 public:
49 // Created on the main thread.
50 LevelDBServiceObjects(scoped_refptr<base::SingleThreadTaskRunner> task_runner)
51 : task_runner_(std::move(task_runner)) {}
52
53 // Destroyed on the |leveldb_service_runner_|.
54 ~LevelDBServiceObjects() {}
55
56 // Called on the |leveldb_service_runner_|.
57 void OnLevelDBServiceRequest(mojo::Connection* connection,
58 leveldb::LevelDBServiceRequest request) {
59 if (!leveldb_service_)
60 leveldb_service_.reset(new leveldb::LevelDBServiceImpl(task_runner_));
61 leveldb_bindings_.AddBinding(leveldb_service_.get(), std::move(request));
62 }
63
64 private:
65 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
66
67 // Variables that are only accessible on the |leveldb_service_runner_| thread.
68 scoped_ptr<leveldb::LevelDBService> leveldb_service_;
69 mojo::BindingSet<leveldb::LevelDBService> leveldb_bindings_;
70
71 DISALLOW_COPY_AND_ASSIGN(LevelDBServiceObjects);
72 };
73
74 scoped_ptr<mojo::ShellClient> CreateProfileApp(
75 scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner,
76 scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) {
77 return make_scoped_ptr(new ProfileApp(
78 std::move(profile_service_runner),
79 std::move(leveldb_service_runner)));
80 }
81
82 ProfileApp::ProfileApp(
83 scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner,
84 scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner)
85 : profile_service_runner_(std::move(profile_service_runner)),
86 leveldb_service_runner_(std::move(leveldb_service_runner)) {}
87
88 ProfileApp::~ProfileApp() {
89 profile_service_runner_->DeleteSoon(FROM_HERE, profile_objects_.release());
90 leveldb_service_runner_->DeleteSoon(FROM_HERE, leveldb_objects_.release());
91 }
92
93 void ProfileApp::Initialize(mojo::Connector* connector,
94 const mojo::Identity& identity,
95 uint32_t id) {
96 tracing_.Initialize(connector, identity.name());
97 profile_objects_.reset(new ProfileApp::ProfileServiceObjects(
98 GetProfileDirForUserID(identity.user_id())));
99 leveldb_objects_.reset(
100 new ProfileApp::LevelDBServiceObjects(leveldb_service_runner_));
101 }
102
103 bool ProfileApp::AcceptConnection(mojo::Connection* connection) {
104 connection->AddInterface<leveldb::LevelDBService>(this);
105 connection->AddInterface<ProfileService>(this);
106 return true;
107 }
108
109 void ProfileApp::Create(mojo::Connection* connection,
110 ProfileServiceRequest request) {
111 profile_service_runner_->PostTask(
112 FROM_HERE,
113 base::Bind(&ProfileApp::ProfileServiceObjects::OnProfileServiceRequest,
114 profile_objects_->AsWeakPtr(), connection,
115 base::Passed(&request)));
116 }
117
118 void ProfileApp::Create(mojo::Connection* connection,
119 leveldb::LevelDBServiceRequest request) {
120 leveldb_service_runner_->PostTask(
121 FROM_HERE,
122 base::Bind(&ProfileApp::LevelDBServiceObjects::OnLevelDBServiceRequest,
123 leveldb_objects_->AsWeakPtr(), connection,
124 base::Passed(&request)));
125 }
126
127 } // namespace profile
OLDNEW
« no previous file with comments | « components/profile_service/profile_app.h ('k') | components/profile_service/profile_service.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698