| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 scoped_ptr<DictionaryValue> info(new DictionaryValue); | 199 scoped_ptr<DictionaryValue> info(new DictionaryValue); |
| 200 info->SetString(kNameKey, name); | 200 info->SetString(kNameKey, name); |
| 201 info->SetString(kUserNameKey, username); | 201 info->SetString(kUserNameKey, username); |
| 202 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); | 202 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); |
| 203 // Default value for whether background apps are running is false. | 203 // Default value for whether background apps are running is false. |
| 204 info->SetBoolean(kBackgroundAppsKey, false); | 204 info->SetBoolean(kBackgroundAppsKey, false); |
| 205 cache->Set(key, info.release()); | 205 cache->Set(key, info.release()); |
| 206 | 206 |
| 207 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 207 sorted_keys_.insert(FindPositionForProfile(key, name), key); |
| 208 | 208 |
| 209 gfx::Image& avatar_img = | |
| 210 ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 211 GetDefaultAvatarIconResourceIDAtIndex(icon_index)); | |
| 212 | |
| 213 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 209 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 214 observer_list_, | 210 observer_list_, |
| 215 OnProfileAdded(name, UTF8ToUTF16(key), | 211 OnProfileAdded(profile_path, UTF8ToUTF16(key))); |
| 216 profile_path, &avatar_img)); | |
| 217 | 212 |
| 218 content::NotificationService::current()->Notify( | 213 content::NotificationService::current()->Notify( |
| 219 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 214 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 220 content::NotificationService::AllSources(), | 215 content::NotificationService::AllSources(), |
| 221 content::NotificationService::NoDetails()); | 216 content::NotificationService::NoDetails()); |
| 222 } | 217 } |
| 223 | 218 |
| 224 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { | 219 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { |
| 225 observer_list_.AddObserver(obs); | 220 observer_list_.AddObserver(obs); |
| 226 } | 221 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 SetInfoForProfileAtIndex(index, info.release()); | 429 SetInfoForProfileAtIndex(index, info.release()); |
| 435 } | 430 } |
| 436 | 431 |
| 437 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, | 432 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, |
| 438 size_t icon_index) { | 433 size_t icon_index) { |
| 439 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 434 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 440 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); | 435 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); |
| 441 // This takes ownership of |info|. | 436 // This takes ownership of |info|. |
| 442 SetInfoForProfileAtIndex(index, info.release()); | 437 SetInfoForProfileAtIndex(index, info.release()); |
| 443 | 438 |
| 444 string16 name = GetNameOfProfileAtIndex(index); | |
| 445 FilePath profile_path = GetPathOfProfileAtIndex(index); | 439 FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 446 std::string key = CacheKeyFromProfilePath(profile_path); | 440 std::string key = CacheKeyFromProfilePath(profile_path); |
| 447 gfx::Image& avatar_img = | |
| 448 ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 449 GetDefaultAvatarIconResourceIDAtIndex(icon_index)); | |
| 450 | 441 |
| 451 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 442 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 452 observer_list_, | 443 observer_list_, |
| 453 OnProfileAvatarChanged(name, UTF8ToUTF16(key), | 444 OnProfileAvatarChanged(profile_path, UTF8ToUTF16(key))); |
| 454 profile_path, &avatar_img)); | |
| 455 } | 445 } |
| 456 | 446 |
| 457 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( | 447 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( |
| 458 size_t index, | 448 size_t index, |
| 459 bool running_background_apps) { | 449 bool running_background_apps) { |
| 460 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) | 450 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) |
| 461 return; | 451 return; |
| 462 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 452 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 463 info->SetBoolean(kBackgroundAppsKey, running_background_apps); | 453 info->SetBoolean(kBackgroundAppsKey, running_background_apps); |
| 464 // This takes ownership of |info|. | 454 // This takes ownership of |info|. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 base::Bind(&ProfileInfoCache::OnGAIAPictureSaved, AsWeakPtr(), | 535 base::Bind(&ProfileInfoCache::OnGAIAPictureSaved, AsWeakPtr(), |
| 546 path, success)); | 536 path, success)); |
| 547 } | 537 } |
| 548 } | 538 } |
| 549 | 539 |
| 550 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 540 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 551 info->SetString(kGAIAPictureFileNameKey, new_file_name); | 541 info->SetString(kGAIAPictureFileNameKey, new_file_name); |
| 552 // This takes ownership of |info|. | 542 // This takes ownership of |info|. |
| 553 SetInfoForProfileAtIndex(index, info.release()); | 543 SetInfoForProfileAtIndex(index, info.release()); |
| 554 | 544 |
| 555 string16 name = GetNameOfProfileAtIndex(index); | |
| 556 const gfx::Image& avatar_image = GetAvatarIconOfProfileAtIndex(index); | |
| 557 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 545 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 558 observer_list_, | 546 observer_list_, |
| 559 OnProfileAvatarChanged(name, UTF8ToUTF16(key), | 547 OnProfileAvatarChanged(path, UTF8ToUTF16(key))); |
| 560 path, &avatar_image)); | |
| 561 } | 548 } |
| 562 | 549 |
| 563 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, | 550 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, |
| 564 bool value) { | 551 bool value) { |
| 565 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 552 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 566 string16 name = GetNameOfProfileAtIndex(index); | |
| 567 info->SetBoolean(kUseGAIAPictureKey, value); | 553 info->SetBoolean(kUseGAIAPictureKey, value); |
| 568 // This takes ownership of |info|. | 554 // This takes ownership of |info|. |
| 569 SetInfoForProfileAtIndex(index, info.release()); | 555 SetInfoForProfileAtIndex(index, info.release()); |
| 570 | 556 |
| 571 // Retrieve some info to update observers who care about avatar changes. | 557 // Retrieve some info to update observers who care about avatar changes. |
| 572 if (value) { | 558 if (value) { |
| 573 FilePath profile_path = GetPathOfProfileAtIndex(index); | 559 FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 574 std::string key = CacheKeyFromProfilePath(profile_path); | 560 std::string key = CacheKeyFromProfilePath(profile_path); |
| 575 if (gaia_pictures_.find(key) != gaia_pictures_.end()) { | 561 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 576 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 562 observer_list_, |
| 577 observer_list_, | 563 OnProfileAvatarChanged(profile_path, UTF8ToUTF16(key))); |
| 578 OnProfileAvatarChanged(name, UTF8ToUTF16(key), | |
| 579 profile_path, | |
| 580 gaia_pictures_[key])); | |
| 581 } | |
| 582 } | 564 } |
| 583 } | 565 } |
| 584 | 566 |
| 585 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) { | 567 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) { |
| 586 string16 name; | 568 string16 name; |
| 587 for (int name_index = 1; ; ++name_index) { | 569 for (int name_index = 1; ; ++name_index) { |
| 588 if (icon_index < kGenericIconCount) { | 570 if (icon_index < kGenericIconCount) { |
| 589 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, | 571 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, |
| 590 name_index); | 572 name_index); |
| 591 } else { | 573 } else { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 info->GetString(kNameKey, &name); | 777 info->GetString(kNameKey, &name); |
| 796 names.push_back(name); | 778 names.push_back(name); |
| 797 } | 779 } |
| 798 return names; | 780 return names; |
| 799 } | 781 } |
| 800 | 782 |
| 801 // static | 783 // static |
| 802 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { | 784 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { |
| 803 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); | 785 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); |
| 804 } | 786 } |
| OLD | NEW |