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/tray/system_tray_notifier.h" | |
8 #include "ash/common/wm_shell.h" | |
9 #include "base/bind.h" | |
10 #include "base/bind_helpers.h" | |
11 #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.
| |
12 #include "services/shell/public/cpp/connector.h" | |
13 | |
14 namespace ash { | |
15 | |
16 SystemTrayController::SystemTrayController(shell::Connector* connector) | |
17 : connector_(connector), hour_clock_type_(base::GetHourClockType()) {} | |
18 | |
19 SystemTrayController::~SystemTrayController() {} | |
20 | |
21 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.
| |
22 return hour_clock_type_; | |
23 } | |
24 | |
25 void SystemTrayController::ShowDateSettings() { | |
26 ConnectToSystemTrayClient(); | |
27 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.
| |
28 system_tray_client_->ShowDateSettings(); | |
29 } | |
30 | |
31 void SystemTrayController::BindRequest(mojom::SystemTrayRequest request) { | |
32 bindings_.AddBinding(this, std::move(request)); | |
33 } | |
34 | |
35 void SystemTrayController::ConnectToSystemTrayClient() { | |
36 // The SystemTrayClient interface in the browser is only implemented for | |
37 // 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.
| |
38 #if defined(OS_CHROMEOS) | |
39 // Unit tests may not have a connector. | |
40 if (!connector_) | |
41 return; | |
42 | |
43 // If already connected, nothing to do. | |
44 if (system_tray_client_.is_bound()) | |
45 return; | |
46 | |
47 // Connect (or reconnect) to the interface. | |
48 if (WmShell::Get()->IsRunningInMash()) | |
49 connector_->ConnectToInterface("exe:chrome", &system_tray_client_); | |
50 else | |
51 connector_->ConnectToInterface("exe:content_browser", &system_tray_client_); | |
52 | |
53 // Handle chrome crashes by forcing a reconnect on the next request. | |
54 system_tray_client_.set_connection_error_handler(base::Bind( | |
55 &SystemTrayController::OnClientConnectionError, base::Unretained(this))); | |
56 #endif // defined(OS_CHROMEOS) | |
57 } | |
58 | |
59 void SystemTrayController::OnClientConnectionError() { | |
60 system_tray_client_.reset(); | |
61 } | |
62 | |
63 void SystemTrayController::SetUse24HourClock(bool use_24_hour) { | |
64 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; | |
65 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); | |
66 } | |
67 | |
68 } // namespace ash | |
OLD | NEW |