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

Side by Side Diff: mash/session/session.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/session/session.h ('k') | mash/task_viewer/task_viewer.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/session/session.h" 5 #include "mash/session/session.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "mash/login/public/interfaces/login.mojom.h" 10 #include "mash/login/public/interfaces/login.mojom.h"
11 #include "services/service_manager/public/cpp/connection.h" 11 #include "services/service_manager/public/cpp/connection.h"
12 #include "services/service_manager/public/cpp/connector.h" 12 #include "services/service_manager/public/cpp/connector.h"
13 #include "services/service_manager/public/cpp/interface_registry.h"
14 #include "services/service_manager/public/cpp/service_context.h"
13 15
14 namespace { 16 namespace {
15 17
16 void LogAndCallServiceRestartCallback(const std::string& url, 18 void LogAndCallServiceRestartCallback(const std::string& url,
17 const base::Closure& callback) { 19 const base::Closure& callback) {
18 LOG(ERROR) << "Restarting service: " << url; 20 LOG(ERROR) << "Restarting service: " << url;
19 callback.Run(); 21 callback.Run();
20 } 22 }
21 23
22 } // namespace 24 } // namespace
23 25
24 namespace mash { 26 namespace mash {
25 namespace session { 27 namespace session {
26 28
27 Session::Session() : screen_locked_(false) {} 29 Session::Session() : screen_locked_(false) {}
28 Session::~Session() {} 30 Session::~Session() {}
29 31
30 void Session::OnStart(const service_manager::ServiceInfo& info) { 32 void Session::OnStart(service_manager::ServiceContext* context) {
33 context_ = context;
34
31 StartWindowManager(); 35 StartWindowManager();
32 StartQuickLaunch(); 36 StartQuickLaunch();
37
33 // Launch a chrome window for dev convience; don't do this in the long term. 38 // Launch a chrome window for dev convience; don't do this in the long term.
34 connector()->Connect("service:content_browser"); 39 context->connector()->Connect("service:content_browser");
35 } 40 }
36 41
37 bool Session::OnConnect(const service_manager::ServiceInfo& remote_info, 42 bool Session::OnConnect(const service_manager::ServiceInfo& remote_info,
38 service_manager::InterfaceRegistry* registry) { 43 service_manager::InterfaceRegistry* registry) {
39 registry->AddInterface<mojom::Session>(this); 44 registry->AddInterface<mojom::Session>(this);
40 return true; 45 return true;
41 } 46 }
42 47
43 void Session::Logout() { 48 void Session::Logout() {
44 // TODO(beng): Notify connected listeners that login is happening, potentially 49 // TODO(beng): Notify connected listeners that login is happening, potentially
45 // give them the option to stop it. 50 // give them the option to stop it.
46 mash::login::mojom::LoginPtr login; 51 mash::login::mojom::LoginPtr login;
47 connector()->ConnectToInterface("service:login", &login); 52 context_->connector()->ConnectToInterface("service:login", &login);
48 login->ShowLoginUI(); 53 login->ShowLoginUI();
49 // This kills the user environment. 54 // This kills the user environment.
50 base::MessageLoop::current()->QuitWhenIdle(); 55 base::MessageLoop::current()->QuitWhenIdle();
51 } 56 }
52 57
53 void Session::SwitchUser() { 58 void Session::SwitchUser() {
54 mash::login::mojom::LoginPtr login; 59 mash::login::mojom::LoginPtr login;
55 connector()->ConnectToInterface("service:login", &login); 60 context_->connector()->ConnectToInterface("service:login", &login);
56 login->SwitchUser(); 61 login->SwitchUser();
57 } 62 }
58 63
59 void Session::AddScreenlockStateListener( 64 void Session::AddScreenlockStateListener(
60 mojom::ScreenlockStateListenerPtr listener) { 65 mojom::ScreenlockStateListenerPtr listener) {
61 listener->ScreenlockStateChanged(screen_locked_); 66 listener->ScreenlockStateChanged(screen_locked_);
62 screenlock_listeners_.AddPtr(std::move(listener)); 67 screenlock_listeners_.AddPtr(std::move(listener));
63 } 68 }
64 69
65 void Session::LockScreen() { 70 void Session::LockScreen() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 DCHECK(connections_.end() != connection); 119 DCHECK(connections_.end() != connection);
115 connections_.erase(connection); 120 connections_.erase(connection);
116 } 121 }
117 122
118 void Session::StartRestartableService( 123 void Session::StartRestartableService(
119 const std::string& url, 124 const std::string& url,
120 const base::Closure& restart_callback) { 125 const base::Closure& restart_callback) {
121 // TODO(beng): This would be the place to insert logic that counted restarts 126 // TODO(beng): This would be the place to insert logic that counted restarts
122 // to avoid infinite crash-restart loops. 127 // to avoid infinite crash-restart loops.
123 std::unique_ptr<service_manager::Connection> connection = 128 std::unique_ptr<service_manager::Connection> connection =
124 connector()->Connect(url); 129 context_->connector()->Connect(url);
125 // Note: |connection| may be null if we've lost our connection to the service 130 // Note: |connection| may be null if we've lost our connection to the service
126 // manager. 131 // manager.
127 if (connection) { 132 if (connection) {
128 connection->SetConnectionLostClosure( 133 connection->SetConnectionLostClosure(
129 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback)); 134 base::Bind(&LogAndCallServiceRestartCallback, url, restart_callback));
130 connections_[url] = std::move(connection); 135 connections_[url] = std::move(connection);
131 } 136 }
132 } 137 }
133 138
134 } // namespace session 139 } // namespace session
135 } // namespace main 140 } // namespace main
OLDNEW
« no previous file with comments | « mash/session/session.h ('k') | mash/task_viewer/task_viewer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698