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

Side by Side Diff: chrome/browser/profiles/profile_window.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/profile_window.h" 5 #include "chrome/browser/profiles/profile_window.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8
9 #include <string> 8 #include <string>
10 #include <vector> 9 #include <vector>
11 10
12 #include "base/command_line.h" 11 #include "base/command_line.h"
13 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
14 #include "base/macros.h" 13 #include "base/macros.h"
15 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
17 #include "build/build_config.h" 16 #include "build/build_config.h"
18 #include "chrome/browser/about_flags.h" 17 #include "chrome/browser/about_flags.h"
19 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/lifetime/application_lifetime.h" 19 #include "chrome/browser/lifetime/application_lifetime.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_attributes_entry.h"
23 #include "chrome/browser/profiles/profile_attributes_storage.h"
24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 21 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
25 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/signin/account_reconcilor_factory.h" 23 #include "chrome/browser/signin/account_reconcilor_factory.h"
27 #include "chrome/browser/signin/account_tracker_service_factory.h" 24 #include "chrome/browser/signin/account_tracker_service_factory.h"
28 #include "chrome/browser/signin/signin_manager_factory.h" 25 #include "chrome/browser/signin/signin_manager_factory.h"
29 #include "chrome/browser/signin/signin_ui_util.h" 26 #include "chrome/browser/signin/signin_ui_util.h"
30 #include "chrome/browser/sync/profile_sync_service_factory.h" 27 #include "chrome/browser/sync/profile_sync_service_factory.h"
31 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_dialogs.h" 29 #include "chrome/browser/ui/browser_dialogs.h"
33 #include "chrome/browser/ui/profile_chooser_constants.h" 30 #include "chrome/browser/ui/profile_chooser_constants.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // If this is a brand new profile, then start a first run window. 136 // If this is a brand new profile, then start a first run window.
140 if (is_new_profile) { 137 if (is_new_profile) {
141 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; 138 is_process_startup = chrome::startup::IS_PROCESS_STARTUP;
142 is_first_run = chrome::startup::IS_FIRST_RUN; 139 is_first_run = chrome::startup::IS_FIRST_RUN;
143 } 140 }
144 141
145 #if defined(ENABLE_EXTENSIONS) 142 #if defined(ENABLE_EXTENSIONS)
146 // The signin bit will still be set if the profile is being unlocked and the 143 // The signin bit will still be set if the profile is being unlocked and the
147 // browser window for it is opening. As part of this unlock process, unblock 144 // browser window for it is opening. As part of this unlock process, unblock
148 // all the extensions. 145 // all the extensions.
149 if (!profile->IsGuestSession()) { 146 const ProfileInfoCache& cache =
150 ProfileAttributesEntry* entry; 147 g_browser_process->profile_manager()->GetProfileInfoCache();
151 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). 148 int index = cache.GetIndexOfProfileWithPath(profile->GetPath());
152 GetProfileAttributesWithPath(profile->GetPath(), &entry) && 149 if (!profile->IsGuestSession() &&
153 entry->IsSigninRequired()) { 150 cache.ProfileIsSigninRequiredAtIndex(index)) {
154 UnblockExtensions(profile); 151 UnblockExtensions(profile);
155 }
156 } 152 }
157 #endif // defined(ENABLE_EXTENSIONS) 153 #endif // defined(ENABLE_EXTENSIONS)
158 154
159 // If |always_create| is false, and we have a |callback| to run, check 155 // If |always_create| is false, and we have a |callback| to run, check
160 // whether a browser already exists so that we can run the callback. We don't 156 // whether a browser already exists so that we can run the callback. We don't
161 // want to rely on the observer listening to OnBrowserSetLastActive in this 157 // want to rely on the observer listening to OnBrowserSetLastActive in this
162 // case, as you could manually activate an incorrect browser and trigger 158 // case, as you could manually activate an incorrect browser and trigger
163 // a false positive. 159 // a false positive.
164 if (!always_create) { 160 if (!always_create) {
165 Browser* browser = chrome::FindTabbedBrowser(profile, false); 161 Browser* browser = chrome::FindTabbedBrowser(profile, false);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 const char kUserManagerDisplayTutorial[] = "#tutorial"; 244 const char kUserManagerDisplayTutorial[] = "#tutorial";
249 const char kUserManagerSelectProfileTaskManager[] = "#task-manager"; 245 const char kUserManagerSelectProfileTaskManager[] = "#task-manager";
250 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome"; 246 const char kUserManagerSelectProfileAboutChrome[] = "#about-chrome";
251 const char kUserManagerSelectProfileChromeSettings[] = "#chrome-settings"; 247 const char kUserManagerSelectProfileChromeSettings[] = "#chrome-settings";
252 const char kUserManagerSelectProfileAppLauncher[] = "#app-launcher"; 248 const char kUserManagerSelectProfileAppLauncher[] = "#app-launcher";
253 249
254 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager, 250 base::FilePath GetPathOfProfileWithEmail(ProfileManager* profile_manager,
255 const std::string& email) { 251 const std::string& email) {
256 base::string16 profile_email = base::UTF8ToUTF16(email); 252 base::string16 profile_email = base::UTF8ToUTF16(email);
257 std::vector<ProfileAttributesEntry*> entries = 253 std::vector<ProfileAttributesEntry*> entries =
258 profile_manager->GetProfileAttributesStorage().GetAllProfilesAttributes(); 254 profile_manager->GetProfileInfoCache().GetAllProfilesAttributes();
259 for (ProfileAttributesEntry* entry : entries) { 255 for (ProfileAttributesEntry* entry : entries) {
260 if (entry->GetUserName() == profile_email) 256 if (entry->GetUserName() == profile_email)
261 return entry->GetPath(); 257 return entry->GetPath();
262 } 258 }
263 return base::FilePath(); 259 return base::FilePath();
264 } 260 }
265 261
266 void FindOrCreateNewWindowForProfile( 262 void FindOrCreateNewWindowForProfile(
267 Profile* profile, 263 Profile* profile,
268 chrome::startup::IsProcessStartup process_startup, 264 chrome::startup::IsProcessStartup process_startup,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 308
313 bool HasProfileSwitchTargets(Profile* profile) { 309 bool HasProfileSwitchTargets(Profile* profile) {
314 size_t min_profiles = profile->IsGuestSession() ? 1 : 2; 310 size_t min_profiles = profile->IsGuestSession() ? 1 : 2;
315 size_t number_of_profiles = 311 size_t number_of_profiles =
316 g_browser_process->profile_manager()->GetNumberOfProfiles(); 312 g_browser_process->profile_manager()->GetNumberOfProfiles();
317 return number_of_profiles >= min_profiles; 313 return number_of_profiles >= min_profiles;
318 } 314 }
319 315
320 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback, 316 void CreateAndSwitchToNewProfile(ProfileManager::CreateCallback callback,
321 ProfileMetrics::ProfileAdd metric) { 317 ProfileMetrics::ProfileAdd metric) {
322 ProfileAttributesStorage& storage = 318 ProfileInfoCache& cache =
323 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 319 g_browser_process->profile_manager()->GetProfileInfoCache();
324 320
325 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); 321 int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex();
326 ProfileManager::CreateMultiProfileAsync( 322 ProfileManager::CreateMultiProfileAsync(
327 storage.ChooseNameForNewProfile(placeholder_avatar_index), 323 cache.ChooseNameForNewProfile(placeholder_avatar_index),
328 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index), 324 profiles::GetDefaultAvatarIconUrl(placeholder_avatar_index),
329 base::Bind(&OpenBrowserWindowForProfile, callback, true, true), 325 base::Bind(&OpenBrowserWindowForProfile, callback, true, true),
330 std::string()); 326 std::string());
331 ProfileMetrics::LogProfileAddNewUser(metric); 327 ProfileMetrics::LogProfileAddNewUser(metric);
332 } 328 }
333 329
334 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) { 330 void GuestBrowserCloseSuccess(const base::FilePath& profile_path) {
335 UserManager::Show(base::FilePath(), 331 UserManager::Show(base::FilePath(),
336 profiles::USER_MANAGER_NO_TUTORIAL, 332 profiles::USER_MANAGER_NO_TUTORIAL,
337 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 333 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
338 } 334 }
339 335
340 void CloseGuestProfileWindows() { 336 void CloseGuestProfileWindows() {
341 ProfileManager* profile_manager = g_browser_process->profile_manager(); 337 ProfileManager* profile_manager = g_browser_process->profile_manager();
342 Profile* profile = profile_manager->GetProfileByPath( 338 Profile* profile = profile_manager->GetProfileByPath(
343 ProfileManager::GetGuestProfilePath()); 339 ProfileManager::GetGuestProfilePath());
344 340
345 if (profile) { 341 if (profile) {
346 BrowserList::CloseAllBrowsersWithProfile( 342 BrowserList::CloseAllBrowsersWithProfile(
347 profile, base::Bind(&GuestBrowserCloseSuccess)); 343 profile, base::Bind(&GuestBrowserCloseSuccess));
348 } 344 }
349 } 345 }
350 346
351 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { 347 void LockBrowserCloseSuccess(const base::FilePath& profile_path) {
352 ProfileManager* profile_manager = g_browser_process->profile_manager(); 348 ProfileManager* profile_manager = g_browser_process->profile_manager();
353 ProfileAttributesEntry* entry; 349 ProfileInfoCache* cache = &profile_manager->GetProfileInfoCache();
354 bool has_entry = profile_manager->GetProfileAttributesStorage(). 350
355 GetProfileAttributesWithPath(profile_path, &entry); 351 cache->SetProfileSigninRequiredAtIndex(
356 DCHECK(has_entry); 352 cache->GetIndexOfProfileWithPath(profile_path), true);
357 entry->SetIsSigninRequired(true);
358 353
359 #if defined(ENABLE_EXTENSIONS) 354 #if defined(ENABLE_EXTENSIONS)
360 // Profile guaranteed to exist for it to have been locked. 355 // Profile guaranteed to exist for it to have been locked.
361 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); 356 BlockExtensions(profile_manager->GetProfileByPath(profile_path));
362 #endif // defined(ENABLE_EXTENSIONS) 357 #endif // defined(ENABLE_EXTENSIONS)
363 358
364 chrome::HideTaskManager(); 359 chrome::HideTaskManager();
365 UserManager::Show(profile_path, 360 UserManager::Show(profile_path,
366 profiles::USER_MANAGER_NO_TUTORIAL, 361 profiles::USER_MANAGER_NO_TUTORIAL,
367 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 362 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
(...skipping 26 matching lines...) Expand all
394 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); 389 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
395 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain; 390 hosted_domain = account_tracker->GetAccountInfo(account_id).hosted_domain;
396 } 391 }
397 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then, 392 // TODO(mlerman): Prohibit only users who authenticate using SAML. Until then,
398 // prohibited users who use hosted domains (aside from google.com). 393 // prohibited users who use hosted domains (aside from google.com).
399 if (hosted_domain != Profile::kNoHostedDomainFound && 394 if (hosted_domain != Profile::kNoHostedDomainFound &&
400 hosted_domain != "google.com") { 395 hosted_domain != "google.com") {
401 return false; 396 return false;
402 } 397 }
403 398
404 // Lock only when there is at least one supervised user on the machine. 399 const ProfileInfoCache& cache =
405 std::vector<ProfileAttributesEntry*> entries = 400 g_browser_process->profile_manager()->GetProfileInfoCache();
406 g_browser_process->profile_manager()->GetProfileAttributesStorage(). 401 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
407 GetAllProfilesAttributes(); 402 if (cache.ProfileIsSupervisedAtIndex(i))
408 for (ProfileAttributesEntry* entry : entries) {
409 if (entry->IsSupervised())
410 return true; 403 return true;
411 } 404 }
412 return false; 405 return false;
413 } 406 }
414 407
415 void CreateSystemProfileForUserManager( 408 void CreateSystemProfileForUserManager(
416 const base::FilePath& profile_path_to_focus, 409 const base::FilePath& profile_path_to_focus,
417 profiles::UserManagerTutorialMode tutorial_mode, 410 profiles::UserManagerTutorialMode tutorial_mode,
418 profiles::UserManagerProfileSelected profile_open_action, 411 profiles::UserManagerProfileSelected profile_open_action,
419 const base::Callback<void(Profile*, const std::string&)>& callback) { 412 const base::Callback<void(Profile*, const std::string&)>& callback) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 PrefService* local_state = g_browser_process->local_state(); 531 PrefService* local_state = g_browser_process->local_state();
539 const bool dismissed = local_state->GetBoolean( 532 const bool dismissed = local_state->GetBoolean(
540 prefs::kProfileAvatarRightClickTutorialDismissed); 533 prefs::kProfileAvatarRightClickTutorialDismissed);
541 534
542 // Don't show the tutorial if it's already been dismissed or if right-clicking 535 // Don't show the tutorial if it's already been dismissed or if right-clicking
543 // wouldn't show any targets. 536 // wouldn't show any targets.
544 return !dismissed && HasProfileSwitchTargets(profile); 537 return !dismissed && HasProfileSwitchTargets(profile);
545 } 538 }
546 539
547 } // namespace profiles 540 } // namespace profiles
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_shortcut_manager_win.cc ('k') | chrome/browser/profiles/profiles_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698