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

Side by Side Diff: ash/mus/system_tray_delegate_mus.cc

Issue 2381753002: Use mojo SystemTray interfaces for both mash and classic ash (Closed)
Patch Set: Restructure based on feedback Created 4 years, 2 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
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/mus/system_tray_delegate_mus.h" 5 #include "ash/mus/system_tray_delegate_mus.h"
6 6
7 #include "ash/common/system/networking_config_delegate.h" 7 #include "ash/common/system/networking_config_delegate.h"
8 #include "ash/common/system/tray/system_tray_notifier.h" 8 #include "ash/common/system/tray/system_tray_notifier.h"
msw 2016/09/30 23:26:49 nit: remove
James Cook 2016/10/03 18:07:56 Done, here and below. Geez, I missed a lot of clea
9 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
msw 2016/09/30 23:26:49 nit: remove
10 #include "ash/mus/vpn_delegate_mus.h" 10 #include "ash/mus/vpn_delegate_mus.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
msw 2016/09/30 23:26:49 nit: remove
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
msw 2016/09/30 23:26:49 nit: remove
13 #include "base/i18n/time_formatting.h" 13 #include "base/i18n/time_formatting.h"
msw 2016/09/30 23:26:49 nit: remove
14 #include "base/logging.h" 14 #include "base/logging.h"
msw 2016/09/30 23:26:49 nit: remove
15 #include "services/shell/public/cpp/connector.h" 15 #include "services/shell/public/cpp/connector.h"
msw 2016/09/30 23:26:49 nit: remove
16 16
17 namespace ash { 17 namespace ash {
18 namespace { 18 namespace {
19 19
20 SystemTrayDelegateMus* g_instance = nullptr;
21
22 // TODO(mash): Provide a real implementation, perhaps by folding its behavior 20 // TODO(mash): Provide a real implementation, perhaps by folding its behavior
23 // into an ash-side network information cache. http://crbug.com/651157 21 // into an ash-side network information cache. http://crbug.com/651157
24 class StubNetworkingConfigDelegate : public NetworkingConfigDelegate { 22 class StubNetworkingConfigDelegate : public NetworkingConfigDelegate {
25 public: 23 public:
26 StubNetworkingConfigDelegate() {} 24 StubNetworkingConfigDelegate() {}
27 ~StubNetworkingConfigDelegate() override {} 25 ~StubNetworkingConfigDelegate() override {}
28 26
29 private: 27 private:
30 // NetworkingConfigDelegate: 28 // NetworkingConfigDelegate:
31 std::unique_ptr<const ExtensionInfo> LookUpExtensionForNetwork( 29 std::unique_ptr<const ExtensionInfo> LookUpExtensionForNetwork(
32 const std::string& service_path) override { 30 const std::string& service_path) override {
33 return nullptr; 31 return nullptr;
34 } 32 }
35 33
36 DISALLOW_COPY_AND_ASSIGN(StubNetworkingConfigDelegate); 34 DISALLOW_COPY_AND_ASSIGN(StubNetworkingConfigDelegate);
37 }; 35 };
38 36
39 } // namespace 37 } // namespace
40 38
41 SystemTrayDelegateMus::SystemTrayDelegateMus(shell::Connector* connector) 39 SystemTrayDelegateMus::SystemTrayDelegateMus()
42 : connector_(connector), 40 : networking_config_delegate_(new StubNetworkingConfigDelegate),
43 hour_clock_type_(base::GetHourClockType()), 41 vpn_delegate_(new VPNDelegateMus) {}
44 networking_config_delegate_(new StubNetworkingConfigDelegate),
45 vpn_delegate_(new VPNDelegateMus) {
46 // Don't make an initial connection to exe:chrome. Do it on demand.
47 DCHECK(!g_instance);
48 g_instance = this;
49 }
50 42
51 SystemTrayDelegateMus::~SystemTrayDelegateMus() { 43 SystemTrayDelegateMus::~SystemTrayDelegateMus() {
52 DCHECK_EQ(this, g_instance);
53 g_instance = nullptr;
54 }
55
56 // static
57 SystemTrayDelegateMus* SystemTrayDelegateMus::Get() {
58 return g_instance;
59 }
60
61 mojom::SystemTrayClient* SystemTrayDelegateMus::ConnectToSystemTrayClient() {
62 if (!system_tray_client_.is_bound()) {
63 // Connect (or reconnect) to the interface.
64 connector_->ConnectToInterface("exe:chrome", &system_tray_client_);
65
66 // Tolerate chrome crashing and coming back up.
67 system_tray_client_.set_connection_error_handler(
68 base::Bind(&SystemTrayDelegateMus::OnClientConnectionError,
69 base::Unretained(this)));
70 }
71 return system_tray_client_.get();
72 }
73
74 void SystemTrayDelegateMus::OnClientConnectionError() {
75 system_tray_client_.reset();
76 }
77
78 ////////////////////////////////////////////////////////////////////////////////
79 // SystemTrayDelegate:
80
81 base::HourClockType SystemTrayDelegateMus::GetHourClockType() const {
82 return hour_clock_type_;
83 }
84
85 void SystemTrayDelegateMus::ShowSettings() {
86 ConnectToSystemTrayClient()->ShowSettings();
87 }
88
89 void SystemTrayDelegateMus::ShowDateSettings() {
90 ConnectToSystemTrayClient()->ShowDateSettings();
91 }
92
93 void SystemTrayDelegateMus::ShowNetworkSettingsForGuid(
94 const std::string& guid) {
95 // http://crbug.com/647412
96 NOTIMPLEMENTED();
97 }
98
99 void SystemTrayDelegateMus::ShowDisplaySettings() {
100 ConnectToSystemTrayClient()->ShowDisplaySettings();
101 }
102
103 void SystemTrayDelegateMus::ShowPowerSettings() {
104 ConnectToSystemTrayClient()->ShowPowerSettings();
105 }
106
107 void SystemTrayDelegateMus::ShowChromeSlow() {
108 ConnectToSystemTrayClient()->ShowChromeSlow();
109 }
110
111 void SystemTrayDelegateMus::ShowIMESettings() {
112 ConnectToSystemTrayClient()->ShowIMESettings();
113 }
114
115 void SystemTrayDelegateMus::ShowHelp() {
116 ConnectToSystemTrayClient()->ShowHelp();
117 }
118
119 void SystemTrayDelegateMus::ShowAccessibilityHelp() {
120 ConnectToSystemTrayClient()->ShowAccessibilityHelp();
121 }
122
123 void SystemTrayDelegateMus::ShowAccessibilitySettings() {
124 ConnectToSystemTrayClient()->ShowAccessibilitySettings();
125 }
126
127 void SystemTrayDelegateMus::ShowPaletteHelp() {
128 ConnectToSystemTrayClient()->ShowPaletteHelp();
129 }
130
131 void SystemTrayDelegateMus::ShowPaletteSettings() {
132 ConnectToSystemTrayClient()->ShowPaletteSettings();
133 }
134
135 void SystemTrayDelegateMus::ShowPublicAccountInfo() {
136 ConnectToSystemTrayClient()->ShowPublicAccountInfo();
137 }
138
139 void SystemTrayDelegateMus::ShowEnterpriseInfo() {
140 // http://crbug.com/647412
141 NOTIMPLEMENTED();
142 }
143
144 void SystemTrayDelegateMus::ShowProxySettings() {
145 ConnectToSystemTrayClient()->ShowProxySettings();
146 } 44 }
147 45
148 NetworkingConfigDelegate* SystemTrayDelegateMus::GetNetworkingConfigDelegate() 46 NetworkingConfigDelegate* SystemTrayDelegateMus::GetNetworkingConfigDelegate()
149 const { 47 const {
150 return networking_config_delegate_.get(); 48 return networking_config_delegate_.get();
151 } 49 }
152 50
153 VPNDelegate* SystemTrayDelegateMus::GetVPNDelegate() const { 51 VPNDelegate* SystemTrayDelegateMus::GetVPNDelegate() const {
154 return vpn_delegate_.get(); 52 return vpn_delegate_.get();
155 } 53 }
156 54
157 ////////////////////////////////////////////////////////////////////////////////
158 // mojom::SystemTray:
159
160 void SystemTrayDelegateMus::SetUse24HourClock(bool use_24_hour) {
161 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock;
162 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged();
163 }
164
165 } // namespace ash 55 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698