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

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

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/prefs/pref_registry_simple.h" 12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/prefs/scoped_user_pref_update.h" 14 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/profiler/scoped_tracker.h" 15 #include "base/profiler/scoped_tracker.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/profiles/profile_avatar_downloader.h" 23 #include "chrome/browser/profiles/profile_avatar_downloader.h"
24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 24 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
25 #include "chrome/browser/profiles/profiles_state.h" 25 #include "chrome/browser/profiles/profiles_state.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "chrome/grit/generated_resources.h" 27 #include "chrome/grit/generated_resources.h"
28 #include "components/signin/core/common/profile_management_switches.h" 28 #include "components/signin/core/common/profile_management_switches.h"
29 #include "components/user_manager/user_id.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/gfx/image/image.h" 33 #include "ui/gfx/image/image.h"
33 #include "ui/gfx/image/image_util.h" 34 #include "ui/gfx/image/image_util.h"
34 35
35 #if defined(ENABLE_SUPERVISED_USERS) 36 #if defined(ENABLE_SUPERVISED_USERS)
36 #include "chrome/browser/supervised_user/supervised_user_constants.h" 37 #include "chrome/browser/supervised_user/supervised_user_constants.h"
37 #endif 38 #endif
38 39
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 avatar_images_downloads_in_progress_.begin(), 195 avatar_images_downloads_in_progress_.begin(),
195 avatar_images_downloads_in_progress_.end()); 196 avatar_images_downloads_in_progress_.end());
196 } 197 }
197 198
198 void ProfileInfoCache::AddProfileToCache( 199 void ProfileInfoCache::AddProfileToCache(
199 const base::FilePath& profile_path, 200 const base::FilePath& profile_path,
200 const base::string16& name, 201 const base::string16& name,
201 const std::string& gaia_id, 202 const std::string& gaia_id,
202 const base::string16& user_name, 203 const base::string16& user_name,
203 size_t icon_index, 204 size_t icon_index,
204 const std::string& supervised_user_id) { 205 const user_manager::UserID& supervised_user_id) {
205 std::string key = CacheKeyFromProfilePath(profile_path); 206 std::string key = CacheKeyFromProfilePath(profile_path);
206 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); 207 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
207 base::DictionaryValue* cache = update.Get(); 208 base::DictionaryValue* cache = update.Get();
208 209
209 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); 210 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue);
210 info->SetString(kNameKey, name); 211 info->SetString(kNameKey, name);
211 info->SetString(kGAIAIdKey, gaia_id); 212 info->SetString(kGAIAIdKey, gaia_id);
212 info->SetString(kUserNameKey, user_name); 213 info->SetString(kUserNameKey, user_name);
213 info->SetString(kAvatarIconKey, 214 info->SetString(kAvatarIconKey,
214 profiles::GetDefaultAvatarIconUrl(icon_index)); 215 profiles::GetDefaultAvatarIconUrl(icon_index));
215 // Default value for whether background apps are running is false. 216 // Default value for whether background apps are running is false.
216 info->SetBoolean(kBackgroundAppsKey, false); 217 info->SetBoolean(kBackgroundAppsKey, false);
217 info->SetString(kSupervisedUserId, supervised_user_id); 218 info->SetString(kSupervisedUserId, supervised_user_id.GetUserEmail());
218 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty()); 219 info->SetBoolean(kIsOmittedFromProfileListKey, !supervised_user_id.empty());
219 info->SetBoolean(kProfileIsEphemeral, false); 220 info->SetBoolean(kProfileIsEphemeral, false);
220 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name)); 221 info->SetBoolean(kIsUsingDefaultNameKey, IsDefaultProfileName(name));
221 // Assume newly created profiles use a default avatar. 222 // Assume newly created profiles use a default avatar.
222 info->SetBoolean(kIsUsingDefaultAvatarKey, true); 223 info->SetBoolean(kIsUsingDefaultAvatarKey, true);
223 cache->SetWithoutPathExpansion(key, info.release()); 224 cache->SetWithoutPathExpansion(key, info.release());
224 225
225 sorted_keys_.insert(FindPositionForProfile(key, name), key); 226 sorted_keys_.insert(FindPositionForProfile(key, name), key);
226 227
227 if (switches::IsNewAvatarMenu() && !disable_avatar_download_for_testing_) 228 if (switches::IsNewAvatarMenu() && !disable_avatar_download_for_testing_)
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 return value; 408 return value;
408 } 409 }
409 410
410 bool ProfileInfoCache::ProfileIsSupervisedAtIndex(size_t index) const { 411 bool ProfileInfoCache::ProfileIsSupervisedAtIndex(size_t index) const {
411 return !GetSupervisedUserIdOfProfileAtIndex(index).empty(); 412 return !GetSupervisedUserIdOfProfileAtIndex(index).empty();
412 } 413 }
413 414
414 bool ProfileInfoCache::ProfileIsChildAtIndex(size_t index) const { 415 bool ProfileInfoCache::ProfileIsChildAtIndex(size_t index) const {
415 #if defined(ENABLE_SUPERVISED_USERS) 416 #if defined(ENABLE_SUPERVISED_USERS)
416 return GetSupervisedUserIdOfProfileAtIndex(index) == 417 return GetSupervisedUserIdOfProfileAtIndex(index) ==
417 supervised_users::kChildAccountSUID; 418 supervised_users::GetChildAccountSUID();
418 #else 419 #else
419 return false; 420 return false;
420 #endif 421 #endif
421 } 422 }
422 423
423 bool ProfileInfoCache::ProfileIsLegacySupervisedAtIndex(size_t index) const { 424 bool ProfileInfoCache::ProfileIsLegacySupervisedAtIndex(size_t index) const {
424 return ProfileIsSupervisedAtIndex(index) && !ProfileIsChildAtIndex(index); 425 return ProfileIsSupervisedAtIndex(index) && !ProfileIsChildAtIndex(index);
425 } 426 }
426 427
427 bool ProfileInfoCache::IsOmittedProfileAtIndex(size_t index) const { 428 bool ProfileInfoCache::IsOmittedProfileAtIndex(size_t index) const {
428 bool value = false; 429 bool value = false;
429 GetInfoForProfileAtIndex(index)->GetBoolean(kIsOmittedFromProfileListKey, 430 GetInfoForProfileAtIndex(index)->GetBoolean(kIsOmittedFromProfileListKey,
430 &value); 431 &value);
431 return value; 432 return value;
432 } 433 }
433 434
434 bool ProfileInfoCache::ProfileIsSigninRequiredAtIndex(size_t index) const { 435 bool ProfileInfoCache::ProfileIsSigninRequiredAtIndex(size_t index) const {
435 bool value = false; 436 bool value = false;
436 GetInfoForProfileAtIndex(index)->GetBoolean(kSigninRequiredKey, &value); 437 GetInfoForProfileAtIndex(index)->GetBoolean(kSigninRequiredKey, &value);
437 return value; 438 return value;
438 } 439 }
439 440
440 std::string ProfileInfoCache::GetSupervisedUserIdOfProfileAtIndex( 441 user_manager::UserID ProfileInfoCache::GetSupervisedUserIdOfProfileAtIndex(
441 size_t index) const { 442 size_t index) const {
442 std::string supervised_user_id; 443 std::string supervised_user_email;
443 GetInfoForProfileAtIndex(index)->GetString(kSupervisedUserId, 444 GetInfoForProfileAtIndex(index)->GetString(kSupervisedUserId,
444 &supervised_user_id); 445 &supervised_user_email);
445 return supervised_user_id; 446 return user_manager::UserID::FromUserEmail(supervised_user_email);
446 } 447 }
447 448
448 bool ProfileInfoCache::ProfileIsEphemeralAtIndex(size_t index) const { 449 bool ProfileInfoCache::ProfileIsEphemeralAtIndex(size_t index) const {
449 bool value = false; 450 bool value = false;
450 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); 451 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value);
451 return value; 452 return value;
452 } 453 }
453 454
454 bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const { 455 bool ProfileInfoCache::ProfileIsUsingDefaultNameAtIndex(size_t index) const {
455 bool value = false; 456 bool value = false;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 SetInfoForProfileAtIndex(index, info.release()); 596 SetInfoForProfileAtIndex(index, info.release());
596 597
597 base::FilePath profile_path = GetPathOfProfileAtIndex(index); 598 base::FilePath profile_path = GetPathOfProfileAtIndex(index);
598 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, 599 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
599 observer_list_, 600 observer_list_,
600 OnProfileIsOmittedChanged(profile_path)); 601 OnProfileIsOmittedChanged(profile_path));
601 } 602 }
602 603
603 void ProfileInfoCache::SetSupervisedUserIdOfProfileAtIndex( 604 void ProfileInfoCache::SetSupervisedUserIdOfProfileAtIndex(
604 size_t index, 605 size_t index,
605 const std::string& id) { 606 const user_manager::UserID& id) {
606 if (GetSupervisedUserIdOfProfileAtIndex(index) == id) 607 if (GetSupervisedUserIdOfProfileAtIndex(index) == id)
607 return; 608 return;
608 scoped_ptr<base::DictionaryValue> info( 609 scoped_ptr<base::DictionaryValue> info(
609 GetInfoForProfileAtIndex(index)->DeepCopy()); 610 GetInfoForProfileAtIndex(index)->DeepCopy());
610 info->SetString(kSupervisedUserId, id); 611 info->SetString(kSupervisedUserId, id.GetUserEmail());
611 // This takes ownership of |info|. 612 // This takes ownership of |info|.
612 SetInfoForProfileAtIndex(index, info.release()); 613 SetInfoForProfileAtIndex(index, info.release());
613 614
614 base::FilePath profile_path = GetPathOfProfileAtIndex(index); 615 base::FilePath profile_path = GetPathOfProfileAtIndex(index);
615 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, 616 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
616 observer_list_, 617 observer_list_,
617 OnProfileSupervisedUserIdChanged(profile_path)); 618 OnProfileSupervisedUserIdChanged(profile_path));
618 } 619 }
619 620
620 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex( 621 void ProfileInfoCache::SetLocalAuthCredentialsOfProfileAtIndex(
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 std::vector<base::FilePath>::const_iterator it; 1214 std::vector<base::FilePath>::const_iterator it;
1214 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { 1215 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) {
1215 size_t profile_index = GetIndexOfProfileWithPath(*it); 1216 size_t profile_index = GetIndexOfProfileWithPath(*it);
1216 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); 1217 SetProfileIsUsingDefaultNameAtIndex(profile_index, true);
1217 // This will assign a new "Person %d" type name and re-sort the cache. 1218 // This will assign a new "Person %d" type name and re-sort the cache.
1218 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( 1219 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile(
1219 GetAvatarIconIndexOfProfileAtIndex(profile_index))); 1220 GetAvatarIconIndexOfProfileAtIndex(profile_index)));
1220 } 1221 }
1221 #endif 1222 #endif
1222 } 1223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698