Chromium Code Reviews| Index: ash/mus/system_tray_delegate_mus.cc |
| diff --git a/ash/mus/system_tray_delegate_mus.cc b/ash/mus/system_tray_delegate_mus.cc |
| index 8add535aa2bf63f0e61f51d57121d91a21396604..ad729a4dbbdbea3d8476cc8ff8b601f644bbc3b2 100644 |
| --- a/ash/mus/system_tray_delegate_mus.cc |
| +++ b/ash/mus/system_tray_delegate_mus.cc |
| @@ -8,6 +8,7 @@ |
| #include "ash/common/wm_shell.h" |
| #include "base/i18n/time_formatting.h" |
| #include "base/logging.h" |
| +#include "services/shell/public/cpp/connector.h" |
| namespace ash { |
| namespace { |
| @@ -16,8 +17,13 @@ SystemTrayDelegateMus* g_instance = nullptr; |
| } // namespace |
| -SystemTrayDelegateMus::SystemTrayDelegateMus() |
| - : hour_clock_type_(base::GetHourClockType()) { |
| +SystemTrayDelegateMus::SystemTrayDelegateMus(shell::Connector* connector) |
| + : connector_(connector), |
| + hour_clock_type_(base::GetHourClockType()), |
| + weak_factory_(this) { |
| + DCHECK(connector_); |
| + // Don't make an initial connection to exe:chrome. Do it on demand. |
| + |
| DCHECK(!g_instance); |
| g_instance = this; |
| } |
| @@ -32,10 +38,33 @@ SystemTrayDelegateMus* SystemTrayDelegateMus::Get() { |
| return g_instance; |
| } |
| +void SystemTrayDelegateMus::ConnectToSystemTrayClient() { |
| + // Check if already connected. |
|
sky
2016/09/26 15:23:14
optional: IMO this comment and 43 document exactly
James Cook
2016/09/26 18:01:37
Removed this one and the one on line 46.
|
| + if (system_tray_client_.is_bound()) |
| + return; |
| + |
| + // Connect to chrome browser. |
| + connector_->ConnectToInterface("exe:chrome", &system_tray_client_); |
|
sky
2016/09/26 15:23:14
What you have here certainly works. Consider thoug
James Cook
2016/09/26 18:01:37
As discussed offline, keeping this so commands on
|
| + |
| + // Tolerate chrome crashing and coming back up. |
| + system_tray_client_.set_connection_error_handler( |
| + base::Bind(&SystemTrayDelegateMus::OnClientConnectionError, |
| + weak_factory_.GetWeakPtr())); |
|
sky
2016/09/26 15:23:14
As this owns system_tray_client_ you shouldn't nee
James Cook
2016/09/26 18:01:37
Done.
|
| +} |
| + |
| +void SystemTrayDelegateMus::OnClientConnectionError() { |
| + system_tray_client_.reset(); |
| +} |
| + |
| base::HourClockType SystemTrayDelegateMus::GetHourClockType() const { |
| return hour_clock_type_; |
| } |
| +void SystemTrayDelegateMus::ShowDateSettings() { |
| + ConnectToSystemTrayClient(); |
| + system_tray_client_->ShowDateSettings(); |
| +} |
| + |
| void SystemTrayDelegateMus::SetUse24HourClock(bool use_24_hour) { |
| hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; |
| WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); |