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

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

Issue 129293002: Removing GetDefaultProfileOrOffTheRecord and GetDefaultProfile(<path>) from ProfileManager's (publi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
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_manager.h" 5 #include "chrome/browser/profiles/profile_manager.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 ++it) { 210 ++it) {
211 NukeProfileFromDisk(*it); 211 NukeProfileFromDisk(*it);
212 } 212 }
213 ProfilesToDelete().clear(); 213 ProfilesToDelete().clear();
214 } 214 }
215 215
216 // static 216 // static
217 // TODO(skuhne): Remove this method once all clients are migrated. 217 // TODO(skuhne): Remove this method once all clients are migrated.
218 Profile* ProfileManager::GetDefaultProfile() { 218 Profile* ProfileManager::GetDefaultProfile() {
219 ProfileManager* profile_manager = g_browser_process->profile_manager(); 219 ProfileManager* profile_manager = g_browser_process->profile_manager();
220 return profile_manager->GetDefaultProfile(profile_manager->user_data_dir_); 220 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(
221 profile_manager->user_data_dir_);
221 } 222 }
222 223
223 // static 224 // static
224 // TODO(skuhne): Remove this method once all clients are migrated.
225 Profile* ProfileManager::GetDefaultProfileOrOffTheRecord() {
226 return GetDefaultProfile();
227 }
228
229 // static
230 Profile* ProfileManager::GetLastUsedProfile() { 225 Profile* ProfileManager::GetLastUsedProfile() {
231 ProfileManager* profile_manager = g_browser_process->profile_manager(); 226 ProfileManager* profile_manager = g_browser_process->profile_manager();
232 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_); 227 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_);
233 } 228 }
234 229
235 // static 230 // static
236 Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() { 231 Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
237 Profile* profile = GetLastUsedProfile(); 232 Profile* profile = GetLastUsedProfile();
238 if (IncognitoModePrefs::GetAvailability(profile->GetPrefs()) == 233 if (IncognitoModePrefs::GetAvailability(profile->GetPrefs()) ==
239 IncognitoModePrefs::FORCED) { 234 IncognitoModePrefs::FORCED) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 relative_profile_dir = 325 relative_profile_dir =
331 relative_profile_dir.AppendASCII(chrome::kInitialProfile); 326 relative_profile_dir.AppendASCII(chrome::kInitialProfile);
332 return relative_profile_dir; 327 return relative_profile_dir;
333 } 328 }
334 329
335 Profile* ProfileManager::GetLastUsedProfile( 330 Profile* ProfileManager::GetLastUsedProfile(
336 const base::FilePath& user_data_dir) { 331 const base::FilePath& user_data_dir) {
337 #if defined(OS_CHROMEOS) 332 #if defined(OS_CHROMEOS)
338 // Use default login profile if user has not logged in yet. 333 // Use default login profile if user has not logged in yet.
339 if (!logged_in_) { 334 if (!logged_in_) {
340 return GetDefaultProfile(user_data_dir); 335 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir);
341 } else { 336 } else {
342 // CrOS multi-profiles implementation is different so GetLastUsedProfile 337 // CrOS multi-profiles implementation is different so GetLastUsedProfile
343 // has custom implementation too. 338 // has custom implementation too.
344 base::FilePath profile_dir; 339 base::FilePath profile_dir;
345 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 340 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
346 if (command_line.HasSwitch(switches::kMultiProfiles)) { 341 if (command_line.HasSwitch(switches::kMultiProfiles)) {
347 // In case of multi-profiles we ignore "last used profile" preference 342 // In case of multi-profiles we ignore "last used profile" preference
348 // since it may refer to profile that has been in use in previous session. 343 // since it may refer to profile that has been in use in previous session.
349 // That profile dir may not be mounted in this session so instead return 344 // That profile dir may not be mounted in this session so instead return
350 // active profile from current session. 345 // active profile from current session.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 if (!profile_manager->IsLoggedIn() || !chromeos::UserManager::IsInitialized()) 416 if (!profile_manager->IsLoggedIn() || !chromeos::UserManager::IsInitialized())
422 return GetDefaultProfile(); 417 return GetDefaultProfile();
423 chromeos::UserManager* manager = chromeos::UserManager::Get(); 418 chromeos::UserManager* manager = chromeos::UserManager::Get();
424 // Note: The user manager will take care of guest profiles. 419 // Note: The user manager will take care of guest profiles.
425 return manager->GetProfileByUser(manager->GetActiveUser()); 420 return manager->GetProfileByUser(manager->GetActiveUser());
426 #else 421 #else
427 return GetDefaultProfile(); 422 return GetDefaultProfile();
428 #endif 423 #endif
429 } 424 }
430 425
431 Profile* ProfileManager::GetDefaultProfile(
432 const base::FilePath& user_data_dir) {
433 #if defined(OS_CHROMEOS)
434 base::FilePath default_profile_dir(user_data_dir);
435 if (logged_in_) {
436 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
437 } else {
438 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir);
439 }
440 #else
441 base::FilePath default_profile_dir(user_data_dir);
442 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
443 #endif
444 #if defined(OS_CHROMEOS)
445 if (!logged_in_) {
446 Profile* profile = GetProfile(default_profile_dir);
447 // For cros, return the OTR profile so we never accidentally keep
448 // user data in an unencrypted profile. But doing this makes
449 // many of the browser and ui tests fail. We do return the OTR profile
450 // if the login-profile switch is passed so that we can test this.
451 if (ShouldGoOffTheRecord(profile))
452 return profile->GetOffTheRecordProfile();
453 DCHECK(!chromeos::UserManager::Get()->IsLoggedInAsGuest());
454 return profile;
455 }
456
457 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir);
458 // Fallback to default off-the-record profile, if user profile has not fully
459 // loaded yet.
460 if (profile_info && !profile_info->created)
461 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir);
462
463 Profile* profile = GetProfile(default_profile_dir);
464 // Some unit tests didn't initialize the UserManager.
465 if (chromeos::UserManager::IsInitialized() &&
466 chromeos::UserManager::Get()->IsLoggedInAsGuest())
467 return profile->GetOffTheRecordProfile();
468 return profile;
469 #else
470 return GetProfile(default_profile_dir);
471 #endif
472 }
473
474 bool ProfileManager::IsValidProfile(Profile* profile) { 426 bool ProfileManager::IsValidProfile(Profile* profile) {
475 for (ProfilesInfoMap::iterator iter = profiles_info_.begin(); 427 for (ProfilesInfoMap::iterator iter = profiles_info_.begin();
476 iter != profiles_info_.end(); ++iter) { 428 iter != profiles_info_.end(); ++iter) {
477 if (iter->second->created) { 429 if (iter->second->created) {
478 Profile* candidate = iter->second->profile.get(); 430 Profile* candidate = iter->second->profile.get();
479 if (candidate == profile || 431 if (candidate == profile ||
480 (candidate->HasOffTheRecordProfile() && 432 (candidate->HasOffTheRecordProfile() &&
481 candidate->GetOffTheRecordProfile() == profile)) { 433 candidate->GetOffTheRecordProfile() == profile)) {
482 return true; 434 return true;
483 } 435 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // Profile has already been created. Run callback immediately. 517 // Profile has already been created. Run callback immediately.
566 callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED); 518 callback.Run(profile, Profile::CREATE_STATUS_INITIALIZED);
567 } else { 519 } else {
568 // Profile is either already in the process of being created, or new. 520 // Profile is either already in the process of being created, or new.
569 // Add callback to the list. 521 // Add callback to the list.
570 info->callbacks.push_back(callback); 522 info->callbacks.push_back(callback);
571 } 523 }
572 } 524 }
573 } 525 }
574 526
527 Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath(
528 const base::FilePath& user_data_dir) {
529 #if defined(OS_CHROMEOS)
530 base::FilePath default_profile_dir(user_data_dir);
531 if (!logged_in_) {
532 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir);
533 Profile* profile = GetProfile(default_profile_dir);
534 // For cros, return the OTR profile so we never accidentally keep
535 // user data in an unencrypted profile. But doing this makes
536 // many of the browser and ui tests fail. We do return the OTR profile
537 // if the login-profile switch is passed so that we can test this.
538 if (ShouldGoOffTheRecord(profile))
539 return profile->GetOffTheRecordProfile();
540 DCHECK(!chromeos::UserManager::Get()->IsLoggedInAsGuest());
541 return profile;
542 }
543
544 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
545 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir);
546 // Fallback to default off-the-record profile, if user profile has not fully
547 // loaded yet.
548 if (profile_info && !profile_info->created)
549 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir);
550
551 Profile* profile = GetProfile(default_profile_dir);
552 // Some unit tests didn't initialize the UserManager.
553 if (chromeos::UserManager::IsInitialized() &&
554 chromeos::UserManager::Get()->IsLoggedInAsGuest())
555 return profile->GetOffTheRecordProfile();
556 return profile;
557 #else
558 base::FilePath default_profile_dir(user_data_dir);
559 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
560 return GetProfile(default_profile_dir);
561 #endif
562 }
563
575 bool ProfileManager::AddProfile(Profile* profile) { 564 bool ProfileManager::AddProfile(Profile* profile) {
576 DCHECK(profile); 565 DCHECK(profile);
577 566
578 // Make sure that we're not loading a profile with the same ID as a profile 567 // Make sure that we're not loading a profile with the same ID as a profile
579 // that's already loaded. 568 // that's already loaded.
580 if (GetProfileByPath(profile->GetPath())) { 569 if (GetProfileByPath(profile->GetPath())) {
581 NOTREACHED() << "Attempted to add profile with the same path (" << 570 NOTREACHED() << "Attempted to add profile with the same path (" <<
582 profile->GetPath().value() << 571 profile->GetPath().value() <<
583 ") as an already-loaded profile."; 572 ") as an already-loaded profile.";
584 return false; 573 return false;
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 ProfileManager::ProfileInfo::ProfileInfo( 1236 ProfileManager::ProfileInfo::ProfileInfo(
1248 Profile* profile, 1237 Profile* profile,
1249 bool created) 1238 bool created)
1250 : profile(profile), 1239 : profile(profile),
1251 created(created) { 1240 created(created) {
1252 } 1241 }
1253 1242
1254 ProfileManager::ProfileInfo::~ProfileInfo() { 1243 ProfileManager::ProfileInfo::~ProfileInfo() {
1255 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); 1244 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release());
1256 } 1245 }
OLDNEW
« chrome/browser/profiles/profile_manager.h ('K') | « chrome/browser/profiles/profile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698