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

Side by Side Diff: chrome/browser/notifications/message_center_settings_controller.cc

Issue 895803003: [Profiles] Remove the NotificationService from the ProfileInfoCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: maybe fix NTPLoginHandler tests Created 5 years, 10 months 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 (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
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, 138 RebuildNotifierGroups(false);
139 content::NotificationService::AllBrowserContextsAndSources());
140 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 const favicon_base::FaviconImageResult& favicon_result) { 396 const favicon_base::FaviconImageResult& favicon_result) {
397 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 397 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
398 observers_, 398 observers_,
399 UpdateIconImage(NotifierId(url), favicon_result.image)); 399 UpdateIconImage(NotifierId(url), favicon_result.image));
400 } 400 }
401 401
402 402
403 #if defined(OS_CHROMEOS) 403 #if defined(OS_CHROMEOS)
404 void MessageCenterSettingsController::ActiveUserChanged( 404 void MessageCenterSettingsController::ActiveUserChanged(
405 const user_manager::User* active_user) { 405 const user_manager::User* active_user) {
406 RebuildNotifierGroups(); 406 RebuildNotifierGroups(false);
407 } 407 }
408 #endif 408 #endif
409 409
410 void MessageCenterSettingsController::SetAppImage(const std::string& id, 410 void MessageCenterSettingsController::SetAppImage(const std::string& id,
411 const gfx::ImageSkia& image) { 411 const gfx::ImageSkia& image) {
412 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 412 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
413 observers_, 413 observers_,
414 UpdateIconImage(NotifierId(NotifierId::APPLICATION, id), 414 UpdateIconImage(NotifierId(NotifierId::APPLICATION, id),
415 gfx::Image(image))); 415 gfx::Image(image)));
416 } 416 }
417 417
418 void MessageCenterSettingsController::Observe( 418 void MessageCenterSettingsController::Observe(
419 int type, 419 int type,
420 const content::NotificationSource& source, 420 const content::NotificationSource& source,
421 const content::NotificationDetails& details) { 421 const content::NotificationDetails& details) {
422 // GetOffTheRecordProfile() may create a new off-the-record profile, but that 422 // GetOffTheRecordProfile() may create a new off-the-record profile, but that
423 // doesn't need to rebuild the groups. 423 // doesn't need to rebuild the groups.
424 if (type == chrome::NOTIFICATION_PROFILE_CREATED && 424 if (type == chrome::NOTIFICATION_PROFILE_CREATED &&
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(true);
430 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 430 }
431 observers_, 431
432 NotifierGroupChanged()); 432 void MessageCenterSettingsController::OnProfileAdded(
433 const base::FilePath& profile_path) {
434 RebuildNotifierGroups(true);
435 }
436 void MessageCenterSettingsController::OnProfileWasRemoved(
437 const base::FilePath& profile_path,
438 const base::string16& profile_name) {
439 RebuildNotifierGroups(true);
440 }
441 void MessageCenterSettingsController::OnProfileNameChanged(
442 const base::FilePath& profile_path,
443 const base::string16& old_profile_name) {
444 RebuildNotifierGroups(true);
445 }
446 void MessageCenterSettingsController::OnProfileUserNameChanged(
447 const base::FilePath& profile_path) {
448 RebuildNotifierGroups(true);
433 } 449 }
434 450
435 #if defined(OS_CHROMEOS) 451 #if defined(OS_CHROMEOS)
436 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { 452 void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() {
437 // Already created. 453 // Already created.
438 if (!notifier_groups_.empty()) 454 if (!notifier_groups_.empty())
439 return; 455 return;
440 456
441 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 457 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
442 // |notifier_groups_| can be empty in login screen too. 458 // |notifier_groups_| can be empty in login screen too.
(...skipping 10 matching lines...) Expand all
453 user->GetDisplayName(), 469 user->GetDisplayName(),
454 0, 470 0,
455 profile)); 471 profile));
456 472
457 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 473 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
458 observers_, 474 observers_,
459 NotifierGroupChanged()); 475 NotifierGroupChanged());
460 } 476 }
461 #endif 477 #endif
462 478
463 void MessageCenterSettingsController::RebuildNotifierGroups() { 479 void MessageCenterSettingsController::RebuildNotifierGroups(bool notify) {
464 notifier_groups_.clear(); 480 notifier_groups_.clear();
465 current_notifier_group_ = 0; 481 current_notifier_group_ = 0;
466 482
467 const size_t count = profile_info_cache_->GetNumberOfProfiles(); 483 const size_t count = profile_info_cache_->GetNumberOfProfiles();
468
469 for (size_t i = 0; i < count; ++i) { 484 for (size_t i = 0; i < count; ++i) {
470 scoped_ptr<message_center::ProfileNotifierGroup> group( 485 scoped_ptr<message_center::ProfileNotifierGroup> group(
471 new message_center::ProfileNotifierGroup( 486 new message_center::ProfileNotifierGroup(
472 profile_info_cache_->GetAvatarIconOfProfileAtIndex(i), 487 profile_info_cache_->GetAvatarIconOfProfileAtIndex(i),
473 profile_info_cache_->GetNameOfProfileAtIndex(i), 488 profile_info_cache_->GetNameOfProfileAtIndex(i),
474 profile_info_cache_->GetUserNameOfProfileAtIndex(i), 489 profile_info_cache_->GetUserNameOfProfileAtIndex(i),
475 i, 490 i,
476 profile_info_cache_->GetPathOfProfileAtIndex(i))); 491 profile_info_cache_->GetPathOfProfileAtIndex(i)));
477 if (group->profile() == NULL) 492 if (group->profile() == NULL)
478 continue; 493 continue;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 // registering it as the primary one, which causes this method which causes 525 // registering it as the primary one, which causes this method which causes
511 // another creating a primary profile, and causes an infinite loop. 526 // another creating a primary profile, and causes an infinite loop.
512 // Thus, it would be better to delay creating group for guest login. 527 // Thus, it would be better to delay creating group for guest login.
513 base::MessageLoopProxy::current()->PostTask( 528 base::MessageLoopProxy::current()->PostTask(
514 FROM_HERE, 529 FROM_HERE,
515 base::Bind( 530 base::Bind(
516 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, 531 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin,
517 weak_factory_.GetWeakPtr())); 532 weak_factory_.GetWeakPtr()));
518 } 533 }
519 #endif 534 #endif
535
536 if (notify) {
537 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
538 observers_,
539 NotifierGroupChanged());
540 }
520 } 541 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698