| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/system_tray_controller_mus.h" | 5 #include "chrome/browser/ui/ash/system_tray_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 7 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/browser_process_platform_part.h" | 10 #include "chrome/browser/browser_process_platform_part.h" |
| 9 #include "chrome/browser/chromeos/system/system_clock.h" | 11 #include "chrome/browser/chromeos/system/system_clock.h" |
| 12 #include "chrome/browser/ui/ash/system_tray_common.h" |
| 10 #include "content/public/common/mojo_shell_connection.h" | 13 #include "content/public/common/mojo_shell_connection.h" |
| 11 #include "services/shell/public/cpp/connector.h" | 14 #include "services/shell/public/cpp/connector.h" |
| 12 | 15 |
| 13 SystemTrayControllerMus::SystemTrayControllerMus() { | 16 namespace { |
| 14 shell::Connector* connector = | |
| 15 content::MojoShellConnection::GetForProcess()->GetConnector(); | |
| 16 connector->ConnectToInterface("mojo:ash", &system_tray_); | |
| 17 | 17 |
| 18 SystemTrayClient* g_instance = nullptr; |
| 19 |
| 20 } // namespace |
| 21 |
| 22 SystemTrayClient::SystemTrayClient() { |
| 23 // If this observes clock setting changes before ash comes up the IPCs will |
| 24 // be queued on |system_tray_|. |
| 18 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); | 25 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); |
| 26 |
| 27 DCHECK(!g_instance); |
| 28 g_instance = this; |
| 19 } | 29 } |
| 20 | 30 |
| 21 SystemTrayControllerMus::~SystemTrayControllerMus() { | 31 SystemTrayClient::~SystemTrayClient() { |
| 32 DCHECK_EQ(this, g_instance); |
| 33 g_instance = nullptr; |
| 34 |
| 22 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); | 35 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); |
| 23 } | 36 } |
| 24 | 37 |
| 25 void SystemTrayControllerMus::OnSystemClockChanged( | 38 // static |
| 39 SystemTrayClient* SystemTrayClient::Get() { |
| 40 return g_instance; |
| 41 } |
| 42 |
| 43 void SystemTrayClient::ConnectToSystemTray() { |
| 44 if (system_tray_.is_bound()) |
| 45 return; |
| 46 |
| 47 content::MojoShellConnection::GetForProcess() |
| 48 ->GetConnector() |
| 49 ->ConnectToInterface("mojo:ash", &system_tray_); |
| 50 |
| 51 // Tolerate ash crashing and coming back up. |
| 52 system_tray_.set_connection_error_handler(base::Bind( |
| 53 &SystemTrayClient::OnClientConnectionError, base::Unretained(this))); |
| 54 } |
| 55 |
| 56 void SystemTrayClient::OnClientConnectionError() { |
| 57 system_tray_.reset(); |
| 58 } |
| 59 |
| 60 void SystemTrayClient::ShowDateSettings() { |
| 61 SystemTrayCommon::ShowDateSettings(); |
| 62 } |
| 63 |
| 64 void SystemTrayClient::OnSystemClockChanged( |
| 26 chromeos::system::SystemClock* clock) { | 65 chromeos::system::SystemClock* clock) { |
| 66 ConnectToSystemTray(); |
| 27 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); | 67 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); |
| 28 } | 68 } |
| OLD | NEW |