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

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

Issue 2568413002: Revert of ash: Use system tray mojo interface to show system update tray icon (Closed)
Patch Set: 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_delegate_chromeos.h" 5 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "ash/common/login_status.h" 16 #include "ash/common/login_status.h"
17 #include "ash/common/session/session_state_delegate.h" 17 #include "ash/common/session/session_state_delegate.h"
18 #include "ash/common/session/session_state_observer.h" 18 #include "ash/common/session/session_state_observer.h"
19 #include "ash/common/shell_delegate.h" 19 #include "ash/common/shell_delegate.h"
20 #include "ash/common/system/chromeos/bluetooth/bluetooth_observer.h" 20 #include "ash/common/system/chromeos/bluetooth/bluetooth_observer.h"
21 #include "ash/common/system/chromeos/power/power_status.h" 21 #include "ash/common/system/chromeos/power/power_status.h"
22 #include "ash/common/system/chromeos/session/logout_button_observer.h" 22 #include "ash/common/system/chromeos/session/logout_button_observer.h"
23 #include "ash/common/system/date/clock_observer.h" 23 #include "ash/common/system/date/clock_observer.h"
24 #include "ash/common/system/ime/ime_observer.h" 24 #include "ash/common/system/ime/ime_observer.h"
25 #include "ash/common/system/tray/system_tray_notifier.h" 25 #include "ash/common/system/tray/system_tray_notifier.h"
26 #include "ash/common/system/tray_accessibility.h" 26 #include "ash/common/system/tray_accessibility.h"
27 #include "ash/common/system/update/update_observer.h"
27 #include "ash/common/system/user/user_observer.h" 28 #include "ash/common/system/user/user_observer.h"
28 #include "ash/common/wm_shell.h" 29 #include "ash/common/wm_shell.h"
29 #include "ash/system/chromeos/rotation/tray_rotation_lock.h" 30 #include "ash/system/chromeos/rotation/tray_rotation_lock.h"
30 #include "base/bind_helpers.h" 31 #include "base/bind_helpers.h"
31 #include "base/callback.h" 32 #include "base/callback.h"
32 #include "base/logging.h" 33 #include "base/logging.h"
33 #include "base/memory/ptr_util.h" 34 #include "base/memory/ptr_util.h"
34 #include "base/memory/weak_ptr.h" 35 #include "base/memory/weak_ptr.h"
35 #include "base/metrics/user_metrics.h" 36 #include "base/metrics/user_metrics.h"
36 #include "base/strings/utf_string_conversions.h" 37 #include "base/strings/utf_string_conversions.h"
(...skipping 13 matching lines...) Expand all
50 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 51 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
51 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" 52 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
52 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 53 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
53 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" 54 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
54 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" 55 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
55 #include "chrome/browser/chromeos/profiles/profile_helper.h" 56 #include "chrome/browser/chromeos/profiles/profile_helper.h"
56 #include "chrome/browser/profiles/profile_manager.h" 57 #include "chrome/browser/profiles/profile_manager.h"
57 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 58 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
58 #include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h" 59 #include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h"
59 #include "chrome/browser/ui/ash/system_tray_client.h" 60 #include "chrome/browser/ui/ash/system_tray_client.h"
61 #include "chrome/browser/ui/ash/system_tray_delegate_utils.h"
60 #include "chrome/browser/ui/browser.h" 62 #include "chrome/browser/ui/browser.h"
61 #include "chrome/browser/ui/browser_list.h" 63 #include "chrome/browser/ui/browser_list.h"
62 #include "chrome/browser/ui/chrome_pages.h" 64 #include "chrome/browser/ui/chrome_pages.h"
63 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 65 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
64 #include "chrome/browser/ui/singleton_tabs.h" 66 #include "chrome/browser/ui/singleton_tabs.h"
67 #include "chrome/browser/upgrade_detector.h"
65 #include "chrome/common/chrome_switches.h" 68 #include "chrome/common/chrome_switches.h"
66 #include "chrome/common/features.h" 69 #include "chrome/common/features.h"
67 #include "chrome/common/pref_names.h" 70 #include "chrome/common/pref_names.h"
68 #include "chrome/common/url_constants.h" 71 #include "chrome/common/url_constants.h"
69 #include "chrome/grit/generated_resources.h" 72 #include "chrome/grit/generated_resources.h"
70 #include "chrome/grit/locale_settings.h" 73 #include "chrome/grit/locale_settings.h"
71 #include "chromeos/dbus/dbus_thread_manager.h" 74 #include "chromeos/dbus/dbus_thread_manager.h"
72 #include "chromeos/dbus/session_manager_client.h" 75 #include "chromeos/dbus/session_manager_client.h"
73 #include "chromeos/login/login_state.h" 76 #include "chromeos/login/login_state.h"
74 #include "chromeos/network/portal_detector/network_portal_detector.h" 77 #include "chromeos/network/portal_detector/network_portal_detector.h"
(...skipping 24 matching lines...) Expand all
99 namespace chromeos { 102 namespace chromeos {
100 103
101 namespace { 104 namespace {
102 105
103 // The minimum session length limit that can be set. 106 // The minimum session length limit that can be set.
104 const int kSessionLengthLimitMinMs = 30 * 1000; // 30 seconds. 107 const int kSessionLengthLimitMinMs = 30 * 1000; // 30 seconds.
105 108
106 // The maximum session length limit that can be set. 109 // The maximum session length limit that can be set.
107 const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000; // 24 hours. 110 const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000; // 24 hours.
108 111
112 // A pointer so that callers can access the single class instance.
113 SystemTrayDelegateChromeOS* g_instance = nullptr;
114
109 void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime, 115 void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime,
110 const input_method::InputMethodUtil& util, 116 const input_method::InputMethodUtil& util,
111 ash::IMEInfo* info) { 117 ash::IMEInfo* info) {
112 info->id = ime.id(); 118 info->id = ime.id();
113 info->name = util.GetInputMethodLongName(ime); 119 info->name = util.GetInputMethodLongName(ime);
114 info->medium_name = util.GetInputMethodMediumName(ime); 120 info->medium_name = util.GetInputMethodMediumName(ime);
115 info->short_name = util.GetInputMethodShortName(ime); 121 info->short_name = util.GetInputMethodShortName(ime);
116 info->third_party = extension_ime_util::IsExtensionIME(ime.id()); 122 info->third_party = extension_ime_util::IsExtensionIME(ime.id());
117 } 123 }
118 124
(...skipping 19 matching lines...) Expand all
138 144
139 } // namespace 145 } // namespace
140 146
141 SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() 147 SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
142 : networking_config_delegate_(new NetworkingConfigDelegateChromeos()), 148 : networking_config_delegate_(new NetworkingConfigDelegateChromeos()),
143 weak_ptr_factory_(this) { 149 weak_ptr_factory_(this) {
144 // Register notifications on construction so that events such as 150 // Register notifications on construction so that events such as
145 // PROFILE_CREATED do not get missed if they happen before Initialize(). 151 // PROFILE_CREATED do not get missed if they happen before Initialize().
146 registrar_.reset(new content::NotificationRegistrar); 152 registrar_.reset(new content::NotificationRegistrar);
147 registrar_->Add(this, 153 registrar_->Add(this,
154 chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
155 content::NotificationService::AllSources());
156 registrar_->Add(this,
148 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 157 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
149 content::NotificationService::AllSources()); 158 content::NotificationService::AllSources());
150 if (GetUserLoginStatus() == ash::LoginStatus::NOT_LOGGED_IN) { 159 if (GetUserLoginStatus() == ash::LoginStatus::NOT_LOGGED_IN) {
151 registrar_->Add(this, 160 registrar_->Add(this,
152 chrome::NOTIFICATION_SESSION_STARTED, 161 chrome::NOTIFICATION_SESSION_STARTED,
153 content::NotificationService::AllSources()); 162 content::NotificationService::AllSources());
154 } 163 }
155 registrar_->Add(this, 164 registrar_->Add(this,
156 chrome::NOTIFICATION_PROFILE_CREATED, 165 chrome::NOTIFICATION_PROFILE_CREATED,
157 content::NotificationService::AllSources()); 166 content::NotificationService::AllSources());
158 registrar_->Add(this, 167 registrar_->Add(this,
159 chrome::NOTIFICATION_PROFILE_DESTROYED, 168 chrome::NOTIFICATION_PROFILE_DESTROYED,
160 content::NotificationService::AllSources()); 169 content::NotificationService::AllSources());
161 170
162 AccessibilityManager* accessibility_manager = AccessibilityManager::Get(); 171 AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
163 CHECK(accessibility_manager); 172 CHECK(accessibility_manager);
164 accessibility_subscription_ = accessibility_manager->RegisterCallback( 173 accessibility_subscription_ = accessibility_manager->RegisterCallback(
165 base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged, 174 base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged,
166 base::Unretained(this))); 175 base::Unretained(this)));
167 176
168 user_manager::UserManager::Get()->AddSessionStateObserver(this); 177 user_manager::UserManager::Get()->AddSessionStateObserver(this);
178
179 DCHECK(!g_instance);
180 g_instance = this;
181 }
182
183 // static
184 SystemTrayDelegateChromeOS* SystemTrayDelegateChromeOS::instance() {
185 return g_instance;
169 } 186 }
170 187
171 void SystemTrayDelegateChromeOS::Initialize() { 188 void SystemTrayDelegateChromeOS::Initialize() {
172 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); 189 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
173 190
174 input_method::InputMethodManager::Get()->AddObserver(this); 191 input_method::InputMethodManager::Get()->AddObserver(this);
175 input_method::InputMethodManager::Get()->AddImeMenuObserver(this); 192 input_method::InputMethodManager::Get()->AddImeMenuObserver(this);
176 ui::ime::InputMethodMenuManager::GetInstance()->AddObserver(this); 193 ui::ime::InputMethodMenuManager::GetInstance()->AddObserver(this);
177 194
178 device::BluetoothAdapterFactory::GetAdapter( 195 device::BluetoothAdapterFactory::GetAdapter(
(...skipping 29 matching lines...) Expand all
208 policy::BrowserPolicyConnectorChromeOS* policy_connector = 225 policy::BrowserPolicyConnectorChromeOS* policy_connector =
209 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 226 g_browser_process->platform_part()->browser_policy_connector_chromeos();
210 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = 227 policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
211 policy_connector->GetDeviceCloudPolicyManager(); 228 policy_connector->GetDeviceCloudPolicyManager();
212 if (policy_manager) 229 if (policy_manager)
213 policy_manager->core()->store()->AddObserver(this); 230 policy_manager->core()->store()->AddObserver(this);
214 UpdateEnterpriseDomain(); 231 UpdateEnterpriseDomain();
215 } 232 }
216 233
217 SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() { 234 SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
235 DCHECK_EQ(this, g_instance);
236 g_instance = nullptr;
237
218 // Unregister PrefChangeRegistrars. 238 // Unregister PrefChangeRegistrars.
219 local_state_registrar_.reset(); 239 local_state_registrar_.reset();
220 user_pref_registrar_.reset(); 240 user_pref_registrar_.reset();
221 241
222 // Unregister content notifications before destroying any components. 242 // Unregister content notifications before destroying any components.
223 registrar_.reset(); 243 registrar_.reset();
224 244
225 // Unregister a11y status subscription. 245 // Unregister a11y status subscription.
226 accessibility_subscription_.reset(); 246 accessibility_subscription_.reset();
227 247
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 318
299 bool SystemTrayDelegateChromeOS::IsUserSupervised() const { 319 bool SystemTrayDelegateChromeOS::IsUserSupervised() const {
300 user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser(); 320 user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser();
301 return user && user->IsSupervised(); 321 return user && user->IsSupervised();
302 } 322 }
303 323
304 bool SystemTrayDelegateChromeOS::IsUserChild() const { 324 bool SystemTrayDelegateChromeOS::IsUserChild() const {
305 return user_manager::UserManager::Get()->IsLoggedInAsChildUser(); 325 return user_manager::UserManager::Get()->IsLoggedInAsChildUser();
306 } 326 }
307 327
328 void SystemTrayDelegateChromeOS::GetSystemUpdateInfo(
329 ash::UpdateInfo* info) const {
330 GetUpdateInfo(UpgradeDetector::GetInstance(), info);
331 // If a flash component update is available, force the tray to show the user
332 // the Restart to Update dialog.
333 if (flash_update_available_)
334 info->update_required = true;
335 }
336
308 bool SystemTrayDelegateChromeOS::ShouldShowSettings() const { 337 bool SystemTrayDelegateChromeOS::ShouldShowSettings() const {
309 // Show setting button only when the user flow allows and it's not in the 338 // Show setting button only when the user flow allows and it's not in the
310 // multi-profile login screen. 339 // multi-profile login screen.
311 return ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldShowSettings() && 340 return ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldShowSettings() &&
312 !IsSessionInSecondaryLoginScreen(); 341 !IsSessionInSecondaryLoginScreen();
313 } 342 }
314 343
315 bool SystemTrayDelegateChromeOS::ShouldShowNotificationTray() const { 344 bool SystemTrayDelegateChromeOS::ShouldShowNotificationTray() const {
316 // Show notification tray only when the user flow allows and it's not in the 345 // Show notification tray only when the user flow allows and it's not in the
317 // multi-profile login screen. 346 // multi-profile login screen.
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 void SystemTrayDelegateChromeOS::UserChangedChildStatus( 617 void SystemTrayDelegateChromeOS::UserChangedChildStatus(
589 user_manager::User* user) { 618 user_manager::User* user) {
590 Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(user); 619 Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(user);
591 620
592 // Returned user_profile might be NULL on restoring Users on browser start. 621 // Returned user_profile might be NULL on restoring Users on browser start.
593 // At some point profile is not yet fully initiated. 622 // At some point profile is not yet fully initiated.
594 if (session_started_ && user_profile && user_profile_ == user_profile) 623 if (session_started_ && user_profile && user_profile_ == user_profile)
595 ash::WmShell::Get()->UpdateAfterLoginStatusChange(GetUserLoginStatus()); 624 ash::WmShell::Get()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
596 } 625 }
597 626
627 void SystemTrayDelegateChromeOS::SetFlashUpdateAvailable() {
628 flash_update_available_ = true;
629
630 ash::UpdateInfo info;
631 GetSystemUpdateInfo(&info);
632 GetSystemTrayNotifier()->NotifyUpdateRecommended(info);
633 }
634
635 bool SystemTrayDelegateChromeOS::GetFlashUpdateAvailable() {
636 return flash_update_available_;
637 }
638
598 ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() { 639 ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() {
599 return ash::WmShell::Get()->system_tray_notifier(); 640 return ash::WmShell::Get()->system_tray_notifier();
600 } 641 }
601 642
602 void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) { 643 void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
603 // Stop observing the AppWindowRegistry of the current |user_profile_|. 644 // Stop observing the AppWindowRegistry of the current |user_profile_|.
604 StopObservingAppWindowRegistry(); 645 StopObservingAppWindowRegistry();
605 646
606 // Stop observing custodian info changes of the current |user_profile_|. 647 // Stop observing custodian info changes of the current |user_profile_|.
607 StopObservingCustodianInfoChanges(); 648 StopObservingCustodianInfoChanges();
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 void SystemTrayDelegateChromeOS::ScreenIsUnlocked() { 796 void SystemTrayDelegateChromeOS::ScreenIsUnlocked() {
756 ash::WmShell::Get()->UpdateAfterLoginStatusChange(GetUserLoginStatus()); 797 ash::WmShell::Get()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
757 } 798 }
758 799
759 // content::NotificationObserver implementation. 800 // content::NotificationObserver implementation.
760 void SystemTrayDelegateChromeOS::Observe( 801 void SystemTrayDelegateChromeOS::Observe(
761 int type, 802 int type,
762 const content::NotificationSource& source, 803 const content::NotificationSource& source,
763 const content::NotificationDetails& details) { 804 const content::NotificationDetails& details) {
764 switch (type) { 805 switch (type) {
806 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
807 ash::UpdateInfo info;
808 GetUpdateInfo(content::Source<UpgradeDetector>(source).ptr(), &info);
809 GetSystemTrayNotifier()->NotifyUpdateRecommended(info);
810 break;
811 }
765 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { 812 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: {
766 // This notification is also sent on login screen when user avatar 813 // This notification is also sent on login screen when user avatar
767 // is loaded from file. 814 // is loaded from file.
768 if (GetUserLoginStatus() != ash::LoginStatus::NOT_LOGGED_IN) { 815 if (GetUserLoginStatus() != ash::LoginStatus::NOT_LOGGED_IN) {
769 GetSystemTrayNotifier()->NotifyUserUpdate(); 816 GetSystemTrayNotifier()->NotifyUserUpdate();
770 } 817 }
771 break; 818 break;
772 } 819 }
773 case chrome::NOTIFICATION_PROFILE_CREATED: { 820 case chrome::NOTIFICATION_PROFILE_CREATED: {
774 SetProfile(content::Source<Profile>(source).ptr()); 821 SetProfile(content::Source<Profile>(source).ptr());
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 LOG(WARNING) << "SystemTrayDelegateChromeOS::GetChildUserMessage call while " 1025 LOG(WARNING) << "SystemTrayDelegateChromeOS::GetChildUserMessage call while "
979 << "ENABLE_SUPERVISED_USERS undefined."; 1026 << "ENABLE_SUPERVISED_USERS undefined.";
980 return base::string16(); 1027 return base::string16();
981 } 1028 }
982 1029
983 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { 1030 ash::SystemTrayDelegate* CreateSystemTrayDelegate() {
984 return new SystemTrayDelegateChromeOS(); 1031 return new SystemTrayDelegateChromeOS();
985 } 1032 }
986 1033
987 } // namespace chromeos 1034 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698