| 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 "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/browser_process_platform_part.h" | 8 #include "chrome/browser/browser_process_platform_part.h" |
| 9 #include "chrome/browser/chromeos/system/system_clock.h" | 9 #include "chrome/browser/chromeos/system/system_clock.h" |
| 10 #include "chrome/browser/ui/ash/system_tray_common.h" |
| 10 #include "content/public/common/mojo_shell_connection.h" | 11 #include "content/public/common/mojo_shell_connection.h" |
| 11 #include "services/shell/public/cpp/connector.h" | 12 #include "services/shell/public/cpp/connector.h" |
| 12 | 13 |
| 13 SystemTrayControllerMus::SystemTrayControllerMus() { | 14 namespace { |
| 14 shell::Connector* connector = | |
| 15 content::MojoShellConnection::GetForProcess()->GetConnector(); | |
| 16 connector->ConnectToInterface("mojo:ash", &system_tray_); | |
| 17 | 15 |
| 16 SystemTrayClient* g_instance = nullptr; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 SystemTrayClient::SystemTrayClient() : binding_(this) { |
| 21 // Connect to the mojo SystemTray service in ash. |
| 22 ConnectToSystemTray(); |
| 23 |
| 24 // If this observes clock setting changes before ash comes up the IPCs will |
| 25 // be queued on |system_tray_|. |
| 18 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); | 26 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); |
| 27 |
| 28 DCHECK(!g_instance); |
| 29 g_instance = this; |
| 19 } | 30 } |
| 20 | 31 |
| 21 SystemTrayControllerMus::~SystemTrayControllerMus() { | 32 SystemTrayClient::~SystemTrayClient() { |
| 33 DCHECK_EQ(this, g_instance); |
| 34 g_instance = nullptr; |
| 35 |
| 22 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); | 36 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); |
| 23 } | 37 } |
| 24 | 38 |
| 25 void SystemTrayControllerMus::OnSystemClockChanged( | 39 // static |
| 40 SystemTrayClient* SystemTrayClient::Get() { |
| 41 return g_instance; |
| 42 } |
| 43 |
| 44 void SystemTrayClient::ConnectToSystemTray() { |
| 45 // Check if already connected. |
| 46 if (system_tray_.is_bound()) |
| 47 return; |
| 48 |
| 49 // Connect to ash. |
| 50 content::MojoShellConnection::GetForProcess() |
| 51 ->GetConnector() |
| 52 ->ConnectToInterface("mojo:ash", &system_tray_); |
| 53 |
| 54 // Tolerate ash crashing and coming back up. This object is destroyed after |
| 55 // main message loop shutdown so Bind() doesn't need a weak pointer. |
| 56 system_tray_.set_connection_error_handler(base::Bind( |
| 57 &SystemTrayClient::OnClientConnectionError, base::Unretained(this))); |
| 58 } |
| 59 |
| 60 void SystemTrayClient::OnClientConnectionError() { |
| 61 system_tray_.reset(); |
| 62 } |
| 63 |
| 64 void SystemTrayClient::ShowDateSettings() { |
| 65 SystemTrayCommon::ShowDateSettings(); |
| 66 } |
| 67 |
| 68 void SystemTrayClient::OnSystemClockChanged( |
| 26 chromeos::system::SystemClock* clock) { | 69 chromeos::system::SystemClock* clock) { |
| 70 ConnectToSystemTray(); |
| 27 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); | 71 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); |
| 28 } | 72 } |
| OLD | NEW |