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

Side by Side Diff: chrome/browser/ui/ash/system_tray_client.cc

Issue 2558043006: ash: Use system tray mojo interface to show system update tray icon (Closed)
Patch Set: Make Flash updates yellow Created 4 years 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 "chrome/browser/ui/ash/system_tray_client.h" 5 #include "chrome/browser/ui/ash/system_tray_client.h"
6 6
7 #include "ash/common/login_status.h" 7 #include "ash/common/login_status.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browser_process_platform_part.h" 14 #include "chrome/browser/browser_process_platform_part.h"
15 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" 16 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
16 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 17 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
17 #include "chrome/browser/chromeos/options/network_config_view.h" 18 #include "chrome/browser/chromeos/options/network_config_view.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 19 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/chromeos/set_time_dialog.h" 20 #include "chrome/browser/chromeos/set_time_dialog.h"
20 #include "chrome/browser/chromeos/system/system_clock.h" 21 #include "chrome/browser/chromeos/system/system_clock.h"
21 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" 22 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
22 #include "chrome/browser/lifetime/application_lifetime.h" 23 #include "chrome/browser/lifetime/application_lifetime.h"
23 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/ui/ash/ash_util.h" 25 #include "chrome/browser/ui/ash/ash_util.h"
25 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" 26 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
26 #include "chrome/browser/ui/chrome_pages.h" 27 #include "chrome/browser/ui/chrome_pages.h"
27 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 28 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
28 #include "chrome/browser/ui/singleton_tabs.h" 29 #include "chrome/browser/ui/singleton_tabs.h"
30 #include "chrome/browser/upgrade_detector.h"
29 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
30 #include "chromeos/dbus/dbus_thread_manager.h" 32 #include "chromeos/dbus/dbus_thread_manager.h"
31 #include "chromeos/dbus/session_manager_client.h" 33 #include "chromeos/dbus/session_manager_client.h"
32 #include "chromeos/login/login_state.h" 34 #include "chromeos/login/login_state.h"
33 #include "components/user_manager/user_manager.h" 35 #include "components/user_manager/user_manager.h"
36 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/user_metrics.h" 37 #include "content/public/browser/user_metrics.h"
35 #include "content/public/common/service_manager_connection.h" 38 #include "content/public/common/service_manager_connection.h"
36 #include "extensions/browser/api/vpn_provider/vpn_service.h" 39 #include "extensions/browser/api/vpn_provider/vpn_service.h"
37 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" 40 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h"
38 #include "net/base/escape.h" 41 #include "net/base/escape.h"
39 #include "services/service_manager/public/cpp/connector.h" 42 #include "services/service_manager/public/cpp/connector.h"
40 #include "services/ui/public/cpp/property_type_converters.h" 43 #include "services/ui/public/cpp/property_type_converters.h"
41 #include "services/ui/public/interfaces/window_manager.mojom.h" 44 #include "services/ui/public/interfaces/window_manager.mojom.h"
42 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" 45 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
43 #include "ui/views/widget/widget.h" 46 #include "ui/views/widget/widget.h"
44 #include "ui/views/window/dialog_delegate.h" 47 #include "ui/views/window/dialog_delegate.h"
45 48
46 using chromeos::DBusThreadManager; 49 using chromeos::DBusThreadManager;
47 using chromeos::LoginState; 50 using chromeos::LoginState;
48 using views::Widget; 51 using views::Widget;
49 52
50 namespace { 53 namespace {
51 54
52 const char kDisplaySettingsSubPageName[] = "display"; 55 const char kDisplaySettingsSubPageName[] = "display";
53 const char kPaletteSettingsSubPageName[] = "stylus-overlay"; 56 const char kPaletteSettingsSubPageName[] = "stylus-overlay";
54 57
55 SystemTrayClient* g_instance = nullptr; 58 SystemTrayClient* g_instance = nullptr;
56 59
57 void ShowSettingsSubPageForActiveUser(const std::string& sub_page) { 60 void ShowSettingsSubPageForActiveUser(const std::string& sub_page) {
58 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), 61 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(),
59 sub_page); 62 sub_page);
60 } 63 }
61 64
65 // Returns the severity of a pending Chrome / Chrome OS update.
66 ash::mojom::UpdateSeverity GetUpdateSeverity(UpgradeDetector* detector) {
67 switch (detector->upgrade_notification_stage()) {
68 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
69 return ash::mojom::UpdateSeverity::NONE;
70 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
71 return ash::mojom::UpdateSeverity::LOW;
72 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
73 return ash::mojom::UpdateSeverity::ELEVATED;
74 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
75 return ash::mojom::UpdateSeverity::HIGH;
76 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
77 return ash::mojom::UpdateSeverity::SEVERE;
78 case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
79 return ash::mojom::UpdateSeverity::CRITICAL;
80 }
81 }
82
62 } // namespace 83 } // namespace
63 84
64 SystemTrayClient::SystemTrayClient() : binding_(this) { 85 SystemTrayClient::SystemTrayClient() : binding_(this) {
65 content::ServiceManagerConnection::GetForProcess() 86 content::ServiceManagerConnection::GetForProcess()
66 ->GetConnector() 87 ->GetConnector()
67 ->ConnectToInterface(ash_util::GetAshServiceName(), &system_tray_); 88 ->ConnectToInterface(ash_util::GetAshServiceName(), &system_tray_);
68 // Register this object as the client interface implementation. 89 // Register this object as the client interface implementation.
69 system_tray_->SetClient(binding_.CreateInterfacePtrAndBind()); 90 system_tray_->SetClient(binding_.CreateInterfacePtrAndBind());
70 91
71 // If this observes clock setting changes before ash comes up the IPCs will 92 // If this observes clock setting changes before ash comes up the IPCs will
72 // be queued on |system_tray_|. 93 // be queued on |system_tray_|.
73 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); 94 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this);
74 95
96 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
97 content::NotificationService::AllSources());
98
99 // If an upgrade is available at startup then tell ash about it.
100 if (UpgradeDetector::GetInstance()->notify_upgrade())
101 HandleUpdateAvailable();
102
75 DCHECK(!g_instance); 103 DCHECK(!g_instance);
76 g_instance = this; 104 g_instance = this;
77 } 105 }
78 106
79 SystemTrayClient::~SystemTrayClient() { 107 SystemTrayClient::~SystemTrayClient() {
80 DCHECK_EQ(this, g_instance); 108 DCHECK_EQ(this, g_instance);
81 g_instance = nullptr; 109 g_instance = nullptr;
82 110
83 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this); 111 g_browser_process->platform_part()->GetSystemClock()->RemoveObserver(this);
84 } 112 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 mojo::ConvertTo<std::vector<uint8_t>>(container_id); 188 mojo::ConvertTo<std::vector<uint8_t>>(container_id);
161 } else { 189 } else {
162 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), 190 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
163 container_id); 191 container_id);
164 } 192 }
165 Widget* widget = new Widget; // Owned by native widget. 193 Widget* widget = new Widget; // Owned by native widget.
166 widget->Init(params); 194 widget->Init(params);
167 return widget; 195 return widget;
168 } 196 }
169 197
198 void SystemTrayClient::SetFlashUpdateAvailable() {
199 flash_update_available_ = true;
200 HandleUpdateAvailable();
201 }
202
170 //////////////////////////////////////////////////////////////////////////////// 203 ////////////////////////////////////////////////////////////////////////////////
171 // ash::mojom::SystemTrayClient: 204 // ash::mojom::SystemTrayClient:
172 205
173 void SystemTrayClient::ShowSettings() { 206 void SystemTrayClient::ShowSettings() {
174 ShowSettingsSubPageForActiveUser(std::string()); 207 ShowSettingsSubPageForActiveUser(std::string());
175 } 208 }
176 209
177 void SystemTrayClient::ShowDateSettings() { 210 void SystemTrayClient::ShowDateSettings() {
178 content::RecordAction(base::UserMetricsAction("ShowDateOptions")); 211 content::RecordAction(base::UserMetricsAction("ShowDateOptions"));
179 // Everybody can change the time zone (even though it is a device setting). 212 // Everybody can change the time zone (even though it is a device setting).
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 CHECK(!login_state->IsUserLoggedIn() || 335 CHECK(!login_state->IsUserLoggedIn() ||
303 login_state->GetLoggedInUserType() == LoginState::LOGGED_IN_USER_NONE); 336 login_state->GetLoggedInUserType() == LoginState::LOGGED_IN_USER_NONE);
304 chromeos::LoginDisplayHost::default_host()->OpenProxySettings(); 337 chromeos::LoginDisplayHost::default_host()->OpenProxySettings();
305 } 338 }
306 339
307 void SystemTrayClient::SignOut() { 340 void SystemTrayClient::SignOut() {
308 chrome::AttemptUserExit(); 341 chrome::AttemptUserExit();
309 } 342 }
310 343
311 void SystemTrayClient::RequestRestartForUpdate() { 344 void SystemTrayClient::RequestRestartForUpdate() {
312 bool component_update = false; 345 // Flash updates on Chrome OS require device reboot.
313 chromeos::SystemTrayDelegateChromeOS* tray = 346 const chrome::RebootPolicy reboot_policy =
314 chromeos::SystemTrayDelegateChromeOS::instance(); 347 flash_update_available_ ? chrome::RebootPolicy::kForceReboot
315 if (tray) 348 : chrome::RebootPolicy::kOptionalReboot;
316 component_update = tray->GetFlashUpdateAvailable();
317
318 chrome::RebootPolicy reboot_policy =
319 component_update ? chrome::RebootPolicy::kForceReboot
320 : chrome::RebootPolicy::kOptionalReboot;
321 349
322 chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy); 350 chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy);
323 } 351 }
324 352
353 void SystemTrayClient::HandleUpdateAvailable() {
354 // Show update icon for Chrome updates and Flash component updates.
msw 2016/12/09 23:41:51 nit: "Show an update icon"
James Cook 2016/12/12 18:15:12 Done.
355 UpgradeDetector* detector = UpgradeDetector::GetInstance();
356 DCHECK(detector->notify_upgrade() || flash_update_available_);
357
358 // Get the Chrome update severity.
359 ash::mojom::UpdateSeverity severity = GetUpdateSeverity(detector);
360
361 // Flash updates are elevated severity unless the Chrome severity is higher.
362 if (flash_update_available_)
363 severity = std::max(severity, ash::mojom::UpdateSeverity::ELEVATED);
364
365 system_tray_->ShowUpdateIcon(severity, detector->is_factory_reset_required());
366 }
367
325 //////////////////////////////////////////////////////////////////////////////// 368 ////////////////////////////////////////////////////////////////////////////////
326 // chromeos::system::SystemClockObserver: 369 // chromeos::system::SystemClockObserver:
327 370
328 void SystemTrayClient::OnSystemClockChanged( 371 void SystemTrayClient::OnSystemClockChanged(
329 chromeos::system::SystemClock* clock) { 372 chromeos::system::SystemClock* clock) {
330 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); 373 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock());
331 } 374 }
375
376 void SystemTrayClient::Observe(int type,
377 const content::NotificationSource& source,
378 const content::NotificationDetails& details) {
379 DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type);
380 HandleUpdateAvailable();
381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698