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

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

Issue 1794353003: Refactor ProfileInfoCache in c/b/profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/profile_window.h" 5 #include "chrome/browser/profiles/profile_window.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "chrome/browser/about_flags.h" 18 #include "chrome/browser/about_flags.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/lifetime/application_lifetime.h" 20 #include "chrome/browser/lifetime/application_lifetime.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_attributes_entry.h"
23 #include "chrome/browser/profiles/profile_attributes_storage.h"
21 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 24 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
22 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/signin/account_reconcilor_factory.h" 26 #include "chrome/browser/signin/account_reconcilor_factory.h"
24 #include "chrome/browser/signin/account_tracker_service_factory.h" 27 #include "chrome/browser/signin/account_tracker_service_factory.h"
25 #include "chrome/browser/signin/signin_manager_factory.h" 28 #include "chrome/browser/signin/signin_manager_factory.h"
26 #include "chrome/browser/signin/signin_ui_util.h" 29 #include "chrome/browser/signin/signin_ui_util.h"
27 #include "chrome/browser/sync/profile_sync_service_factory.h" 30 #include "chrome/browser/sync/profile_sync_service_factory.h"
28 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
29 #include "chrome/browser/ui/browser_dialogs.h" 32 #include "chrome/browser/ui/browser_dialogs.h"
30 #include "chrome/browser/ui/profile_chooser_constants.h" 33 #include "chrome/browser/ui/profile_chooser_constants.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // If this is a brand new profile, then start a first run window. 138 // If this is a brand new profile, then start a first run window.
136 if (is_new_profile) { 139 if (is_new_profile) {
137 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; 140 is_process_startup = chrome::startup::IS_PROCESS_STARTUP;
138 is_first_run = chrome::startup::IS_FIRST_RUN; 141 is_first_run = chrome::startup::IS_FIRST_RUN;
139 } 142 }
140 143
141 #if defined(ENABLE_EXTENSIONS) 144 #if defined(ENABLE_EXTENSIONS)
142 // The signin bit will still be set if the profile is being unlocked and the 145 // The signin bit will still be set if the profile is being unlocked and the
143 // browser window for it is opening. As part of this unlock process, unblock 146 // browser window for it is opening. As part of this unlock process, unblock
144 // all the extensions. 147 // all the extensions.
145 const ProfileInfoCache& cache = 148 if (!profile->IsGuestSession()) {
146 g_browser_process->profile_manager()->GetProfileInfoCache(); 149 ProfileAttributesEntry* entry;
147 int index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 150 if (g_browser_process->profile_manager()->GetProfileAttributesStorage().
148 if (!profile->IsGuestSession() && 151 GetProfileAttributesWithPath(profile->GetPath(), &entry) &&
149 cache.ProfileIsSigninRequiredAtIndex(index)) { 152 entry->IsSigninRequired()) {
150 UnblockExtensions(profile); 153 UnblockExtensions(profile);
154 }
151 } 155 }
152 #endif // defined(ENABLE_EXTENSIONS) 156 #endif // defined(ENABLE_EXTENSIONS)
153 157
154 // If |always_create| is false, and we have a |callback| to run, check 158 // If |always_create| is false, and we have a |callback| to run, check
155 // whether a browser already exists so that we can run the callback. We don't 159 // whether a browser already exists so that we can run the callback. We don't
156 // want to rely on the observer listening to OnBrowserSetLastActive in this 160 // want to rely on the observer listening to OnBrowserSetLastActive in this
157 // case, as you could manually activate an incorrect browser and trigger 161 // case, as you could manually activate an incorrect browser and trigger
158 // a false positive. 162 // a false positive.
159 if (!always_create) { 163 if (!always_create) {
160 Browser* browser = chrome::FindTabbedBrowser(profile, false); 164 Browser* browser = chrome::FindTabbedBrowser(profile, false);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null()) 202 if (status != Profile::CREATE_STATUS_INITIALIZED || callback.is_null())
199 return; 203 return;
200 204
201 // Tell the webui which user should be focused. 205 // Tell the webui which user should be focused.
202 std::string page = switches::IsMaterialDesignUserManager() ? 206 std::string page = switches::IsMaterialDesignUserManager() ?
203 chrome::kChromeUIMdUserManagerUrl : chrome::kChromeUIUserManagerURL; 207 chrome::kChromeUIMdUserManagerUrl : chrome::kChromeUIUserManagerURL;
204 208
205 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) { 209 if (tutorial_mode == profiles::USER_MANAGER_TUTORIAL_OVERVIEW) {
206 page += profiles::kUserManagerDisplayTutorial; 210 page += profiles::kUserManagerDisplayTutorial;
207 } else if (!profile_path_to_focus.empty()) { 211 } else if (!profile_path_to_focus.empty()) {
208 const ProfileInfoCache& cache = 212 // TODO(anthonyvd) : Send |profile_path_to_focus| to the user manager
209 g_browser_process->profile_manager()->GetProfileInfoCache(); 213 // instead of the profile index.
210 size_t index = cache.GetIndexOfProfileWithPath(profile_path_to_focus); 214 std::vector<ProfileAttributesEntry*> entries =
211 if (index != std::string::npos) { 215 g_browser_process->profile_manager()->GetProfileAttributesStorage().
212 page += "#"; 216 GetAllProfilesAttributesSortedByName();
Mike Lerman 2016/03/18 17:10:44 This is now very fragile, as we're assuming that w
lwchkg 2016/03/19 18:48:46 Agree. Anyway I've modified that SendUserList to
Mike Lerman 2016/03/30 01:18:10 Let's wait for your other related CL to land first
lwchkg 2016/03/31 19:32:26 Sure. Will rebase later today.
213 page += base::SizeTToString(index); 217 size_t count = entries.size();
218 for (size_t i = 0; i < count; ++i) {
219 if (profile_path_to_focus == entries[i]->GetPath()) {
220 page += "#";
221 page += base::SizeTToString(i);
222 break;
223 }
214 } 224 }
215 } else if (profile_open_action == 225 } else if (profile_open_action ==
216 profiles::USER_MANAGER_SELECT_PROFILE_TASK_MANAGER) { 226 profiles::USER_MANAGER_SELECT_PROFILE_TASK_MANAGER) {
217 page += profiles::kUserManagerSelectProfileTaskManager; 227 page += profiles::kUserManagerSelectProfileTaskManager;
218 } else if (profile_open_action == 228 } else if (profile_open_action ==
219 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME) { 229 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME) {
220 page += profiles::kUserManagerSelectProfileAboutChrome; 230 page += profiles::kUserManagerSelectProfileAboutChrome;
221 } else if (profile_open_action == 231 } else if (profile_open_action ==
222 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS) { 232 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS) {
223 page += profiles::kUserManagerSelectProfileChromeSettings; 233 page += profiles::kUserManagerSelectProfileChromeSettings;
(...skipping 25 matching lines...) Expand all
249 const char kUserManagerSelectProfileTaskManager[] = "#task-manager"; 259 const char kUserManagerSelectProfileTaskManager[] = "#task-manager";
250 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome"; 260 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome";
251 const char kUserManagerSelectProfileChromeSettings[] = "#chrome-settings"; 261 const char kUserManagerSelectProfileChromeSettings[] = "#chrome-settings";
252 const char kUserManagerSelectProfileChromeMemory[] = "#chrome-memory"; 262 const char kUserManagerSelectProfileChromeMemory[] = "#chrome-memory";
253 const char kUserManagerSelectProfileAppLauncher[] = "#app-launcher"; 263 const char kUserManagerSelectProfileAppLauncher[] = "#app-launcher";
254 264
255 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager, 265 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager,
256 const std::string& email) { 266 const std::string& email) {
257 base::string16 profile_email = base::UTF8ToUTF16(email); 267 base::string16 profile_email = base::UTF8ToUTF16(email);
258 std::vector<ProfileAttributesEntry*> entries = 268 std::vector<ProfileAttributesEntry*> entries =
259 profile_manager->GetProfileInfoCache().GetAllProfilesAttributes(); 269 profile_manager->GetProfileAttributesStorage().GetAllProfilesAttributes();
260 for (ProfileAttributesEntry* entry : entries) { 270 for (ProfileAttributesEntry* entry : entries) {
261 if (entry->GetUserName() == profile_email) 271 if (entry->GetUserName() == profile_email)
262 return entry->GetPath(); 272 return entry->GetPath();
263 } 273 }
264 return base::FilePath(); 274 return base::FilePath();
265 } 275 }
266 276
267 void FindOrCreateNewWindowForProfile( 277 void FindOrCreateNewWindowForProfile(
268 Profile* profile, 278 Profile* profile,
269 chrome::startup::IsProcessStartup process_startup, 279 chrome::startup::IsProcessStartup process_startup,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 323
314 bool HasProfileSwitchTargets(Profile* profile) { 324 bool HasProfileSwitchTargets(Profile* profile) {
315 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; 325 size_t min_profiles = profile->IsGuestSession() ? 1 : 2;
316 size_t number_of_profiles = 326 size_t number_of_profiles =
317 g_browser_process->profile_manager()->GetNumberOfProfiles(); 327 g_browser_process->profile_manager()->GetNumberOfProfiles();
318 return number_of_profiles >= min_profiles; 328 return number_of_profiles >= min_profiles;
319 } 329 }
320 330
321 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback, 331 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback,
322 ProfileMetrics::ProfileAdd metric) { 332 ProfileMetrics::ProfileAdd metric) {
323 ProfileInfoCache& cache = 333 ProfileAttributesStorage& storage =
324 g_browser_process->profile_manager()->GetProfileInfoCache(); 334 g_browser_process->profile_manager()->GetProfileAttributesStorage();
325 335
326 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); 336 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex();
327 ProfileManager::CreateMultiProfileAsync( 337 ProfileManager::CreateMultiProfileAsync(
328 cache.ChooseNameForNewProfile(placeholder_avatar_index), 338 storage.ChooseNameForNewProfile(placeholder_avatar_index),
329 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index), 339 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index),
330 base::Bind(&OpenBrowserWindowForProfile, callback, true, true), 340 base::Bind(&OpenBrowserWindowForProfile, callback, true, true),
331 std::string()); 341 std::string());
332 ProfileMetrics::LogProfileAddNewUser(metric); 342 ProfileMetrics::LogProfileAddNewUser(metric);
333 } 343 }
334 344
335 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) { 345 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) {
336 UserManager::Show(base::FilePath(), 346 UserManager::Show(base::FilePath(),
337 profiles::USER_MANAGER_NO_TUTORIAL, 347 profiles::USER_MANAGER_NO_TUTORIAL,
338 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 348 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
339 } 349 }
340 350
341 void CloseGuestProfileWindows() { 351 void CloseGuestProfileWindows() {
342 ProfileManager* profile_manager = g_browser_process->profile_manager(); 352 ProfileManager* profile_manager = g_browser_process->profile_manager();
343 Profile* profile = profile_manager->GetProfileByPath( 353 Profile* profile = profile_manager->GetProfileByPath(
344 ProfileManager::GetGuestProfilePath()); 354 ProfileManager::GetGuestProfilePath());
345 355
346 if (profile) { 356 if (profile) {
347 BrowserList::CloseAllBrowsersWithProfile( 357 BrowserList::CloseAllBrowsersWithProfile(
348 profile, base::Bind(&GuestBrowserCloseSuccess)); 358 profile, base::Bind(&GuestBrowserCloseSuccess));
349 } 359 }
350 } 360 }
351 361
352 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { 362 void LockBrowserCloseSuccess(const base::FilePath& profile_path) {
353 ProfileManager* profile_manager = g_browser_process->profile_manager(); 363 ProfileManager* profile_manager = g_browser_process->profile_manager();
354 ProfileInfoCache* cache = &profile_manager->GetProfileInfoCache(); 364 ProfileAttributesEntry* entry;
355 365 bool has_entry = profile_manager->GetProfileAttributesStorage().
356 cache->SetProfileSigninRequiredAtIndex( 366 GetProfileAttributesWithPath(profile_path, &entry);
357 cache->GetIndexOfProfileWithPath(profile_path), true); 367 DCHECK(has_entry);
368 entry->SetIsSigninRequired(true);
358 369
359 #if defined(ENABLE_EXTENSIONS) 370 #if defined(ENABLE_EXTENSIONS)
360 // Profile guaranteed to exist for it to have been locked. 371 // Profile guaranteed to exist for it to have been locked.
361 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); 372 BlockExtensions(profile_manager->GetProfileByPath(profile_path));
362 #endif // defined(ENABLE_EXTENSIONS) 373 #endif // defined(ENABLE_EXTENSIONS)
363 374
364 chrome::HideTaskManager(); 375 chrome::HideTaskManager();
365 UserManager::Show(profile_path, 376 UserManager::Show(profile_path,
366 profiles::USER_MANAGER_NO_TUTORIAL, 377 profiles::USER_MANAGER_NO_TUTORIAL,
367 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 378 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
(...skipping 26 matching lines...) Expand all
394 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); 405 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
395 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain; 406 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain;
396 } 407 }
397 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then, 408 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then,
398 // prohibited users who use hosted domains (aside from google.com). 409 // prohibited users who use hosted domains (aside from google.com).
399 if (hosted_domain != Profile::kNoHostedDomainFound && 410 if (hosted_domain != Profile::kNoHostedDomainFound &&
400 hosted_domain != "google.com") { 411 hosted_domain != "google.com") {
401 return false; 412 return false;
402 } 413 }
403 414
404 const ProfileInfoCache& cache = 415 // Lock only when there is at least one supervised user on the machine.
405 g_browser_process->profile_manager()->GetProfileInfoCache(); 416 std::vector<ProfileAttributesEntry*> entries =
406 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { 417 g_browser_process->profile_manager()->GetProfileAttributesStorage().
407 if (cache.ProfileIsSupervisedAtIndex(i)) 418 GetAllProfilesAttributes();
419 for (ProfileAttributesEntry* entry : entries) {
420 if (entry->IsSupervised())
408 return true; 421 return true;
409 } 422 }
410 return false; 423 return false;
411 } 424 }
412 425
413 void CreateSystemProfileForUserManager( 426 void CreateSystemProfileForUserManager(
414 const base::FilePath& profile_path_to_focus, 427 const base::FilePath& profile_path_to_focus,
415 profiles::UserManagerTutorialMode tutorial_mode, 428 profiles::UserManagerTutorialMode tutorial_mode,
416 profiles::UserManagerProfileSelected profile_open_action, 429 profiles::UserManagerProfileSelected profile_open_action,
417 const base::Callback<void(Profile*, const std::string&)>& callback) { 430 const base::Callback<void(Profile*, const std::string&)>& callback) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 PrefService* local_state = g_browser_process->local_state(); 549 PrefService* local_state = g_browser_process->local_state();
537 const bool dismissed = local_state->GetBoolean( 550 const bool dismissed = local_state->GetBoolean(
538 prefs::kProfileAvatarRightClickTutorialDismissed); 551 prefs::kProfileAvatarRightClickTutorialDismissed);
539 552
540 // Don't show the tutorial if it's already been dismissed or if right-clicking 553 // Don't show the tutorial if it's already been dismissed or if right-clicking
541 // wouldn't show any targets. 554 // wouldn't show any targets.
542 return !dismissed && HasProfileSwitchTargets(profile); 555 return !dismissed && HasProfileSwitchTargets(profile);
543 } 556 }
544 557
545 } // namespace profiles 558 } // namespace profiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698