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

Side by Side Diff: ash/common/system/tray/system_tray_controller.cc

Issue 2525813004: chromeos: Introduce SetClient() on ash::mojom::SystemTray interface (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 | « ash/common/system/tray/system_tray_controller.h ('k') | ash/common/wm_shell.cc » ('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 "ash/common/system/tray/system_tray_controller.h" 5 #include "ash/common/system/tray/system_tray_controller.h"
6 6
7 #include "ash/common/system/tray/system_tray_notifier.h" 7 #include "ash/common/system/tray/system_tray_notifier.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "content/public/common/service_names.mojom.h"
12 #include "services/service_manager/public/cpp/connector.h"
13 9
14 namespace ash { 10 namespace ash {
15 11
16 SystemTrayController::SystemTrayController( 12 SystemTrayController::SystemTrayController()
17 service_manager::Connector* connector) 13 : hour_clock_type_(base::GetHourClockType()) {}
18 : connector_(connector), hour_clock_type_(base::GetHourClockType()) {}
19 14
20 SystemTrayController::~SystemTrayController() {} 15 SystemTrayController::~SystemTrayController() {}
21 16
22 void SystemTrayController::ShowSettings() { 17 void SystemTrayController::ShowSettings() {
23 if (ConnectToSystemTrayClient()) 18 if (HasSystemTrayClient())
24 system_tray_client_->ShowSettings(); 19 system_tray_client_->ShowSettings();
25 } 20 }
26 21
27 void SystemTrayController::ShowDateSettings() { 22 void SystemTrayController::ShowDateSettings() {
28 if (ConnectToSystemTrayClient()) 23 if (HasSystemTrayClient())
29 system_tray_client_->ShowDateSettings(); 24 system_tray_client_->ShowDateSettings();
30 } 25 }
31 26
32 void SystemTrayController::ShowSetTimeDialog() { 27 void SystemTrayController::ShowSetTimeDialog() {
33 if (ConnectToSystemTrayClient()) 28 if (HasSystemTrayClient())
34 system_tray_client_->ShowSetTimeDialog(); 29 system_tray_client_->ShowSetTimeDialog();
35 } 30 }
36 31
37 void SystemTrayController::ShowDisplaySettings() { 32 void SystemTrayController::ShowDisplaySettings() {
38 if (ConnectToSystemTrayClient()) 33 if (HasSystemTrayClient())
39 system_tray_client_->ShowDisplaySettings(); 34 system_tray_client_->ShowDisplaySettings();
40 } 35 }
41 36
42 void SystemTrayController::ShowPowerSettings() { 37 void SystemTrayController::ShowPowerSettings() {
43 if (ConnectToSystemTrayClient()) 38 if (HasSystemTrayClient())
44 system_tray_client_->ShowPowerSettings(); 39 system_tray_client_->ShowPowerSettings();
45 } 40 }
46 41
47 void SystemTrayController::ShowChromeSlow() { 42 void SystemTrayController::ShowChromeSlow() {
48 if (ConnectToSystemTrayClient()) 43 if (HasSystemTrayClient())
49 system_tray_client_->ShowChromeSlow(); 44 system_tray_client_->ShowChromeSlow();
50 } 45 }
51 46
52 void SystemTrayController::ShowIMESettings() { 47 void SystemTrayController::ShowIMESettings() {
53 if (ConnectToSystemTrayClient()) 48 if (HasSystemTrayClient())
54 system_tray_client_->ShowIMESettings(); 49 system_tray_client_->ShowIMESettings();
55 } 50 }
56 51
57 void SystemTrayController::ShowHelp() { 52 void SystemTrayController::ShowHelp() {
58 if (ConnectToSystemTrayClient()) 53 if (HasSystemTrayClient())
59 system_tray_client_->ShowHelp(); 54 system_tray_client_->ShowHelp();
60 } 55 }
61 56
62 void SystemTrayController::ShowAccessibilityHelp() { 57 void SystemTrayController::ShowAccessibilityHelp() {
63 if (ConnectToSystemTrayClient()) 58 if (HasSystemTrayClient())
64 system_tray_client_->ShowAccessibilityHelp(); 59 system_tray_client_->ShowAccessibilityHelp();
65 } 60 }
66 61
67 void SystemTrayController::ShowAccessibilitySettings() { 62 void SystemTrayController::ShowAccessibilitySettings() {
68 if (ConnectToSystemTrayClient()) 63 if (HasSystemTrayClient())
69 system_tray_client_->ShowAccessibilitySettings(); 64 system_tray_client_->ShowAccessibilitySettings();
70 } 65 }
71 66
72 void SystemTrayController::ShowPaletteHelp() { 67 void SystemTrayController::ShowPaletteHelp() {
73 if (ConnectToSystemTrayClient()) 68 if (HasSystemTrayClient())
74 system_tray_client_->ShowPaletteHelp(); 69 system_tray_client_->ShowPaletteHelp();
75 } 70 }
76 71
77 void SystemTrayController::ShowPaletteSettings() { 72 void SystemTrayController::ShowPaletteSettings() {
78 if (ConnectToSystemTrayClient()) 73 if (HasSystemTrayClient())
79 system_tray_client_->ShowPaletteSettings(); 74 system_tray_client_->ShowPaletteSettings();
80 } 75 }
81 76
82 void SystemTrayController::ShowPublicAccountInfo() { 77 void SystemTrayController::ShowPublicAccountInfo() {
83 if (ConnectToSystemTrayClient()) 78 if (HasSystemTrayClient())
84 system_tray_client_->ShowPublicAccountInfo(); 79 system_tray_client_->ShowPublicAccountInfo();
85 } 80 }
86 81
87 void SystemTrayController::ShowNetworkConfigure(const std::string& network_id) { 82 void SystemTrayController::ShowNetworkConfigure(const std::string& network_id) {
88 if (ConnectToSystemTrayClient()) 83 if (HasSystemTrayClient())
89 system_tray_client_->ShowNetworkConfigure(network_id); 84 system_tray_client_->ShowNetworkConfigure(network_id);
90 } 85 }
91 86
92 void SystemTrayController::ShowNetworkCreate(const std::string& type) { 87 void SystemTrayController::ShowNetworkCreate(const std::string& type) {
93 if (ConnectToSystemTrayClient()) 88 if (HasSystemTrayClient())
94 system_tray_client_->ShowNetworkCreate(type); 89 system_tray_client_->ShowNetworkCreate(type);
95 } 90 }
96 91
97 void SystemTrayController::ShowNetworkSettings(const std::string& network_id) { 92 void SystemTrayController::ShowNetworkSettings(const std::string& network_id) {
98 if (ConnectToSystemTrayClient()) 93 if (HasSystemTrayClient())
99 system_tray_client_->ShowNetworkSettings(network_id); 94 system_tray_client_->ShowNetworkSettings(network_id);
100 } 95 }
101 96
102 void SystemTrayController::ShowProxySettings() { 97 void SystemTrayController::ShowProxySettings() {
103 if (ConnectToSystemTrayClient()) 98 if (HasSystemTrayClient())
104 system_tray_client_->ShowProxySettings(); 99 system_tray_client_->ShowProxySettings();
105 } 100 }
106 101
107 void SystemTrayController::SignOut() { 102 void SystemTrayController::SignOut() {
108 if (ConnectToSystemTrayClient()) 103 if (HasSystemTrayClient())
109 system_tray_client_->SignOut(); 104 system_tray_client_->SignOut();
110 } 105 }
111 106
112 void SystemTrayController::RequestRestartForUpdate() { 107 void SystemTrayController::RequestRestartForUpdate() {
113 if (ConnectToSystemTrayClient()) 108 if (HasSystemTrayClient())
114 system_tray_client_->RequestRestartForUpdate(); 109 system_tray_client_->RequestRestartForUpdate();
115 } 110 }
116 111
117 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) { 112 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) {
118 bindings_.AddBinding(this, std::move(request)); 113 bindings_.AddBinding(this, std::move(request));
119 } 114 }
120 115
121 bool SystemTrayController::ConnectToSystemTrayClient() { 116 bool SystemTrayController::HasSystemTrayClient() {
122 // Unit tests may not have a connector. 117 if (system_tray_client_)
123 if (!connector_)
124 return false;
125
126 #if defined(OS_CHROMEOS)
127 // If already connected, nothing to do.
128 if (system_tray_client_.is_bound())
129 return true; 118 return true;
130 119 LOG(ERROR) << "SystemTrayClient not bound";
James Cook 2016/11/22 23:46:20 I didn't want to have silent failures when running
131 // Connect (or reconnect) to the interface.
132 connector_->ConnectToInterface(content::mojom::kBrowserServiceName,
133 &system_tray_client_);
134
135 // Handle chrome crashes by forcing a reconnect on the next request.
136 system_tray_client_.set_connection_error_handler(base::Bind(
137 &SystemTrayController::OnClientConnectionError, base::Unretained(this)));
138 return true;
139 #else
140 // The SystemTrayClient interface in the browser is only implemented for
141 // Chrome OS, so don't try to connect on other platforms.
142 return false; 120 return false;
143 #endif // defined(OS_CHROMEOS)
144 } 121 }
145 122
146 void SystemTrayController::OnClientConnectionError() { 123 void SystemTrayController::SetClient(mojom::SystemTrayClientPtr client) {
147 system_tray_client_.reset(); 124 system_tray_client_ = std::move(client);
148 } 125 }
149 126
150 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { 127 void SystemTrayController::SetUse24HourClock(bool use_24_hour) {
151 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; 128 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock;
152 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); 129 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged();
153 } 130 }
154 131
155 } // namespace ash 132 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/system_tray_controller.h ('k') | ash/common/wm_shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698