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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 registrar_.Add(this, | 134 registrar_.Add(this, |
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 (user_manager::UserManager::IsInitialized()) |
145 chromeos::UserManager::Get()->AddSessionStateObserver(this); | 145 user_manager::UserManager::Get()->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 (user_manager::UserManager::IsInitialized()) |
153 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); | 153 user_manager::UserManager::Get()->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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 observers_, | 439 observers_, |
440 NotifierGroupChanged()); | 440 NotifierGroupChanged()); |
441 } | 441 } |
442 | 442 |
443 #if defined(OS_CHROMEOS) | 443 #if defined(OS_CHROMEOS) |
444 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { | 444 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { |
445 // Already created. | 445 // Already created. |
446 if (!notifier_groups_.empty()) | 446 if (!notifier_groups_.empty()) |
447 return; | 447 return; |
448 | 448 |
449 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 449 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
450 // |notifier_groups_| can be empty in login screen too. | 450 // |notifier_groups_| can be empty in login screen too. |
451 if (!user_manager->IsLoggedInAsGuest()) | 451 if (!user_manager->IsLoggedInAsGuest()) |
452 return; | 452 return; |
453 | 453 |
454 user_manager::User* user = user_manager->GetActiveUser(); | 454 user_manager::User* user = user_manager->GetActiveUser(); |
455 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); | 455 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
456 DCHECK(profile); | 456 DCHECK(profile); |
457 notifier_groups_.push_back( | 457 notifier_groups_.push_back( |
458 new message_center::ProfileNotifierGroup(gfx::Image(user->GetImage()), | 458 new message_center::ProfileNotifierGroup(gfx::Image(user->GetImage()), |
459 user->GetDisplayName(), | 459 user->GetDisplayName(), |
(...skipping 20 matching lines...) Expand all Loading... |
480 profile_info_cache_->GetNameOfProfileAtIndex(i), | 480 profile_info_cache_->GetNameOfProfileAtIndex(i), |
481 profile_info_cache_->GetUserNameOfProfileAtIndex(i), | 481 profile_info_cache_->GetUserNameOfProfileAtIndex(i), |
482 i, | 482 i, |
483 profile_info_cache_->GetPathOfProfileAtIndex(i))); | 483 profile_info_cache_->GetPathOfProfileAtIndex(i))); |
484 if (group->profile() == NULL) | 484 if (group->profile() == NULL) |
485 continue; | 485 continue; |
486 | 486 |
487 #if defined(OS_CHROMEOS) | 487 #if defined(OS_CHROMEOS) |
488 // Allows the active user only. | 488 // Allows the active user only. |
489 // UserManager may not exist in some tests. | 489 // UserManager may not exist in some tests. |
490 if (chromeos::UserManager::IsInitialized()) { | 490 if (user_manager::UserManager::IsInitialized()) { |
491 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 491 user_manager::UserManager* user_manager = |
| 492 user_manager::UserManager::Get(); |
492 if (chromeos::ProfileHelper::Get()->GetUserByProfile(group->profile()) != | 493 if (chromeos::ProfileHelper::Get()->GetUserByProfile(group->profile()) != |
493 user_manager->GetActiveUser()) { | 494 user_manager->GetActiveUser()) { |
494 continue; | 495 continue; |
495 } | 496 } |
496 } | 497 } |
497 | 498 |
498 // In ChromeOS, the login screen first creates a dummy profile which is not | 499 // In ChromeOS, the login screen first creates a dummy profile which is not |
499 // actually used, and then the real profile for the user is created when | 500 // actually used, and then the real profile for the user is created when |
500 // login (or turns into kiosk mode). This profile should be skipped. | 501 // login (or turns into kiosk mode). This profile should be skipped. |
501 if (chromeos::ProfileHelper::IsSigninProfile(group->profile())) | 502 if (chromeos::ProfileHelper::IsSigninProfile(group->profile())) |
502 continue; | 503 continue; |
503 #endif | 504 #endif |
504 notifier_groups_.push_back(group.release()); | 505 notifier_groups_.push_back(group.release()); |
505 } | 506 } |
506 | 507 |
507 #if defined(OS_CHROMEOS) | 508 #if defined(OS_CHROMEOS) |
508 // ChromeOS guest login cannot get the profile from the for-loop above, so | 509 // ChromeOS guest login cannot get the profile from the for-loop above, so |
509 // get the group here. | 510 // get the group here. |
510 if (notifier_groups_.empty() && chromeos::UserManager::IsInitialized() && | 511 if (notifier_groups_.empty() && user_manager::UserManager::IsInitialized() && |
511 chromeos::UserManager::Get()->IsLoggedInAsGuest()) { | 512 user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
512 // Do not invoke CreateNotifierGroupForGuestLogin() directly. In some tests, | 513 // Do not invoke CreateNotifierGroupForGuestLogin() directly. In some tests, |
513 // this method may be called before the primary profile is created, which | 514 // this method may be called before the primary profile is created, which |
514 // means ProfileHelper::Get()->GetProfileByUser() will create a new primary | 515 // means ProfileHelper::Get()->GetProfileByUser() will create a new primary |
515 // profile. But creating a primary profile causes an Observe() before | 516 // profile. But creating a primary profile causes an Observe() before |
516 // registering it as the primary one, which causes this method which causes | 517 // registering it as the primary one, which causes this method which causes |
517 // another creating a primary profile, and causes an infinite loop. | 518 // another creating a primary profile, and causes an infinite loop. |
518 // Thus, it would be better to delay creating group for guest login. | 519 // Thus, it would be better to delay creating group for guest login. |
519 base::MessageLoopProxy::current()->PostTask( | 520 base::MessageLoopProxy::current()->PostTask( |
520 FROM_HERE, | 521 FROM_HERE, |
521 base::Bind( | 522 base::Bind( |
522 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, | 523 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, |
523 weak_factory_.GetWeakPtr())); | 524 weak_factory_.GetWeakPtr())); |
524 } | 525 } |
525 #endif | 526 #endif |
526 } | 527 } |
OLD | NEW |