Chromium Code Reviews| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 // rebuild the list when we get any of them. | 127 // rebuild the list when we get any of them. |
| 128 registrar_.Add(this, | 128 registrar_.Add(this, |
| 129 chrome::NOTIFICATION_PROFILE_CREATED, | 129 chrome::NOTIFICATION_PROFILE_CREATED, |
| 130 content::NotificationService::AllBrowserContextsAndSources()); | 130 content::NotificationService::AllBrowserContextsAndSources()); |
| 131 registrar_.Add(this, | 131 registrar_.Add(this, |
| 132 chrome::NOTIFICATION_PROFILE_ADDED, | 132 chrome::NOTIFICATION_PROFILE_ADDED, |
| 133 content::NotificationService::AllBrowserContextsAndSources()); | 133 content::NotificationService::AllBrowserContextsAndSources()); |
| 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 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
| 138 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
| 139 content::NotificationService::AllBrowserContextsAndSources()); | |
| 140 RebuildNotifierGroups(); | 138 RebuildNotifierGroups(); |
| 141 | 139 |
| 142 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
| 143 // UserManager may not exist in some tests. | 141 // UserManager may not exist in some tests. |
| 144 if (user_manager::UserManager::IsInitialized()) | 142 if (user_manager::UserManager::IsInitialized()) |
| 145 user_manager::UserManager::Get()->AddSessionStateObserver(this); | 143 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
| 146 #endif | 144 #endif |
| 147 } | 145 } |
| 148 | 146 |
| 149 MessageCenterSettingsController::~MessageCenterSettingsController() { | 147 MessageCenterSettingsController::~MessageCenterSettingsController() { |
| 148 g_browser_process->profile_manager()-> | |
| 149 GetProfileInfoCache().RemoveObserver(this); | |
| 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 (user_manager::UserManager::IsInitialized()) | 152 if (user_manager::UserManager::IsInitialized()) |
| 153 user_manager::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); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 content::Source<Profile>(source).ptr()->IsOffTheRecord()) { | 425 content::Source<Profile>(source).ptr()->IsOffTheRecord()) { |
| 426 return; | 426 return; |
| 427 } | 427 } |
| 428 | 428 |
| 429 RebuildNotifierGroups(); | 429 RebuildNotifierGroups(); |
| 430 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 430 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
| 431 observers_, | 431 observers_, |
| 432 NotifierGroupChanged()); | 432 NotifierGroupChanged()); |
| 433 } | 433 } |
| 434 | 434 |
| 435 void MessageCenterSettingsController::OnProfileAdded( | |
| 436 const base::FilePath& profile_path) { | |
| 437 RebuildNotifierGroups(); | |
|
Cait (Slow)
2015/02/06 16:47:22
This pattern (Rebuild & Notify Observers) seems to
noms (inactive)
2015/02/12 21:46:02
Done.
| |
| 438 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | |
| 439 observers_, | |
| 440 NotifierGroupChanged()); | |
| 441 } | |
| 442 void MessageCenterSettingsController::OnProfileWasRemoved( | |
| 443 const base::FilePath& profile_path, | |
| 444 const base::string16& profile_name) { | |
| 445 RebuildNotifierGroups(); | |
| 446 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | |
| 447 observers_, | |
| 448 NotifierGroupChanged()); | |
| 449 } | |
| 450 void MessageCenterSettingsController::OnProfileNameChanged( | |
| 451 const base::FilePath& profile_path, | |
| 452 const base::string16& old_profile_name) { | |
| 453 RebuildNotifierGroups(); | |
| 454 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | |
| 455 observers_, | |
| 456 NotifierGroupChanged()); | |
| 457 } | |
| 458 void MessageCenterSettingsController::OnProfileUserNameChanged( | |
| 459 const base::FilePath& profile_path) { | |
| 460 RebuildNotifierGroups(); | |
| 461 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | |
| 462 observers_, | |
| 463 NotifierGroupChanged()); | |
| 464 } | |
| 465 | |
| 435 #if defined(OS_CHROMEOS) | 466 #if defined(OS_CHROMEOS) |
| 436 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { | 467 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { |
| 437 // Already created. | 468 // Already created. |
| 438 if (!notifier_groups_.empty()) | 469 if (!notifier_groups_.empty()) |
| 439 return; | 470 return; |
| 440 | 471 |
| 441 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 472 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 442 // |notifier_groups_| can be empty in login screen too. | 473 // |notifier_groups_| can be empty in login screen too. |
| 443 if (!user_manager->IsLoggedInAsGuest()) | 474 if (!user_manager->IsLoggedInAsGuest()) |
| 444 return; | 475 return; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 458 observers_, | 489 observers_, |
| 459 NotifierGroupChanged()); | 490 NotifierGroupChanged()); |
| 460 } | 491 } |
| 461 #endif | 492 #endif |
| 462 | 493 |
| 463 void MessageCenterSettingsController::RebuildNotifierGroups() { | 494 void MessageCenterSettingsController::RebuildNotifierGroups() { |
| 464 notifier_groups_.clear(); | 495 notifier_groups_.clear(); |
| 465 current_notifier_group_ = 0; | 496 current_notifier_group_ = 0; |
| 466 | 497 |
| 467 const size_t count = profile_info_cache_->GetNumberOfProfiles(); | 498 const size_t count = profile_info_cache_->GetNumberOfProfiles(); |
| 468 | |
| 469 for (size_t i = 0; i < count; ++i) { | 499 for (size_t i = 0; i < count; ++i) { |
| 470 scoped_ptr<message_center::ProfileNotifierGroup> group( | 500 scoped_ptr<message_center::ProfileNotifierGroup> group( |
| 471 new message_center::ProfileNotifierGroup( | 501 new message_center::ProfileNotifierGroup( |
| 472 profile_info_cache_->GetAvatarIconOfProfileAtIndex(i), | 502 profile_info_cache_->GetAvatarIconOfProfileAtIndex(i), |
| 473 profile_info_cache_->GetNameOfProfileAtIndex(i), | 503 profile_info_cache_->GetNameOfProfileAtIndex(i), |
| 474 profile_info_cache_->GetUserNameOfProfileAtIndex(i), | 504 profile_info_cache_->GetUserNameOfProfileAtIndex(i), |
| 475 i, | 505 i, |
| 476 profile_info_cache_->GetPathOfProfileAtIndex(i))); | 506 profile_info_cache_->GetPathOfProfileAtIndex(i))); |
| 477 if (group->profile() == NULL) | 507 if (group->profile() == NULL) |
| 478 continue; | 508 continue; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 // another creating a primary profile, and causes an infinite loop. | 541 // another creating a primary profile, and causes an infinite loop. |
| 512 // Thus, it would be better to delay creating group for guest login. | 542 // Thus, it would be better to delay creating group for guest login. |
| 513 base::MessageLoopProxy::current()->PostTask( | 543 base::MessageLoopProxy::current()->PostTask( |
| 514 FROM_HERE, | 544 FROM_HERE, |
| 515 base::Bind( | 545 base::Bind( |
| 516 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, | 546 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, |
| 517 weak_factory_.GetWeakPtr())); | 547 weak_factory_.GetWeakPtr())); |
| 518 } | 548 } |
| 519 #endif | 549 #endif |
| 520 } | 550 } |
| OLD | NEW |