OLD | NEW |
---|---|
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 Loading... | |
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( | |
Robert Sesek
2011/12/05 18:03:28
GetNativeImageNamed()
SteveT
2011/12/05 20:33:17
Done.
| |
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), |
214 profile_path, &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 Loading... | |
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( | |
Robert Sesek
2011/12/05 18:03:28
here too
SteveT
2011/12/05 20:33:17
Done.
| |
441 GetDefaultAvatarIconResourceIDAtIndex(icon_index)); | |
442 | |
443 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | |
444 observer_list_, | |
445 OnProfileAvatarChanged(name, UTF8ToUTF16(key), | |
446 profile_path, &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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 | 525 |
510 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 526 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
511 info->SetString(kGAIAPictureFileNameKey, new_file_name); | 527 info->SetString(kGAIAPictureFileNameKey, new_file_name); |
512 // This takes ownership of |info|. | 528 // This takes ownership of |info|. |
513 SetInfoForProfileAtIndex(index, info.release()); | 529 SetInfoForProfileAtIndex(index, info.release()); |
514 } | 530 } |
515 | 531 |
516 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, | 532 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, |
517 bool value) { | 533 bool value) { |
518 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 534 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
535 string16 name; | |
536 info->GetString(kNameKey, &name); | |
519 info->SetBoolean(kUseGAIAPictureKey, value); | 537 info->SetBoolean(kUseGAIAPictureKey, value); |
520 // This takes ownership of |info|. | 538 // This takes ownership of |info|. |
521 SetInfoForProfileAtIndex(index, info.release()); | 539 SetInfoForProfileAtIndex(index, info.release()); |
540 | |
541 // Retrieve some info to update observers who care about avatar changes. | |
542 if (value) { | |
543 FilePath profile_path = GetPathOfProfileAtIndex(index); | |
544 std::string key = CacheKeyFromProfilePath(profile_path); | |
545 | |
546 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | |
547 observer_list_, | |
548 OnProfileAvatarChanged(name, UTF8ToUTF16(key), | |
549 profile_path, | |
550 gaia_pictures_[key])); | |
551 } | |
522 } | 552 } |
523 | 553 |
524 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) { | 554 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) { |
525 string16 name; | 555 string16 name; |
526 for (int name_index = 1; ; ++name_index) { | 556 for (int name_index = 1; ; ++name_index) { |
527 if (icon_index < kGenericIconCount) { | 557 if (icon_index < kGenericIconCount) { |
528 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, | 558 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, |
529 name_index); | 559 name_index); |
530 } else { | 560 } else { |
531 name = l10n_util::GetStringUTF16( | 561 name = l10n_util::GetStringUTF16( |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 info->GetString(kNameKey, &name); | 758 info->GetString(kNameKey, &name); |
729 names.push_back(name); | 759 names.push_back(name); |
730 } | 760 } |
731 return names; | 761 return names; |
732 } | 762 } |
733 | 763 |
734 // static | 764 // static |
735 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { | 765 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { |
736 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); | 766 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); |
737 } | 767 } |
OLD | NEW |