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