OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/common/system/tray/system_tray_controller.h" |
| 6 |
| 7 #include "ash/common/system/tray/system_tray_notifier.h" |
| 8 #include "ash/common/wm_shell.h" |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 11 #include "services/shell/public/cpp/connector.h" |
| 12 |
| 13 namespace ash { |
| 14 |
| 15 SystemTrayController::SystemTrayController(shell::Connector* connector) |
| 16 : connector_(connector), hour_clock_type_(base::GetHourClockType()) {} |
| 17 |
| 18 SystemTrayController::~SystemTrayController() {} |
| 19 |
| 20 void SystemTrayController::ShowDateSettings() { |
| 21 if (ConnectToSystemTrayClient()) |
| 22 system_tray_client_->ShowDateSettings(); |
| 23 } |
| 24 |
| 25 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) { |
| 26 bindings_.AddBinding(this, std::move(request)); |
| 27 } |
| 28 |
| 29 bool SystemTrayController::ConnectToSystemTrayClient() { |
| 30 // Unit tests may not have a connector. |
| 31 if (!connector_) |
| 32 return false; |
| 33 |
| 34 #if defined(OS_CHROMEOS) |
| 35 // If already connected, nothing to do. |
| 36 if (system_tray_client_.is_bound()) |
| 37 return true; |
| 38 |
| 39 // Connect (or reconnect) to the interface. |
| 40 if (WmShell::Get()->IsRunningInMash()) |
| 41 connector_->ConnectToInterface("exe:chrome", &system_tray_client_); |
| 42 else |
| 43 connector_->ConnectToInterface("exe:content_browser", &system_tray_client_); |
| 44 |
| 45 // Handle chrome crashes by forcing a reconnect on the next request. |
| 46 system_tray_client_.set_connection_error_handler(base::Bind( |
| 47 &SystemTrayController::OnClientConnectionError, base::Unretained(this))); |
| 48 return true; |
| 49 #else |
| 50 // The SystemTrayClient interface in the browser is only implemented for |
| 51 // Chrome OS, so don't try to connect on other platforms. |
| 52 return false; |
| 53 #endif // defined(OS_CHROMEOS) |
| 54 } |
| 55 |
| 56 void SystemTrayController::OnClientConnectionError() { |
| 57 system_tray_client_.reset(); |
| 58 } |
| 59 |
| 60 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { |
| 61 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; |
| 62 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); |
| 63 } |
| 64 |
| 65 } // namespace ash |
OLD | NEW |