| OLD | NEW |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 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 (system_tray_client_) |
| 94 system_tray_client_->ShowNetworkCreate(type); | 89 system_tray_client_->ShowNetworkCreate(type); |
| 95 } | 90 } |
| 96 | 91 |
| 97 void SystemTrayController::ShowThirdPartyVpnCreate( | 92 void SystemTrayController::ShowThirdPartyVpnCreate( |
| 98 const std::string& extension_id) { | 93 const std::string& extension_id) { |
| 99 if (ConnectToSystemTrayClient()) | 94 if (system_tray_client_) |
| 100 system_tray_client_->ShowThirdPartyVpnCreate(extension_id); | 95 system_tray_client_->ShowThirdPartyVpnCreate(extension_id); |
| 101 } | 96 } |
| 102 | 97 |
| 103 void SystemTrayController::ShowNetworkSettings(const std::string& network_id) { | 98 void SystemTrayController::ShowNetworkSettings(const std::string& network_id) { |
| 104 if (ConnectToSystemTrayClient()) | 99 if (system_tray_client_) |
| 105 system_tray_client_->ShowNetworkSettings(network_id); | 100 system_tray_client_->ShowNetworkSettings(network_id); |
| 106 } | 101 } |
| 107 | 102 |
| 108 void SystemTrayController::ShowProxySettings() { | 103 void SystemTrayController::ShowProxySettings() { |
| 109 if (ConnectToSystemTrayClient()) | 104 if (system_tray_client_) |
| 110 system_tray_client_->ShowProxySettings(); | 105 system_tray_client_->ShowProxySettings(); |
| 111 } | 106 } |
| 112 | 107 |
| 113 void SystemTrayController::SignOut() { | 108 void SystemTrayController::SignOut() { |
| 114 if (ConnectToSystemTrayClient()) | 109 if (system_tray_client_) |
| 115 system_tray_client_->SignOut(); | 110 system_tray_client_->SignOut(); |
| 116 } | 111 } |
| 117 | 112 |
| 118 void SystemTrayController::RequestRestartForUpdate() { | 113 void SystemTrayController::RequestRestartForUpdate() { |
| 119 if (ConnectToSystemTrayClient()) | 114 if (system_tray_client_) |
| 120 system_tray_client_->RequestRestartForUpdate(); | 115 system_tray_client_->RequestRestartForUpdate(); |
| 121 } | 116 } |
| 122 | 117 |
| 123 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) { | 118 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) { |
| 124 bindings_.AddBinding(this, std::move(request)); | 119 bindings_.AddBinding(this, std::move(request)); |
| 125 } | 120 } |
| 126 | 121 |
| 127 bool SystemTrayController::ConnectToSystemTrayClient() { | 122 void SystemTrayController::SetClient(mojom::SystemTrayClientPtr client) { |
| 128 // Unit tests may not have a connector. | 123 system_tray_client_ = std::move(client); |
| 129 if (!connector_) | |
| 130 return false; | |
| 131 | |
| 132 #if defined(OS_CHROMEOS) | |
| 133 // If already connected, nothing to do. | |
| 134 if (system_tray_client_.is_bound()) | |
| 135 return true; | |
| 136 | |
| 137 // Connect (or reconnect) to the interface. | |
| 138 connector_->ConnectToInterface(content::mojom::kBrowserServiceName, | |
| 139 &system_tray_client_); | |
| 140 | |
| 141 // Handle chrome crashes by forcing a reconnect on the next request. | |
| 142 system_tray_client_.set_connection_error_handler(base::Bind( | |
| 143 &SystemTrayController::OnClientConnectionError, base::Unretained(this))); | |
| 144 return true; | |
| 145 #else | |
| 146 // The SystemTrayClient interface in the browser is only implemented for | |
| 147 // Chrome OS, so don't try to connect on other platforms. | |
| 148 return false; | |
| 149 #endif // defined(OS_CHROMEOS) | |
| 150 } | |
| 151 | |
| 152 void SystemTrayController::OnClientConnectionError() { | |
| 153 system_tray_client_.reset(); | |
| 154 } | 124 } |
| 155 | 125 |
| 156 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { | 126 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { |
| 157 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; | 127 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; |
| 158 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); | 128 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); |
| 159 } | 129 } |
| 160 | 130 |
| 161 } // namespace ash | 131 } // namespace ash |
| OLD | NEW |