Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2622)

Side by Side Diff: ash/mus/system_tray_delegate_mus.cc

Issue 2360143004: mash: Add SystemTrayClient interface, use to show date settings (Closed)
Patch Set: format Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ash/mus/system_tray_delegate_mus.h" 5 #include "ash/mus/system_tray_delegate_mus.h"
6 6
7 #include "ash/common/system/tray/system_tray_notifier.h" 7 #include "ash/common/system/tray/system_tray_notifier.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "base/i18n/time_formatting.h" 9 #include "base/i18n/time_formatting.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "services/shell/public/cpp/connector.h"
11 12
12 namespace ash { 13 namespace ash {
13 namespace { 14 namespace {
14 15
15 SystemTrayDelegateMus* g_instance = nullptr; 16 SystemTrayDelegateMus* g_instance = nullptr;
16 17
17 } // namespace 18 } // namespace
18 19
19 SystemTrayDelegateMus::SystemTrayDelegateMus() 20 SystemTrayDelegateMus::SystemTrayDelegateMus(shell::Connector* connector)
20 : hour_clock_type_(base::GetHourClockType()) { 21 : connector_(connector),
22 hour_clock_type_(base::GetHourClockType()),
23 weak_factory_(this) {
24 DCHECK(connector_);
25 // Don't make an initial connection to exe:chrome. Do it on demand.
26
21 DCHECK(!g_instance); 27 DCHECK(!g_instance);
22 g_instance = this; 28 g_instance = this;
23 } 29 }
24 30
25 SystemTrayDelegateMus::~SystemTrayDelegateMus() { 31 SystemTrayDelegateMus::~SystemTrayDelegateMus() {
26 DCHECK_EQ(this, g_instance); 32 DCHECK_EQ(this, g_instance);
27 g_instance = nullptr; 33 g_instance = nullptr;
28 } 34 }
29 35
30 // static 36 // static
31 SystemTrayDelegateMus* SystemTrayDelegateMus::Get() { 37 SystemTrayDelegateMus* SystemTrayDelegateMus::Get() {
32 return g_instance; 38 return g_instance;
33 } 39 }
34 40
41 void SystemTrayDelegateMus::ConnectToSystemTrayClient() {
42 // 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.
43 if (system_tray_client_.is_bound())
44 return;
45
46 // Connect to chrome browser.
47 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
48
49 // Tolerate chrome crashing and coming back up.
50 system_tray_client_.set_connection_error_handler(
51 base::Bind(&SystemTrayDelegateMus::OnClientConnectionError,
52 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.
53 }
54
55 void SystemTrayDelegateMus::OnClientConnectionError() {
56 system_tray_client_.reset();
57 }
58
35 base::HourClockType SystemTrayDelegateMus::GetHourClockType() const { 59 base::HourClockType SystemTrayDelegateMus::GetHourClockType() const {
36 return hour_clock_type_; 60 return hour_clock_type_;
37 } 61 }
38 62
63 void SystemTrayDelegateMus::ShowDateSettings() {
64 ConnectToSystemTrayClient();
65 system_tray_client_->ShowDateSettings();
66 }
67
39 void SystemTrayDelegateMus::SetUse24HourClock(bool use_24_hour) { 68 void SystemTrayDelegateMus::SetUse24HourClock(bool use_24_hour) {
40 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock; 69 hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock;
41 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); 70 WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged();
42 } 71 }
43 72
44 } // namespace ash 73 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698