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

Side by Side Diff: mash/login/login.cc

Issue 2476063002: Service Manager: Rework Service and ServiceContext lifetime (Closed)
Patch Set: . Created 4 years, 1 month 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
« no previous file with comments | « mash/init/init.cc ('k') | mash/package/mash_packaged_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mash/login/login.h" 5 #include "mash/login/login.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "mash/init/public/interfaces/init.mojom.h" 16 #include "mash/init/public/interfaces/init.mojom.h"
17 #include "mash/login/public/interfaces/login.mojom.h" 17 #include "mash/login/public/interfaces/login.mojom.h"
18 #include "mojo/public/cpp/bindings/binding_set.h" 18 #include "mojo/public/cpp/bindings/binding_set.h"
19 #include "services/service_manager/public/cpp/connector.h" 19 #include "services/service_manager/public/cpp/connector.h"
20 #include "services/service_manager/public/cpp/interface_factory.h"
21 #include "services/service_manager/public/cpp/interface_registry.h"
20 #include "services/service_manager/public/cpp/service.h" 22 #include "services/service_manager/public/cpp/service.h"
23 #include "services/service_manager/public/cpp/service_context.h"
21 #include "services/tracing/public/cpp/provider.h" 24 #include "services/tracing/public/cpp/provider.h"
22 #include "services/ui/public/cpp/property_type_converters.h" 25 #include "services/ui/public/cpp/property_type_converters.h"
23 #include "services/ui/public/interfaces/user_access_manager.mojom.h" 26 #include "services/ui/public/interfaces/user_access_manager.mojom.h"
24 #include "services/ui/public/interfaces/window_manager.mojom.h" 27 #include "services/ui/public/interfaces/window_manager.mojom.h"
25 #include "ui/views/background.h" 28 #include "ui/views/background.h"
26 #include "ui/views/controls/button/md_text_button.h" 29 #include "ui/views/controls/button/md_text_button.h"
27 #include "ui/views/mus/aura_init.h" 30 #include "ui/views/mus/aura_init.h"
28 #include "ui/views/mus/native_widget_mus.h" 31 #include "ui/views/mus/native_widget_mus.h"
29 #include "ui/views/mus/window_manager_connection.h" 32 #include "ui/views/mus/window_manager_connection.h"
30 #include "ui/views/widget/widget_delegate.h" 33 #include "ui/views/widget/widget_delegate.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 class Login : public service_manager::Service, 137 class Login : public service_manager::Service,
135 public service_manager::InterfaceFactory<mojom::Login>, 138 public service_manager::InterfaceFactory<mojom::Login>,
136 public mojom::Login { 139 public mojom::Login {
137 public: 140 public:
138 Login() {} 141 Login() {}
139 ~Login() override {} 142 ~Login() override {}
140 143
141 void LoginAs(const std::string& user_id) { 144 void LoginAs(const std::string& user_id) {
142 user_access_manager_->SetActiveUser(user_id); 145 user_access_manager_->SetActiveUser(user_id);
143 mash::init::mojom::InitPtr init; 146 mash::init::mojom::InitPtr init;
144 connector()->ConnectToInterface("service:mash_init", &init); 147 context_->connector()->ConnectToInterface("service:mash_init", &init);
145 init->StartService("service:mash_session", user_id); 148 init->StartService("service:mash_session", user_id);
146 } 149 }
147 150
148 private: 151 private:
149 // service_manager::Service: 152 // service_manager::Service:
150 void OnStart(const service_manager::ServiceInfo& info) override { 153 void OnStart(service_manager::ServiceContext* context) override {
151 identity_ = info.identity; 154 context_ = context;
152 tracing_.Initialize(connector(), identity_.name()); 155 tracing_.Initialize(context->connector(), context->identity().name());
153 156
154 aura_init_ = base::MakeUnique<views::AuraInit>(connector(), info.identity, 157 aura_init_ = base::MakeUnique<views::AuraInit>(
155 "views_mus_resources.pak"); 158 context->connector(), context->identity(), "views_mus_resources.pak");
156 159
157 connector()->ConnectToInterface("service:ui", &user_access_manager_); 160 context->connector()->ConnectToInterface(
158 user_access_manager_->SetActiveUser(identity_.user_id()); 161 "service:ui", &user_access_manager_);
162 user_access_manager_->SetActiveUser(context->identity().user_id());
159 } 163 }
164
160 bool OnConnect(const service_manager::ServiceInfo& remote_info, 165 bool OnConnect(const service_manager::ServiceInfo& remote_info,
161 service_manager::InterfaceRegistry* registry) override { 166 service_manager::InterfaceRegistry* registry) override {
162 registry->AddInterface<mojom::Login>(this); 167 registry->AddInterface<mojom::Login>(this);
163 return true; 168 return true;
164 } 169 }
165 170
166 // service_manager::InterfaceFactory<mojom::Login>: 171 // service_manager::InterfaceFactory<mojom::Login>:
167 void Create(const service_manager::Identity& remote_identity, 172 void Create(const service_manager::Identity& remote_identity,
168 mojom::LoginRequest request) override { 173 mojom::LoginRequest request) override {
169 bindings_.AddBinding(this, std::move(request)); 174 bindings_.AddBinding(this, std::move(request));
170 } 175 }
171 176
172 // mojom::Login: 177 // mojom::Login:
173 void ShowLoginUI() override { 178 void ShowLoginUI() override {
174 UI::Show(connector(), identity_, this); 179 UI::Show(context_->connector(), context_->identity(), this);
175 } 180 }
176 void SwitchUser() override { 181 void SwitchUser() override {
177 UI::Show(connector(), identity_, this); 182 UI::Show(context_->connector(), context_->identity(), this);
178 } 183 }
179 184
180 void StartWindowManager(); 185 void StartWindowManager();
181 186
182 service_manager::Identity identity_; 187 service_manager::ServiceContext* context_ = nullptr;
188
183 tracing::Provider tracing_; 189 tracing::Provider tracing_;
184 std::unique_ptr<views::AuraInit> aura_init_; 190 std::unique_ptr<views::AuraInit> aura_init_;
185 mojo::BindingSet<mojom::Login> bindings_; 191 mojo::BindingSet<mojom::Login> bindings_;
186 ui::mojom::UserAccessManagerPtr user_access_manager_; 192 ui::mojom::UserAccessManagerPtr user_access_manager_;
187 193
188 DISALLOW_COPY_AND_ASSIGN(Login); 194 DISALLOW_COPY_AND_ASSIGN(Login);
189 }; 195 };
190 196
191 void UI::ButtonPressed(views::Button* sender, const ui::Event& event) { 197 void UI::ButtonPressed(views::Button* sender, const ui::Event& event) {
192 // Login... 198 // Login...
193 if (sender == login_button_1_) { 199 if (sender == login_button_1_) {
194 login_->LoginAs(user_id_1_); 200 login_->LoginAs(user_id_1_);
195 } else if (sender == login_button_2_) { 201 } else if (sender == login_button_2_) {
196 login_->LoginAs(user_id_2_); 202 login_->LoginAs(user_id_2_);
197 } else { 203 } else {
198 NOTREACHED(); 204 NOTREACHED();
199 } 205 }
200 GetWidget()->Close(); 206 GetWidget()->Close();
201 } 207 }
202 208
203 } // namespace 209 } // namespace
204 210
205 service_manager::Service* CreateLogin() { 211 service_manager::Service* CreateLogin() {
206 return new Login; 212 return new Login;
207 } 213 }
208 214
209 } // namespace login 215 } // namespace login
210 } // namespace main 216 } // namespace main
OLDNEW
« no previous file with comments | « mash/init/init.cc ('k') | mash/package/mash_packaged_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698