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

Unified Diff: ash/common/system/tray/system_tray_controller.cc

Issue 2381753002: Use mojo SystemTray interfaces for both mash and classic ash (Closed)
Patch Set: review comments 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698