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

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

Issue 1913373002: Revert "Refactor ProfileInfoCache in most of c/b/profiles" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/profiles_state.h" 5 #include "chrome/browser/profiles/profiles_state.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/browsing_data/browsing_data_helper.h" 13 #include "chrome/browser/browsing_data/browsing_data_helper.h"
14 #include "chrome/browser/browsing_data/browsing_data_remover.h" 14 #include "chrome/browser/browsing_data/browsing_data_remover.h"
15 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 15 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
16 #include "chrome/browser/profiles/gaia_info_update_service.h" 16 #include "chrome/browser/profiles/gaia_info_update_service.h"
17 #include "chrome/browser/profiles/gaia_info_update_service_factory.h" 17 #include "chrome/browser/profiles/gaia_info_update_service_factory.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_attributes_entry.h" 19 #include "chrome/browser/profiles/profile_info_cache.h"
20 #include "chrome/browser/profiles/profile_attributes_storage.h"
21 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
23 #include "chrome/browser/signin/signin_error_controller_factory.h" 22 #include "chrome/browser/signin/signin_error_controller_factory.h"
24 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
25 #include "chrome/common/chrome_constants.h" 24 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
27 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
28 #include "components/prefs/pref_registry_simple.h" 27 #include "components/prefs/pref_registry_simple.h"
29 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
30 #include "components/signin/core/browser/profile_oauth2_token_service.h" 29 #include "components/signin/core/browser/profile_oauth2_token_service.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 registry->RegisterBooleanPref( 62 registry->RegisterBooleanPref(
64 prefs::kProfileAvatarRightClickTutorialDismissed, false); 63 prefs::kProfileAvatarRightClickTutorialDismissed, false);
65 } 64 }
66 65
67 base::string16 GetAvatarNameForProfile(const base::FilePath& profile_path) { 66 base::string16 GetAvatarNameForProfile(const base::FilePath& profile_path) {
68 base::string16 display_name; 67 base::string16 display_name;
69 68
70 if (profile_path == ProfileManager::GetGuestProfilePath()) { 69 if (profile_path == ProfileManager::GetGuestProfilePath()) {
71 display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME); 70 display_name = l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME);
72 } else { 71 } else {
73 ProfileAttributesStorage& storage = 72 const ProfileInfoCache& cache =
74 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 73 g_browser_process->profile_manager()->GetProfileInfoCache();
74 size_t index = cache.GetIndexOfProfileWithPath(profile_path);
75 75
76 ProfileAttributesEntry* entry; 76 if (index == std::string::npos)
77 if (!storage.GetProfileAttributesWithPath(profile_path, &entry))
78 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); 77 return l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME);
79 78
80 // Using the --new-avatar-menu flag, there's a couple of rules about what 79 // Using the --new-avatar-menu flag, there's a couple of rules about what
81 // the avatar button displays. If there's a single profile, with a default 80 // the avatar button displays. If there's a single profile, with a default
82 // name (i.e. of the form Person %d) not manually set, it should display 81 // name (i.e. of the form Person %d) not manually set, it should display
83 // IDS_SINGLE_PROFILE_DISPLAY_NAME. If the profile is signed in but is using 82 // IDS_SINGLE_PROFILE_DISPLAY_NAME. If the profile is signed in but is using
84 // a default name, use the profiles's email address. Otherwise, it 83 // a default name, use the profiles's email address. Otherwise, it
85 // will return the actual name of the profile. 84 // will return the actual name of the profile.
86 const base::string16 profile_name = entry->GetName(); 85 const base::string16 profile_name = cache.GetNameOfProfileAtIndex(index);
87 const base::string16 email = entry->GetUserName(); 86 const base::string16 email = cache.GetUserNameOfProfileAtIndex(index);
88 bool is_default_name = entry->IsUsingDefaultName() && 87 bool is_default_name = cache.ProfileIsUsingDefaultNameAtIndex(index) &&
89 storage.IsDefaultProfileName(profile_name); 88 cache.IsDefaultProfileName(profile_name);
90 89
91 if (storage.GetNumberOfProfiles() == 1u && is_default_name) 90 if (cache.GetNumberOfProfiles() == 1 && is_default_name)
92 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); 91 display_name = l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME);
93 else 92 else
94 display_name = (is_default_name && !email.empty()) ? email : profile_name; 93 display_name = (is_default_name && !email.empty()) ? email : profile_name;
95 } 94 }
96 return display_name; 95 return display_name;
97 } 96 }
98 97
99 base::string16 GetAvatarButtonTextForProfile(Profile* profile) { 98 base::string16 GetAvatarButtonTextForProfile(Profile* profile) {
100 const int kMaxCharactersToDisplay = 15; 99 const int kMaxCharactersToDisplay = 15;
101 base::string16 name = GetAvatarNameForProfile(profile->GetPath()); 100 base::string16 name = GetAvatarNameForProfile(profile->GetPath());
(...skipping 12 matching lines...) Expand all
114 return l10n_util::GetStringFUTF16( 113 return l10n_util::GetStringFUTF16(
115 IDS_LEGACY_SUPERVISED_USER_NEW_AVATAR_LABEL, item.name); 114 IDS_LEGACY_SUPERVISED_USER_NEW_AVATAR_LABEL, item.name);
116 } 115 }
117 if (item.child_account) 116 if (item.child_account)
118 return l10n_util::GetStringFUTF16(IDS_CHILD_AVATAR_LABEL, item.name); 117 return l10n_util::GetStringFUTF16(IDS_CHILD_AVATAR_LABEL, item.name);
119 return item.name; 118 return item.name;
120 } 119 }
121 120
122 void UpdateProfileName(Profile* profile, 121 void UpdateProfileName(Profile* profile,
123 const base::string16& new_profile_name) { 122 const base::string16& new_profile_name) {
124 ProfileAttributesEntry* entry; 123 const ProfileInfoCache& cache =
125 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). 124 g_browser_process->profile_manager()->GetProfileInfoCache();
126 GetProfileAttributesWithPath(profile->GetPath(), &entry)) { 125 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
126 if (profile_index == std::string::npos)
127 return; 127 return;
128 }
129 128
130 if (new_profile_name == entry->GetName()) 129 if (new_profile_name == cache.GetNameOfProfileAtIndex(profile_index))
131 return; 130 return;
132 131
133 // This is only called when updating the profile name through the UI, 132 // This is only called when updating the profile name through the UI,
134 // so we can assume the user has done this on purpose. 133 // so we can assume the user has done this on purpose.
135 PrefService* pref_service = profile->GetPrefs(); 134 PrefService* pref_service = profile->GetPrefs();
136 pref_service->SetBoolean(prefs::kProfileUsingDefaultName, false); 135 pref_service->SetBoolean(prefs::kProfileUsingDefaultName, false);
137 136
138 // Updating the profile preference will cause the profile attributes storage 137 // Updating the profile preference will cause the cache to be updated for
139 // to be updated for this preference. 138 // this preference.
140 pref_service->SetString(prefs::kProfileName, 139 pref_service->SetString(prefs::kProfileName,
141 base::UTF16ToUTF8(new_profile_name)); 140 base::UTF16ToUTF8(new_profile_name));
142 } 141 }
143 142
144 std::vector<std::string> GetSecondaryAccountsForProfile( 143 std::vector<std::string> GetSecondaryAccountsForProfile(
145 Profile* profile, 144 Profile* profile,
146 const std::string& primary_account) { 145 const std::string& primary_account) {
147 std::vector<std::string> accounts = 146 std::vector<std::string> accounts =
148 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->GetAccounts(); 147 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->GetAccounts();
149 148
150 // The vector returned by ProfileOAuth2TokenService::GetAccounts() contains 149 // The vector returned by ProfileOAuth2TokenService::GetAccounts() contains
151 // the primary account too, so we need to remove it from the list. 150 // the primary account too, so we need to remove it from the list.
152 std::vector<std::string>::iterator primary_index = 151 std::vector<std::string>::iterator primary_index =
153 std::find(accounts.begin(), accounts.end(), primary_account); 152 std::find(accounts.begin(), accounts.end(), primary_account);
154 DCHECK(primary_index != accounts.end()); 153 DCHECK(primary_index != accounts.end());
155 accounts.erase(primary_index); 154 accounts.erase(primary_index);
156 155
157 return accounts; 156 return accounts;
158 } 157 }
159 158
160 bool IsRegularOrGuestSession(Browser* browser) { 159 bool IsRegularOrGuestSession(Browser* browser) {
161 Profile* profile = browser->profile(); 160 Profile* profile = browser->profile();
162 return profile->IsGuestSession() || !profile->IsOffTheRecord(); 161 return profile->IsGuestSession() || !profile->IsOffTheRecord();
163 } 162 }
164 163
165 bool IsProfileLocked(const base::FilePath& profile_path) { 164 bool IsProfileLocked(const base::FilePath& path) {
166 ProfileAttributesEntry* entry; 165 const ProfileInfoCache& cache =
167 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). 166 g_browser_process->profile_manager()->GetProfileInfoCache();
168 GetProfileAttributesWithPath(profile_path, &entry)) { 167 size_t profile_index = cache.GetIndexOfProfileWithPath(path);
168
169 if (profile_index == std::string::npos)
169 return false; 170 return false;
170 }
171 171
172 return entry->IsSigninRequired(); 172 return cache.ProfileIsSigninRequiredAtIndex(profile_index);
173 } 173 }
174 174
175 void UpdateIsProfileLockEnabledIfNeeded(Profile* profile) { 175 void UpdateIsProfileLockEnabledIfNeeded(Profile* profile) {
176 DCHECK(switches::IsNewProfileManagement()); 176 DCHECK(switches::IsNewProfileManagement());
177 177
178 if (!profile->GetPrefs()->GetString(prefs::kGoogleServicesHostedDomain). 178 if (!profile->GetPrefs()->GetString(prefs::kGoogleServicesHostedDomain).
179 empty()) 179 empty())
180 return; 180 return;
181 181
182 UpdateGaiaProfileInfoIfNeeded(profile); 182 UpdateGaiaProfileInfoIfNeeded(profile);
(...skipping 21 matching lines...) Expand all
204 204
205 bool SetActiveProfileToGuestIfLocked() { 205 bool SetActiveProfileToGuestIfLocked() {
206 ProfileManager* profile_manager = g_browser_process->profile_manager(); 206 ProfileManager* profile_manager = g_browser_process->profile_manager();
207 207
208 const base::FilePath& active_profile_path = 208 const base::FilePath& active_profile_path =
209 profile_manager->GetLastUsedProfileDir(profile_manager->user_data_dir()); 209 profile_manager->GetLastUsedProfileDir(profile_manager->user_data_dir());
210 const base::FilePath& guest_path = ProfileManager::GetGuestProfilePath(); 210 const base::FilePath& guest_path = ProfileManager::GetGuestProfilePath();
211 if (active_profile_path == guest_path) 211 if (active_profile_path == guest_path)
212 return true; 212 return true;
213 213
214 ProfileAttributesEntry* entry; 214 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
215 bool has_entry = 215 size_t index = cache.GetIndexOfProfileWithPath(active_profile_path);
216 g_browser_process->profile_manager()->GetProfileAttributesStorage(). 216 if (!cache.ProfileIsSigninRequiredAtIndex(index))
217 GetProfileAttributesWithPath(active_profile_path, &entry);
218 DCHECK(has_entry);
219
220 if (!entry->IsSigninRequired())
221 return false; 217 return false;
222 218
223 SetLastUsedProfile(guest_path.BaseName().MaybeAsASCII()); 219 SetLastUsedProfile(guest_path.BaseName().MaybeAsASCII());
224 220
225 return true; 221 return true;
226 } 222 }
227 223
228 void RemoveBrowsingDataForProfile(const base::FilePath& profile_path) { 224 void RemoveBrowsingDataForProfile(const base::FilePath& profile_path) {
229 // The BrowsingDataRemover relies on the ResourceDispatcherHost, which is 225 // The BrowsingDataRemover relies on the ResourceDispatcherHost, which is
230 // null in unit tests. 226 // null in unit tests.
(...skipping 19 matching lines...) Expand all
250 // shouldn't have a browser. 246 // shouldn't have a browser.
251 if (profile_dir == base::FilePath(chrome::kSystemProfileDir).AsUTF8Unsafe()) 247 if (profile_dir == base::FilePath(chrome::kSystemProfileDir).AsUTF8Unsafe())
252 return; 248 return;
253 249
254 PrefService* local_state = g_browser_process->local_state(); 250 PrefService* local_state = g_browser_process->local_state();
255 DCHECK(local_state); 251 DCHECK(local_state);
256 local_state->SetString(prefs::kProfileLastUsed, profile_dir); 252 local_state->SetString(prefs::kProfileLastUsed, profile_dir);
257 } 253 }
258 254
259 } // namespace profiles 255 } // namespace profiles
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profiles_state.h ('k') | chrome/browser/ui/webui/signin/signin_create_profile_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698