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

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

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

Powered by Google App Engine
This is Rietveld 408576698