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

Side by Side Diff: chrome/browser/profiles/profile_info_cache.cc

Issue 8785006: Badge Windows profile shortcuts with multi-user avatar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/profiles/profile_info_cache.h" 5 #include "chrome/browser/profiles/profile_info_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 scoped_ptr<DictionaryValue> info(new DictionaryValue); 198 scoped_ptr<DictionaryValue> info(new DictionaryValue);
199 info->SetString(kNameKey, name); 199 info->SetString(kNameKey, name);
200 info->SetString(kUserNameKey, username); 200 info->SetString(kUserNameKey, username);
201 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); 201 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index));
202 // Default value for whether background apps are running is false. 202 // Default value for whether background apps are running is false.
203 info->SetBoolean(kBackgroundAppsKey, false); 203 info->SetBoolean(kBackgroundAppsKey, false);
204 cache->Set(key, info.release()); 204 cache->Set(key, info.release());
205 205
206 sorted_keys_.insert(FindPositionForProfile(key, name), key); 206 sorted_keys_.insert(FindPositionForProfile(key, name), key);
207 207
208 gfx::Image& avatar_img = ResourceBundle::GetSharedInstance().GetImageNamed(
209 GetDefaultAvatarIconResourceIDAtIndex(icon_index));
210
208 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, 211 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
209 observer_list_, 212 observer_list_,
210 OnProfileAdded(name, UTF8ToUTF16(key))); 213 OnProfileAdded(name, UTF8ToUTF16(key), profile_path.value(),
214 &avatar_img));
211 215
212 content::NotificationService::current()->Notify( 216 content::NotificationService::current()->Notify(
213 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 217 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
214 content::NotificationService::AllSources(), 218 content::NotificationService::AllSources(),
215 content::NotificationService::NoDetails()); 219 content::NotificationService::NoDetails());
216 } 220 }
217 221
218 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { 222 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) {
219 observer_list_.AddObserver(obs); 223 observer_list_.AddObserver(obs);
220 } 224 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 422
419 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); 423 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
420 info->SetString(kUserNameKey, user_name); 424 info->SetString(kUserNameKey, user_name);
421 // This takes ownership of |info|. 425 // This takes ownership of |info|.
422 SetInfoForProfileAtIndex(index, info.release()); 426 SetInfoForProfileAtIndex(index, info.release());
423 } 427 }
424 428
425 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, 429 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index,
426 size_t icon_index) { 430 size_t icon_index) {
427 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); 431 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
432 string16 name;
433 info->GetString(kNameKey, &name);
428 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); 434 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index));
429 // This takes ownership of |info|. 435 // This takes ownership of |info|.
430 SetInfoForProfileAtIndex(index, info.release()); 436 SetInfoForProfileAtIndex(index, info.release());
437
438 FilePath profile_path = GetPathOfProfileAtIndex(index);
439 std::string key = CacheKeyFromProfilePath(profile_path);
440 gfx::Image& avatar_img = ResourceBundle::GetSharedInstance().GetImageNamed(
441 GetDefaultAvatarIconResourceIDAtIndex(icon_index));
442
443 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
444 observer_list_,
445 OnProfileAvatarChanged(name, UTF8ToUTF16(key),
446 profile_path.value(), &avatar_img));
431 } 447 }
432 448
433 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( 449 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex(
434 size_t index, 450 size_t index,
435 bool running_background_apps) { 451 bool running_background_apps) {
436 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) 452 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps)
437 return; 453 return;
438 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); 454 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
439 info->SetBoolean(kBackgroundAppsKey, running_background_apps); 455 info->SetBoolean(kBackgroundAppsKey, running_background_apps);
440 // This takes ownership of |info|. 456 // This takes ownership of |info|.
(...skipping 11 matching lines...) Expand all
452 SetInfoForProfileAtIndex(index, info.release()); 468 SetInfoForProfileAtIndex(index, info.release());
453 UpdateSortForProfileIndex(index); 469 UpdateSortForProfileIndex(index);
454 } 470 }
455 471
456 void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index, 472 void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index,
457 bool value) { 473 bool value) {
458 if (value == IsUsingGAIANameOfProfileAtIndex(index)) 474 if (value == IsUsingGAIANameOfProfileAtIndex(index))
459 return; 475 return;
460 476
461 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); 477 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
478 // If |value| is true, then the old name is still in the cache. Pull it out if
479 // we are going to update our observers with it.
480 string16 old_name;
481 if (value)
482 info->GetString(kNameKey, &old_name);
462 info->SetBoolean(kUseGAIANameKey, value); 483 info->SetBoolean(kUseGAIANameKey, value);
463 // This takes ownership of |info|. 484 // This takes ownership of |info|.
464 SetInfoForProfileAtIndex(index, info.release()); 485 SetInfoForProfileAtIndex(index, info.release());
465 UpdateSortForProfileIndex(index); 486 UpdateSortForProfileIndex(index);
487
488 if (value) {
489 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
490 observer_list_,
491 OnProfileNameChanged(old_name,
492 GetGAIANameOfProfileAtIndex(index)));
493 }
466 } 494 }
467 495
468 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, 496 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index,
469 const gfx::Image* image) { 497 const gfx::Image* image) {
470 FilePath path = GetPathOfProfileAtIndex(index); 498 FilePath path = GetPathOfProfileAtIndex(index);
471 std::string key = CacheKeyFromProfilePath(path); 499 std::string key = CacheKeyFromProfilePath(path);
472 500
473 // Delete the old bitmap from cache. 501 // Delete the old bitmap from cache.
474 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key); 502 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key);
475 if (it != gaia_pictures_.end()) { 503 if (it != gaia_pictures_.end()) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 537
510 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); 538 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
511 info->SetString(kGAIAPictureFileNameKey, new_file_name); 539 info->SetString(kGAIAPictureFileNameKey, new_file_name);
512 // This takes ownership of |info|. 540 // This takes ownership of |info|.
513 SetInfoForProfileAtIndex(index, info.release()); 541 SetInfoForProfileAtIndex(index, info.release());
514 } 542 }
515 543
516 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, 544 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index,
517 bool value) { 545 bool value) {
518 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); 546 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
547 string16 name;
548 info->GetString(kNameKey, &name);
519 info->SetBoolean(kUseGAIAPictureKey, value); 549 info->SetBoolean(kUseGAIAPictureKey, value);
520 // This takes ownership of |info|. 550 // This takes ownership of |info|.
521 SetInfoForProfileAtIndex(index, info.release()); 551 SetInfoForProfileAtIndex(index, info.release());
552
553 // Retrieve some info to update observers who care about avatar changes.
554 if (value) {
555 FilePath profile_path = GetPathOfProfileAtIndex(index);
556 std::string key = CacheKeyFromProfilePath(profile_path);
557 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
558 observer_list_,
559 OnProfileAvatarChanged(name, UTF8ToUTF16(key),
560 profile_path.value(),
561 gaia_pictures_[key]));
562 }
522 } 563 }
523 564
524 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) { 565 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) {
525 string16 name; 566 string16 name;
526 for (int name_index = 1; ; ++name_index) { 567 for (int name_index = 1; ; ++name_index) {
527 if (icon_index < kGenericIconCount) { 568 if (icon_index < kGenericIconCount) {
528 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, 569 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME,
529 name_index); 570 name_index);
530 } else { 571 } else {
531 name = l10n_util::GetStringUTF16( 572 name = l10n_util::GetStringUTF16(
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 info->GetString(kNameKey, &name); 769 info->GetString(kNameKey, &name);
729 names.push_back(name); 770 names.push_back(name);
730 } 771 }
731 return names; 772 return names;
732 } 773 }
733 774
734 // static 775 // static
735 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { 776 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) {
736 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); 777 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache);
737 } 778 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698