OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/notifications/message_center_settings_controller.h" | 5 #include "chrome/browser/notifications/message_center_settings_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/string_compare.h" | 10 #include "base/i18n/string_compare.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 chrome::NOTIFICATION_PROFILE_DESTROYED, | 135 chrome::NOTIFICATION_PROFILE_DESTROYED, |
136 content::NotificationService::AllBrowserContextsAndSources()); | 136 content::NotificationService::AllBrowserContextsAndSources()); |
137 registrar_.Add(this, | 137 registrar_.Add(this, |
138 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 138 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
139 content::NotificationService::AllBrowserContextsAndSources()); | 139 content::NotificationService::AllBrowserContextsAndSources()); |
140 RebuildNotifierGroups(); | 140 RebuildNotifierGroups(); |
141 | 141 |
142 #if defined(OS_CHROMEOS) | 142 #if defined(OS_CHROMEOS) |
143 // UserManager may not exist in some tests. | 143 // UserManager may not exist in some tests. |
144 if (chromeos::UserManager::IsInitialized()) | 144 if (chromeos::UserManager::IsInitialized()) |
145 chromeos::UserManager::Get()->AddSessionStateObserver(this); | 145 chromeos::GetUserManager()->AddSessionStateObserver(this); |
146 #endif | 146 #endif |
147 } | 147 } |
148 | 148 |
149 MessageCenterSettingsController::~MessageCenterSettingsController() { | 149 MessageCenterSettingsController::~MessageCenterSettingsController() { |
150 #if defined(OS_CHROMEOS) | 150 #if defined(OS_CHROMEOS) |
151 // UserManager may not exist in some tests. | 151 // UserManager may not exist in some tests. |
152 if (chromeos::UserManager::IsInitialized()) | 152 if (chromeos::UserManager::IsInitialized()) |
153 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); | 153 chromeos::GetUserManager()->RemoveSessionStateObserver(this); |
154 #endif | 154 #endif |
155 } | 155 } |
156 | 156 |
157 void MessageCenterSettingsController::AddObserver( | 157 void MessageCenterSettingsController::AddObserver( |
158 message_center::NotifierSettingsObserver* observer) { | 158 message_center::NotifierSettingsObserver* observer) { |
159 observers_.AddObserver(observer); | 159 observers_.AddObserver(observer); |
160 } | 160 } |
161 | 161 |
162 void MessageCenterSettingsController::RemoveObserver( | 162 void MessageCenterSettingsController::RemoveObserver( |
163 message_center::NotifierSettingsObserver* observer) { | 163 message_center::NotifierSettingsObserver* observer) { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 observers_, | 444 observers_, |
445 NotifierGroupChanged()); | 445 NotifierGroupChanged()); |
446 } | 446 } |
447 | 447 |
448 #if defined(OS_CHROMEOS) | 448 #if defined(OS_CHROMEOS) |
449 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { | 449 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { |
450 // Already created. | 450 // Already created. |
451 if (!notifier_groups_.empty()) | 451 if (!notifier_groups_.empty()) |
452 return; | 452 return; |
453 | 453 |
454 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 454 chromeos::UserManager* user_manager = chromeos::GetUserManager(); |
455 // |notifier_groups_| can be empty in login screen too. | 455 // |notifier_groups_| can be empty in login screen too. |
456 if (!user_manager->IsLoggedInAsGuest()) | 456 if (!user_manager->IsLoggedInAsGuest()) |
457 return; | 457 return; |
458 | 458 |
459 chromeos::User* user = user_manager->GetActiveUser(); | 459 chromeos::User* user = user_manager->GetActiveUser(); |
460 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); | 460 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
461 DCHECK(profile); | 461 DCHECK(profile); |
462 notifier_groups_.push_back( | 462 notifier_groups_.push_back( |
463 new message_center::ProfileNotifierGroup(gfx::Image(user->GetImage()), | 463 new message_center::ProfileNotifierGroup(gfx::Image(user->GetImage()), |
464 user->GetDisplayName(), | 464 user->GetDisplayName(), |
(...skipping 21 matching lines...) Expand all Loading... |
486 profile_info_cache_->GetUserNameOfProfileAtIndex(i), | 486 profile_info_cache_->GetUserNameOfProfileAtIndex(i), |
487 i, | 487 i, |
488 profile_info_cache_->GetPathOfProfileAtIndex(i))); | 488 profile_info_cache_->GetPathOfProfileAtIndex(i))); |
489 if (group->profile() == NULL) | 489 if (group->profile() == NULL) |
490 continue; | 490 continue; |
491 | 491 |
492 #if defined(OS_CHROMEOS) | 492 #if defined(OS_CHROMEOS) |
493 // Allows the active user only. | 493 // Allows the active user only. |
494 // UserManager may not exist in some tests. | 494 // UserManager may not exist in some tests. |
495 if (chromeos::UserManager::IsInitialized()) { | 495 if (chromeos::UserManager::IsInitialized()) { |
496 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 496 chromeos::UserManager* user_manager = chromeos::GetUserManager(); |
497 if (chromeos::ProfileHelper::Get()->GetUserByProfile(group->profile()) != | 497 if (chromeos::ProfileHelper::Get()->GetUserByProfile(group->profile()) != |
498 user_manager->GetActiveUser()) { | 498 user_manager->GetActiveUser()) { |
499 continue; | 499 continue; |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 // In ChromeOS, the login screen first creates a dummy profile which is not | 503 // In ChromeOS, the login screen first creates a dummy profile which is not |
504 // actually used, and then the real profile for the user is created when | 504 // actually used, and then the real profile for the user is created when |
505 // login (or turns into kiosk mode). This profile should be skipped. | 505 // login (or turns into kiosk mode). This profile should be skipped. |
506 if (chromeos::ProfileHelper::IsSigninProfile(group->profile())) | 506 if (chromeos::ProfileHelper::IsSigninProfile(group->profile())) |
507 continue; | 507 continue; |
508 #endif | 508 #endif |
509 notifier_groups_.push_back(group.release()); | 509 notifier_groups_.push_back(group.release()); |
510 } | 510 } |
511 | 511 |
512 #if defined(OS_CHROMEOS) | 512 #if defined(OS_CHROMEOS) |
513 // ChromeOS guest login cannot get the profile from the for-loop above, so | 513 // ChromeOS guest login cannot get the profile from the for-loop above, so |
514 // get the group here. | 514 // get the group here. |
515 if (notifier_groups_.empty() && chromeos::UserManager::IsInitialized() && | 515 if (notifier_groups_.empty() && chromeos::UserManager::IsInitialized() && |
516 chromeos::UserManager::Get()->IsLoggedInAsGuest()) { | 516 chromeos::GetUserManager()->IsLoggedInAsGuest()) { |
517 // Do not invoke CreateNotifierGroupForGuestLogin() directly. In some tests, | 517 // Do not invoke CreateNotifierGroupForGuestLogin() directly. In some tests, |
518 // this method may be called before the primary profile is created, which | 518 // this method may be called before the primary profile is created, which |
519 // means ProfileHelper::Get()->GetProfileByUser() will create a new primary | 519 // means ProfileHelper::Get()->GetProfileByUser() will create a new primary |
520 // profile. But creating a primary profile causes an Observe() before | 520 // profile. But creating a primary profile causes an Observe() before |
521 // registering it as the primary one, which causes this method which causes | 521 // registering it as the primary one, which causes this method which causes |
522 // another creating a primary profile, and causes an infinite loop. | 522 // another creating a primary profile, and causes an infinite loop. |
523 // Thus, it would be better to delay creating group for guest login. | 523 // Thus, it would be better to delay creating group for guest login. |
524 base::MessageLoopProxy::current()->PostTask( | 524 base::MessageLoopProxy::current()->PostTask( |
525 FROM_HERE, | 525 FROM_HERE, |
526 base::Bind( | 526 base::Bind( |
527 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, | 527 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, |
528 weak_factory_.GetWeakPtr())); | 528 weak_factory_.GetWeakPtr())); |
529 } | 529 } |
530 #endif | 530 #endif |
531 } | 531 } |
OLD | NEW |