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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 | 222 |
223 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { | 223 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { |
224 observer_list_.AddObserver(obs); | 224 observer_list_.AddObserver(obs); |
225 } | 225 } |
226 | 226 |
227 void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) { | 227 void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) { |
228 observer_list_.RemoveObserver(obs); | 228 observer_list_.RemoveObserver(obs); |
229 } | 229 } |
230 | 230 |
231 void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) { | 231 void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) { |
232 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 232 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
sail
2011/12/09 18:24:22
can the next three lines be moved after the FOR_EA
SteveT
2011/12/09 18:37:56
Rearranged the code here to be grouped more sensib
| |
233 DictionaryValue* cache = update.Get(); | 233 DictionaryValue* cache = update.Get(); |
234 | 234 |
235 std::string key = CacheKeyFromProfilePath(profile_path); | 235 std::string key = CacheKeyFromProfilePath(profile_path); |
236 DictionaryValue* info = NULL; | 236 DictionaryValue* info = NULL; |
sail
2011/12/09 18:24:22
do you still need this?
SteveT
2011/12/09 18:37:56
No, nor do I need |index| below. That was a bit ca
| |
237 cache->GetDictionary(key, &info); | 237 cache->GetDictionary(key, &info); |
238 string16 name; | 238 string16 name = GetNameOfProfileAtIndex( |
239 info->GetString(kNameKey, &name); | 239 GetIndexOfProfileWithPath(profile_path)); |
240 size_t index = GetIndexOfProfileWithPath(profile_path); | |
240 | 241 |
241 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 242 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
242 observer_list_, | 243 observer_list_, |
243 OnProfileRemoved(name)); | 244 OnProfileRemoved(name)); |
244 | 245 |
245 cache->Remove(key, NULL); | 246 cache->Remove(key, NULL); |
246 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); | 247 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); |
247 | 248 |
248 content::NotificationService::current()->Notify( | 249 content::NotificationService::current()->Notify( |
249 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 250 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; | 398 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; |
398 return GetDefaultAvatarIconResourceIDAtIndex(0); | 399 return GetDefaultAvatarIconResourceIDAtIndex(0); |
399 } | 400 } |
400 | 401 |
401 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, | 402 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, |
402 const string16& name) { | 403 const string16& name) { |
403 if (name == GetNameOfProfileAtIndex(index)) | 404 if (name == GetNameOfProfileAtIndex(index)) |
404 return; | 405 return; |
405 | 406 |
406 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 407 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
407 string16 old_name; | 408 string16 old_name = GetNameOfProfileAtIndex(index); |
408 info->GetString(kNameKey, &old_name); | |
409 info->SetString(kNameKey, name); | 409 info->SetString(kNameKey, name); |
410 // This takes ownership of |info|. | 410 // This takes ownership of |info|. |
411 SetInfoForProfileAtIndex(index, info.release()); | 411 SetInfoForProfileAtIndex(index, info.release()); |
412 UpdateSortForProfileIndex(index); | 412 UpdateSortForProfileIndex(index); |
413 | 413 |
414 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 414 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
415 observer_list_, | 415 observer_list_, |
416 OnProfileNameChanged(old_name, name)); | 416 OnProfileNameChanged(old_name, name)); |
417 } | 417 } |
418 | 418 |
419 void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index, | 419 void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index, |
420 const string16& user_name) { | 420 const string16& user_name) { |
421 if (user_name == GetUserNameOfProfileAtIndex(index)) | 421 if (user_name == GetUserNameOfProfileAtIndex(index)) |
422 return; | 422 return; |
423 | 423 |
424 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 424 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
425 info->SetString(kUserNameKey, user_name); | 425 info->SetString(kUserNameKey, user_name); |
426 // This takes ownership of |info|. | 426 // This takes ownership of |info|. |
427 SetInfoForProfileAtIndex(index, info.release()); | 427 SetInfoForProfileAtIndex(index, info.release()); |
428 } | 428 } |
429 | 429 |
430 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, | 430 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, |
431 size_t icon_index) { | 431 size_t icon_index) { |
432 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 432 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
433 string16 name; | |
434 info->GetString(kNameKey, &name); | |
435 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); | 433 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); |
436 // This takes ownership of |info|. | 434 // This takes ownership of |info|. |
437 SetInfoForProfileAtIndex(index, info.release()); | 435 SetInfoForProfileAtIndex(index, info.release()); |
438 | 436 |
437 string16 name = GetNameOfProfileAtIndex(index); | |
439 FilePath profile_path = GetPathOfProfileAtIndex(index); | 438 FilePath profile_path = GetPathOfProfileAtIndex(index); |
440 std::string key = CacheKeyFromProfilePath(profile_path); | 439 std::string key = CacheKeyFromProfilePath(profile_path); |
441 gfx::Image& avatar_img = | 440 gfx::Image& avatar_img = |
442 ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 441 ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
443 GetDefaultAvatarIconResourceIDAtIndex(icon_index)); | 442 GetDefaultAvatarIconResourceIDAtIndex(icon_index)); |
444 | 443 |
445 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 444 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
446 observer_list_, | 445 observer_list_, |
447 OnProfileAvatarChanged(name, UTF8ToUTF16(key), | 446 OnProfileAvatarChanged(name, UTF8ToUTF16(key), |
448 profile_path, &avatar_img)); | 447 profile_path, &avatar_img)); |
(...skipping 21 matching lines...) Expand all Loading... | |
470 SetInfoForProfileAtIndex(index, info.release()); | 469 SetInfoForProfileAtIndex(index, info.release()); |
471 UpdateSortForProfileIndex(index); | 470 UpdateSortForProfileIndex(index); |
472 } | 471 } |
473 | 472 |
474 void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index, | 473 void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index, |
475 bool value) { | 474 bool value) { |
476 if (value == IsUsingGAIANameOfProfileAtIndex(index)) | 475 if (value == IsUsingGAIANameOfProfileAtIndex(index)) |
477 return; | 476 return; |
478 | 477 |
479 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 478 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
479 string16 old_name; | |
480 info->GetString(kNameKey, &old_name); | |
480 info->SetBoolean(kUseGAIANameKey, value); | 481 info->SetBoolean(kUseGAIANameKey, value); |
481 // This takes ownership of |info|. | 482 // This takes ownership of |info|. |
482 SetInfoForProfileAtIndex(index, info.release()); | 483 SetInfoForProfileAtIndex(index, info.release()); |
484 string16 new_name = GetGAIANameOfProfileAtIndex(index); | |
483 UpdateSortForProfileIndex(index); | 485 UpdateSortForProfileIndex(index); |
486 | |
487 if (value) { | |
488 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | |
489 observer_list_, | |
490 OnProfileNameChanged(old_name, new_name)); | |
491 } | |
484 } | 492 } |
485 | 493 |
486 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, | 494 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, |
487 const gfx::Image* image) { | 495 const gfx::Image* image) { |
488 FilePath path = GetPathOfProfileAtIndex(index); | 496 FilePath path = GetPathOfProfileAtIndex(index); |
489 std::string key = CacheKeyFromProfilePath(path); | 497 std::string key = CacheKeyFromProfilePath(path); |
490 | 498 |
491 // Delete the old bitmap from cache. | 499 // Delete the old bitmap from cache. |
492 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key); | 500 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key); |
493 if (it != gaia_pictures_.end()) { | 501 if (it != gaia_pictures_.end()) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 | 535 |
528 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 536 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
529 info->SetString(kGAIAPictureFileNameKey, new_file_name); | 537 info->SetString(kGAIAPictureFileNameKey, new_file_name); |
530 // This takes ownership of |info|. | 538 // This takes ownership of |info|. |
531 SetInfoForProfileAtIndex(index, info.release()); | 539 SetInfoForProfileAtIndex(index, info.release()); |
532 } | 540 } |
533 | 541 |
534 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, | 542 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, |
535 bool value) { | 543 bool value) { |
536 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 544 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
537 string16 name; | 545 string16 name = GetNameOfProfileAtIndex(index); |
538 info->GetString(kNameKey, &name); | |
539 info->SetBoolean(kUseGAIAPictureKey, value); | 546 info->SetBoolean(kUseGAIAPictureKey, value); |
540 // This takes ownership of |info|. | 547 // This takes ownership of |info|. |
541 SetInfoForProfileAtIndex(index, info.release()); | 548 SetInfoForProfileAtIndex(index, info.release()); |
542 | 549 |
543 // Retrieve some info to update observers who care about avatar changes. | 550 // Retrieve some info to update observers who care about avatar changes. |
544 if (value) { | 551 if (value) { |
545 FilePath profile_path = GetPathOfProfileAtIndex(index); | 552 FilePath profile_path = GetPathOfProfileAtIndex(index); |
546 std::string key = CacheKeyFromProfilePath(profile_path); | 553 std::string key = CacheKeyFromProfilePath(profile_path); |
547 if (gaia_pictures_.find(key) != gaia_pictures_.end()) { | 554 if (gaia_pictures_.find(key) != gaia_pictures_.end()) { |
548 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 555 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 info->GetString(kNameKey, &name); | 768 info->GetString(kNameKey, &name); |
762 names.push_back(name); | 769 names.push_back(name); |
763 } | 770 } |
764 return names; | 771 return names; |
765 } | 772 } |
766 | 773 |
767 // static | 774 // static |
768 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { | 775 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { |
769 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); | 776 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); |
770 } | 777 } |
OLD | NEW |