Chromium Code Reviews| 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/date/clock_observer.h" | |
| 8 #include "base/bind.h" | |
| 9 #include "base/bind_helpers.h" | |
| 10 #include "base/i18n/time_formatting.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 // 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
| |
| 18 } | |
| 19 | |
| 20 SystemTrayController::~SystemTrayController() {} | |
| 21 | |
| 22 base::HourClockType SystemTrayController::GetHourClockType() const { | |
| 23 return hour_clock_type_; | |
| 24 } | |
| 25 | |
| 26 void SystemTrayController::ShowDateSettings() { | |
| 27 // REVIEWERS: We could also expose ConnectToSystemTrayClient() publicly | |
| 28 // and let code in ash directly invoke methods on the mojo interface. | |
| 29 // I'm not sure if it's better to keep things centralized, but my instinct | |
| 30 // is that we should. | |
| 31 ConnectToSystemTrayClient()->ShowDateSettings(); | |
| 32 } | |
| 33 | |
| 34 void SystemTrayController::AddClockObserver(ClockObserver* observer) { | |
| 35 clock_observers_.AddObserver(observer); | |
| 36 } | |
| 37 | |
| 38 void SystemTrayController::RemoveClockObserver(ClockObserver* observer) { | |
| 39 clock_observers_.RemoveObserver(observer); | |
| 40 } | |
| 41 | |
| 42 mojom::SystemTrayClient* SystemTrayController::ConnectToSystemTrayClient() { | |
| 43 DCHECK(connector_); | |
| 44 | |
| 45 if (!system_tray_client_.is_bound()) { | |
| 46 // Connect (or reconnect) to the interface. | |
| 47 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
| |
| 48 | |
| 49 // Tolerate chrome crashing and coming back up. | |
| 50 system_tray_client_.set_connection_error_handler( | |
| 51 base::Bind(&SystemTrayController::OnClientConnectionError, | |
| 52 base::Unretained(this))); | |
| 53 } | |
| 54 return system_tray_client_.get(); | |
| 55 } | |
| 56 | |
| 57 void SystemTrayController::OnClientConnectionError() { | |
| 58 system_tray_client_.reset(); | |
| 59 } | |
| 60 | |
| 61 // mojom::SystemTray: | |
| 62 | |
| 63 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { | |
| 64 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; | |
| 65 FOR_EACH_OBSERVER(ClockObserver, clock_observers_, OnDateFormatChanged()); | |
|
sky
2016/09/29 16:34:05
If you're expecting the client to always call this
| |
| 66 } | |
| 67 | |
| 68 } // namespace ash | |
| OLD | NEW |