| 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/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" | |
| 9 #include "ash/common/wm_shell.h" | |
| 10 #include "ash/mus/vpn_delegate_mus.h" | 8 #include "ash/mus/vpn_delegate_mus.h" |
| 11 #include "base/bind.h" | |
| 12 #include "base/bind_helpers.h" | |
| 13 #include "base/i18n/time_formatting.h" | |
| 14 #include "base/logging.h" | |
| 15 #include "services/shell/public/cpp/connector.h" | |
| 16 | 9 |
| 17 namespace ash { | 10 namespace ash { |
| 18 namespace { | 11 namespace { |
| 19 | 12 |
| 20 SystemTrayDelegateMus* g_instance = nullptr; | |
| 21 | |
| 22 // TODO(mash): Provide a real implementation, perhaps by folding its behavior | 13 // TODO(mash): Provide a real implementation, perhaps by folding its behavior |
| 23 // into an ash-side network information cache. http://crbug.com/651157 | 14 // into an ash-side network information cache. http://crbug.com/651157 |
| 24 class StubNetworkingConfigDelegate : public NetworkingConfigDelegate { | 15 class StubNetworkingConfigDelegate : public NetworkingConfigDelegate { |
| 25 public: | 16 public: |
| 26 StubNetworkingConfigDelegate() {} | 17 StubNetworkingConfigDelegate() {} |
| 27 ~StubNetworkingConfigDelegate() override {} | 18 ~StubNetworkingConfigDelegate() override {} |
| 28 | 19 |
| 29 private: | 20 private: |
| 30 // NetworkingConfigDelegate: | 21 // NetworkingConfigDelegate: |
| 31 std::unique_ptr<const ExtensionInfo> LookUpExtensionForNetwork( | 22 std::unique_ptr<const ExtensionInfo> LookUpExtensionForNetwork( |
| 32 const std::string& service_path) override { | 23 const std::string& service_path) override { |
| 33 return nullptr; | 24 return nullptr; |
| 34 } | 25 } |
| 35 | 26 |
| 36 DISALLOW_COPY_AND_ASSIGN(StubNetworkingConfigDelegate); | 27 DISALLOW_COPY_AND_ASSIGN(StubNetworkingConfigDelegate); |
| 37 }; | 28 }; |
| 38 | 29 |
| 39 } // namespace | 30 } // namespace |
| 40 | 31 |
| 41 SystemTrayDelegateMus::SystemTrayDelegateMus(shell::Connector* connector) | 32 SystemTrayDelegateMus::SystemTrayDelegateMus() |
| 42 : connector_(connector), | 33 : networking_config_delegate_(new StubNetworkingConfigDelegate), |
| 43 hour_clock_type_(base::GetHourClockType()), | 34 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 | 35 |
| 51 SystemTrayDelegateMus::~SystemTrayDelegateMus() { | 36 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 } | 37 } |
| 147 | 38 |
| 148 NetworkingConfigDelegate* SystemTrayDelegateMus::GetNetworkingConfigDelegate() | 39 NetworkingConfigDelegate* SystemTrayDelegateMus::GetNetworkingConfigDelegate() |
| 149 const { | 40 const { |
| 150 return networking_config_delegate_.get(); | 41 return networking_config_delegate_.get(); |
| 151 } | 42 } |
| 152 | 43 |
| 153 VPNDelegate* SystemTrayDelegateMus::GetVPNDelegate() const { | 44 VPNDelegate* SystemTrayDelegateMus::GetVPNDelegate() const { |
| 154 return vpn_delegate_.get(); | 45 return vpn_delegate_.get(); |
| 155 } | 46 } |
| 156 | 47 |
| 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 | 48 } // namespace ash |
| OLD | NEW |