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

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: Restructure based on feedback Created 4 years, 3 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..b05496da891fe8c62ae23a8cecc824933ab6d4d4
--- /dev/null
+++ b/ash/common/system/tray/system_tray_controller.cc
@@ -0,0 +1,68 @@
+// 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 "base/i18n/time_formatting.h"
msw 2016/09/30 23:26:48 nit: not needed (included in header)
James Cook 2016/10/03 18:07:55 Done.
+#include "services/shell/public/cpp/connector.h"
+
+namespace ash {
+
+SystemTrayController::SystemTrayController(shell::Connector* connector)
+ : connector_(connector), hour_clock_type_(base::GetHourClockType()) {}
+
+SystemTrayController::~SystemTrayController() {}
+
+base::HourClockType SystemTrayController::GetHourClockType() const {
msw 2016/09/30 23:26:48 optional nit: make this a simple accessor; inline
James Cook 2016/10/03 18:07:55 Done.
+ return hour_clock_type_;
+}
+
+void SystemTrayController::ShowDateSettings() {
+ ConnectToSystemTrayClient();
+ if (system_tray_client_)
James Cook 2016/09/30 21:18:26 Explicitly checking for system_tray_client_ instea
msw 2016/09/30 23:26:48 Acknowledged. Though ConnectToSystemTrayClient cou
James Cook 2016/10/03 18:07:55 Done.
+ system_tray_client_->ShowDateSettings();
+}
+
+void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) {
+ bindings_.AddBinding(this, std::move(request));
+}
+
+void SystemTrayController::ConnectToSystemTrayClient() {
+// The SystemTrayClient interface in the browser is only implemented for
+// Chrome OS, so don't try to connect on other platforms.
James Cook 2016/09/30 21:18:27 clang-format left-justifies this.
msw 2016/09/30 23:26:48 Acknowledged.
+#if defined(OS_CHROMEOS)
+ // Unit tests may not have a connector.
+ if (!connector_)
+ return;
+
+ // If already connected, nothing to do.
+ if (system_tray_client_.is_bound())
+ return;
+
+ // 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)));
+#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