| 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( |
| 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.value(), |
| 215 &avatar_img)); |
| 211 | 216 |
| 212 content::NotificationService::current()->Notify( | 217 content::NotificationService::current()->Notify( |
| 213 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 218 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 214 content::NotificationService::AllSources(), | 219 content::NotificationService::AllSources(), |
| 215 content::NotificationService::NoDetails()); | 220 content::NotificationService::NoDetails()); |
| 216 } | 221 } |
| 217 | 222 |
| 218 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { | 223 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { |
| 219 observer_list_.AddObserver(obs); | 224 observer_list_.AddObserver(obs); |
| 220 } | 225 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 423 |
| 419 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 424 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 420 info->SetString(kUserNameKey, user_name); | 425 info->SetString(kUserNameKey, user_name); |
| 421 // This takes ownership of |info|. | 426 // This takes ownership of |info|. |
| 422 SetInfoForProfileAtIndex(index, info.release()); | 427 SetInfoForProfileAtIndex(index, info.release()); |
| 423 } | 428 } |
| 424 | 429 |
| 425 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, | 430 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, |
| 426 size_t icon_index) { | 431 size_t icon_index) { |
| 427 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 432 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 433 string16 name; |
| 434 info->GetString(kNameKey, &name); |
| 428 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); | 435 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); |
| 429 // This takes ownership of |info|. | 436 // This takes ownership of |info|. |
| 430 SetInfoForProfileAtIndex(index, info.release()); | 437 SetInfoForProfileAtIndex(index, info.release()); |
| 438 |
| 439 FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 440 std::string key = CacheKeyFromProfilePath(profile_path); |
| 441 gfx::Image& avatar_img = ResourceBundle::GetSharedInstance().GetImageNamed( |
| 442 GetDefaultAvatarIconResourceIDAtIndex(icon_index)); |
| 443 |
| 444 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 445 observer_list_, |
| 446 OnProfileAvatarChanged(name, UTF8ToUTF16(key), |
| 447 profile_path.value(), |
| 448 &avatar_img)); |
| 431 } | 449 } |
| 432 | 450 |
| 433 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( | 451 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( |
| 434 size_t index, | 452 size_t index, |
| 435 bool running_background_apps) { | 453 bool running_background_apps) { |
| 436 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) | 454 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) |
| 437 return; | 455 return; |
| 438 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 456 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 439 info->SetBoolean(kBackgroundAppsKey, running_background_apps); | 457 info->SetBoolean(kBackgroundAppsKey, running_background_apps); |
| 440 // This takes ownership of |info|. | 458 // This takes ownership of |info|. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 527 |
| 510 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 528 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 511 info->SetString(kGAIAPictureFileNameKey, new_file_name); | 529 info->SetString(kGAIAPictureFileNameKey, new_file_name); |
| 512 // This takes ownership of |info|. | 530 // This takes ownership of |info|. |
| 513 SetInfoForProfileAtIndex(index, info.release()); | 531 SetInfoForProfileAtIndex(index, info.release()); |
| 514 } | 532 } |
| 515 | 533 |
| 516 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, | 534 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, |
| 517 bool value) { | 535 bool value) { |
| 518 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 536 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 537 string16 name; |
| 538 info->GetString(kNameKey, &name); |
| 519 info->SetBoolean(kUseGAIAPictureKey, value); | 539 info->SetBoolean(kUseGAIAPictureKey, value); |
| 520 // This takes ownership of |info|. | 540 // This takes ownership of |info|. |
| 521 SetInfoForProfileAtIndex(index, info.release()); | 541 SetInfoForProfileAtIndex(index, info.release()); |
| 542 |
| 543 // Retrieve some info to update observers who care about avatar changes. |
| 544 if (value) { |
| 545 FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 546 std::string key = CacheKeyFromProfilePath(profile_path); |
| 547 |
| 548 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 549 observer_list_, |
| 550 OnProfileAvatarChanged(name, UTF8ToUTF16(key), |
| 551 profile_path.value(), |
| 552 gaia_pictures_[key])); |
| 553 } |
| 522 } | 554 } |
| 523 | 555 |
| 524 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) { | 556 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) { |
| 525 string16 name; | 557 string16 name; |
| 526 for (int name_index = 1; ; ++name_index) { | 558 for (int name_index = 1; ; ++name_index) { |
| 527 if (icon_index < kGenericIconCount) { | 559 if (icon_index < kGenericIconCount) { |
| 528 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, | 560 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, |
| 529 name_index); | 561 name_index); |
| 530 } else { | 562 } else { |
| 531 name = l10n_util::GetStringUTF16( | 563 name = l10n_util::GetStringUTF16( |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 info->GetString(kNameKey, &name); | 760 info->GetString(kNameKey, &name); |
| 729 names.push_back(name); | 761 names.push_back(name); |
| 730 } | 762 } |
| 731 return names; | 763 return names; |
| 732 } | 764 } |
| 733 | 765 |
| 734 // static | 766 // static |
| 735 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { | 767 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { |
| 736 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); | 768 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); |
| 737 } | 769 } |
| OLD | NEW |