| Index: ash/common/system/tray/system_tray_controller.cc
|
| diff --git a/ash/common/system/tray/system_tray_controller.cc b/ash/common/system/tray/system_tray_controller.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..54c0216714face4f773f7518364f9b8a759e085a
|
| --- /dev/null
|
| +++ b/ash/common/system/tray/system_tray_controller.cc
|
| @@ -0,0 +1,65 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ash/common/system/tray/system_tray_controller.h"
|
| +
|
| +#include "ash/common/system/tray/system_tray_notifier.h"
|
| +#include "ash/common/wm_shell.h"
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| +#include "services/shell/public/cpp/connector.h"
|
| +
|
| +namespace ash {
|
| +
|
| +SystemTrayController::SystemTrayController(shell::Connector* connector)
|
| + : connector_(connector), hour_clock_type_(base::GetHourClockType()) {}
|
| +
|
| +SystemTrayController::~SystemTrayController() {}
|
| +
|
| +void SystemTrayController::ShowDateSettings() {
|
| + if (ConnectToSystemTrayClient())
|
| + system_tray_client_->ShowDateSettings();
|
| +}
|
| +
|
| +void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) {
|
| + bindings_.AddBinding(this, std::move(request));
|
| +}
|
| +
|
| +bool SystemTrayController::ConnectToSystemTrayClient() {
|
| + // Unit tests may not have a connector.
|
| + if (!connector_)
|
| + return false;
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| + // If already connected, nothing to do.
|
| + if (system_tray_client_.is_bound())
|
| + return true;
|
| +
|
| + // Connect (or reconnect) to the interface.
|
| + if (WmShell::Get()->IsRunningInMash())
|
| + connector_->ConnectToInterface("exe:chrome", &system_tray_client_);
|
| + else
|
| + connector_->ConnectToInterface("exe:content_browser", &system_tray_client_);
|
| +
|
| + // Handle chrome crashes by forcing a reconnect on the next request.
|
| + system_tray_client_.set_connection_error_handler(base::Bind(
|
| + &SystemTrayController::OnClientConnectionError, base::Unretained(this)));
|
| + return true;
|
| +#else
|
| + // The SystemTrayClient interface in the browser is only implemented for
|
| + // Chrome OS, so don't try to connect on other platforms.
|
| + return false;
|
| +#endif // defined(OS_CHROMEOS)
|
| +}
|
| +
|
| +void SystemTrayController::OnClientConnectionError() {
|
| + system_tray_client_.reset();
|
| +}
|
| +
|
| +void SystemTrayController::SetUse24HourClock(bool use_24_hour) {
|
| + hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock;
|
| + WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged();
|
| +}
|
| +
|
| +} // namespace ash
|
|
|