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..fe4879f5eb72c1cfdc715e456f810d97234701e8 |
--- /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/date/clock_observer.h" |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/i18n/time_formatting.h" |
+#include "services/shell/public/cpp/connector.h" |
+ |
+namespace ash { |
+ |
+SystemTrayController::SystemTrayController(shell::Connector* connector) |
+ : connector_(connector), hour_clock_type_(base::GetHourClockType()) { |
+ // TODO: In general, how do we get initial values? |
sky
2016/09/29 16:34:05
This is a similar problem with the keyboard, where
|
+} |
+ |
+SystemTrayController::~SystemTrayController() {} |
+ |
+base::HourClockType SystemTrayController::GetHourClockType() const { |
+ return hour_clock_type_; |
+} |
+ |
+void SystemTrayController::ShowDateSettings() { |
+ // REVIEWERS: We could also expose ConnectToSystemTrayClient() publicly |
+ // and let code in ash directly invoke methods on the mojo interface. |
+ // I'm not sure if it's better to keep things centralized, but my instinct |
+ // is that we should. |
+ ConnectToSystemTrayClient()->ShowDateSettings(); |
+} |
+ |
+void SystemTrayController::AddClockObserver(ClockObserver* observer) { |
+ clock_observers_.AddObserver(observer); |
+} |
+ |
+void SystemTrayController::RemoveClockObserver(ClockObserver* observer) { |
+ clock_observers_.RemoveObserver(observer); |
+} |
+ |
+mojom::SystemTrayClient* SystemTrayController::ConnectToSystemTrayClient() { |
+ DCHECK(connector_); |
+ |
+ if (!system_tray_client_.is_bound()) { |
+ // Connect (or reconnect) to the interface. |
+ connector_->ConnectToInterface("exe:chrome", &system_tray_client_); |
sky
2016/09/29 16:34:05
The name of this may need to be exe:content_browse
James Cook
2016/09/29 16:43:33
Note for msw: We also need to think about reconnec
|
+ |
+ // Tolerate chrome crashing and coming back up. |
+ system_tray_client_.set_connection_error_handler( |
+ base::Bind(&SystemTrayController::OnClientConnectionError, |
+ base::Unretained(this))); |
+ } |
+ return system_tray_client_.get(); |
+} |
+ |
+void SystemTrayController::OnClientConnectionError() { |
+ system_tray_client_.reset(); |
+} |
+ |
+// mojom::SystemTray: |
+ |
+void SystemTrayController::SetUse24HourClock(bool use_24_hour) { |
+ hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; |
+ FOR_EACH_OBSERVER(ClockObserver, clock_observers_, OnDateFormatChanged()); |
sky
2016/09/29 16:34:05
If you're expecting the client to always call this
|
+} |
+ |
+} // namespace ash |