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

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

Issue 1128173005: Clean up ProfileManager interface. Base URL: https://chromium.googlesource.com/chromium/src@issue479309
Patch Set: sync 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_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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 #include "chromeos/dbus/dbus_thread_manager.h" 104 #include "chromeos/dbus/dbus_thread_manager.h"
105 #include "components/user_manager/user.h" 105 #include "components/user_manager/user.h"
106 #include "components/user_manager/user_manager.h" 106 #include "components/user_manager/user_manager.h"
107 #endif 107 #endif
108 108
109 using base::UserMetricsAction; 109 using base::UserMetricsAction;
110 using content::BrowserThread; 110 using content::BrowserThread;
111 111
112 namespace { 112 namespace {
113 113
114 // Profiles that should be deleted on shutdown.
115 std::vector<base::FilePath>& ProfilesToDelete() {
116 CR_DEFINE_STATIC_LOCAL(std::vector<base::FilePath>, profiles_to_delete, ());
117 return profiles_to_delete;
118 }
119
120 int64 ComputeFilesSize(const base::FilePath& directory, 114 int64 ComputeFilesSize(const base::FilePath& directory,
121 const base::FilePath::StringType& pattern) { 115 const base::FilePath::StringType& pattern) {
122 int64 running_size = 0; 116 int64 running_size = 0;
123 base::FileEnumerator iter(directory, false, base::FileEnumerator::FILES, 117 base::FileEnumerator iter(directory, false, base::FileEnumerator::FILES,
124 pattern); 118 pattern);
125 while (!iter.Next().empty()) 119 while (!iter.Next().empty())
126 running_size += iter.GetInfo().GetSize(); 120 running_size += iter.GetInfo().GetSize();
127 return running_size; 121 return running_size;
128 } 122 }
129 123
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 168
175 size = ComputeFilesSize(path, FILE_PATH_LITERAL("Policy")); 169 size = ComputeFilesSize(path, FILE_PATH_LITERAL("Policy"));
176 size_MB = static_cast<int>(size / kBytesInOneMB); 170 size_MB = static_cast<int>(size / kBytesInOneMB);
177 UMA_HISTOGRAM_COUNTS_10000("Profile.PolicySize", size_MB); 171 UMA_HISTOGRAM_COUNTS_10000("Profile.PolicySize", size_MB);
178 172
179 // Count number of enabled apps in this profile, if we know. 173 // Count number of enabled apps in this profile, if we know.
180 if (enabled_app_count != -1) 174 if (enabled_app_count != -1)
181 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", enabled_app_count); 175 UMA_HISTOGRAM_COUNTS_10000("Profile.AppCount", enabled_app_count);
182 } 176 }
183 177
178 // Profiles that should be deleted on shutdown.
179 std::vector<base::FilePath>& ProfilesToDelete() {
180 CR_DEFINE_STATIC_LOCAL(std::vector<base::FilePath>, profiles_to_delete, ());
181 return profiles_to_delete;
182 }
183
184 void QueueProfileDirectoryForDeletion(const base::FilePath& path) { 184 void QueueProfileDirectoryForDeletion(const base::FilePath& path) {
185 ProfilesToDelete().push_back(path); 185 ProfilesToDelete().push_back(path);
186 } 186 }
187 187
188 bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) { 188 bool IsProfileMarkedForDeletion(const base::FilePath& profile_path) {
189 return std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(), 189 return std::find(ProfilesToDelete().begin(), ProfilesToDelete().end(),
190 profile_path) != ProfilesToDelete().end(); 190 profile_path) != ProfilesToDelete().end();
191 } 191 }
192 192
193 // Physically remove deleted profile directories from disk. 193 // Physically remove deleted profile directories from disk.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 for (std::vector<base::FilePath>::iterator it = 290 for (std::vector<base::FilePath>::iterator it =
291 ProfilesToDelete().begin(); 291 ProfilesToDelete().begin();
292 it != ProfilesToDelete().end(); 292 it != ProfilesToDelete().end();
293 ++it) { 293 ++it) {
294 NukeProfileFromDisk(*it); 294 NukeProfileFromDisk(*it);
295 } 295 }
296 ProfilesToDelete().clear(); 296 ProfilesToDelete().clear();
297 } 297 }
298 298
299 // static 299 // static
300 Profile* ProfileManager::GetLastUsedProfile() {
301 ProfileManager* profile_manager = g_browser_process->profile_manager();
302 return profile_manager->GetLastUsedProfile(profile_manager->user_data_dir_);
303 }
304
305 // static
306 Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
307 Profile* profile = GetLastUsedProfile();
308 if (profile->IsGuestSession() ||
309 profile->IsSystemProfile() ||
310 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) ==
311 IncognitoModePrefs::FORCED) {
312 return profile->GetOffTheRecordProfile();
313 }
314 return profile;
315 }
316
317 // static
318 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() {
319 ProfileManager* profile_manager = g_browser_process->profile_manager();
320 return profile_manager->GetLastOpenedProfiles(
321 profile_manager->user_data_dir_);
322 }
323
324 // static
325 Profile* ProfileManager::GetPrimaryUserProfile() { 300 Profile* ProfileManager::GetPrimaryUserProfile() {
326 ProfileManager* profile_manager = g_browser_process->profile_manager(); 301 ProfileManager* profile_manager = g_browser_process->profile_manager();
327 #if defined(OS_CHROMEOS) 302 #if defined(OS_CHROMEOS)
328 if (!profile_manager->IsLoggedIn() || 303 if (!profile_manager->IsLoggedIn() ||
329 !user_manager::UserManager::IsInitialized()) 304 !user_manager::UserManager::IsInitialized())
330 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( 305 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath();
331 profile_manager->user_data_dir());
332 user_manager::UserManager* manager = user_manager::UserManager::Get(); 306 user_manager::UserManager* manager = user_manager::UserManager::Get();
333 // Note: The ProfileHelper will take care of guest profiles. 307 // Note: The ProfileHelper will take care of guest profiles.
334 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe( 308 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(
335 manager->GetPrimaryUser()); 309 manager->GetPrimaryUser());
336 #else 310 #else
337 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( 311 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath();
338 profile_manager->user_data_dir());
339 #endif 312 #endif
340 } 313 }
341 314
342 // static 315 // static
343 Profile* ProfileManager::GetActiveUserProfile() { 316 Profile* ProfileManager::GetActiveUserProfile() {
344 ProfileManager* profile_manager = g_browser_process->profile_manager(); 317 ProfileManager* profile_manager = g_browser_process->profile_manager();
345 #if defined(OS_CHROMEOS) 318 #if defined(OS_CHROMEOS)
346 if (!profile_manager) 319 if (!profile_manager)
347 return NULL; 320 return NULL;
348 321
349 if (!profile_manager->IsLoggedIn() || 322 if (!profile_manager->IsLoggedIn() ||
350 !user_manager::UserManager::IsInitialized()) { 323 !user_manager::UserManager::IsInitialized()) {
351 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( 324 return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath();
352 profile_manager->user_data_dir());
353 } 325 }
354 326
355 user_manager::UserManager* manager = user_manager::UserManager::Get(); 327 user_manager::UserManager* manager = user_manager::UserManager::Get();
356 const user_manager::User* user = manager->GetActiveUser(); 328 const user_manager::User* user = manager->GetActiveUser();
357 // To avoid an endless loop (crbug.com/334098) we have to additionally check 329 // To avoid an endless loop (crbug.com/334098) we have to additionally check
358 // if the profile of the user was already created. If the profile was not yet 330 // if the profile of the user was already created. If the profile was not yet
359 // created we load the profile using the profile directly. 331 // created we load the profile using the profile directly.
360 // TODO: This should be cleaned up with the new profile manager. 332 // TODO: This should be cleaned up with the new profile manager.
361 if (user && user->is_profile_created()) 333 if (user && user->is_profile_created())
362 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); 334 return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user);
363 335
364 #endif 336 #endif
365 Profile* profile = 337 Profile* profile =
366 profile_manager->GetActiveUserOrOffTheRecordProfileFromPath( 338 profile_manager->GetActiveUserOrOffTheRecordProfileFromPath();
367 profile_manager->user_data_dir());
368 // |profile| could be null if the user doesn't have a profile yet and the path 339 // |profile| could be null if the user doesn't have a profile yet and the path
369 // is on a read-only volume (preventing Chrome from making a new one). 340 // is on a read-only volume (preventing Chrome from making a new one).
370 // However, most callers of this function immediately dereference the result 341 // However, most callers of this function immediately dereference the result
371 // which would lead to crashes in a variety of call sites. Assert here to 342 // which would lead to crashes in a variety of call sites. Assert here to
372 // figure out how common this is. http://crbug.com/383019 343 // figure out how common this is. http://crbug.com/383019
373 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe(); 344 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe();
374 return profile; 345 return profile;
375 } 346 }
376 347
377 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { 348 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 #if defined(OS_CHROMEOS) 446 #if defined(OS_CHROMEOS)
476 if (logged_in_) { 447 if (logged_in_) {
477 return chromeos::ProfileHelper::Get()->GetActiveUserProfileDir(); 448 return chromeos::ProfileHelper::Get()->GetActiveUserProfileDir();
478 } 449 }
479 #endif 450 #endif
480 base::FilePath relative_profile_dir; 451 base::FilePath relative_profile_dir;
481 // TODO(mirandac): should not automatically be default profile. 452 // TODO(mirandac): should not automatically be default profile.
482 return relative_profile_dir.AppendASCII(chrome::kInitialProfile); 453 return relative_profile_dir.AppendASCII(chrome::kInitialProfile);
483 } 454 }
484 455
485 Profile* ProfileManager::GetLastUsedProfile( 456 Profile* ProfileManager::GetLastUsedProfile() {
486 const base::FilePath& user_data_dir) {
487 #if defined(OS_CHROMEOS) 457 #if defined(OS_CHROMEOS)
488 // Use default login profile if user has not logged in yet. 458 // Use default login profile if user has not logged in yet.
489 if (!logged_in_) { 459 if (!logged_in_)
490 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir); 460 return GetActiveUserOrOffTheRecordProfileFromPath();
491 } else {
492 // CrOS multi-profiles implementation is different so GetLastUsedProfile
493 // has custom implementation too.
494 base::FilePath profile_dir;
495 // In case of multi-profiles we ignore "last used profile" preference
496 // since it may refer to profile that has been in use in previous session.
497 // That profile dir may not be mounted in this session so instead return
498 // active profile from current session.
499 profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir();
500 461
501 base::FilePath profile_path(user_data_dir); 462 // CrOS multi-profiles implementation is different so GetLastUsedProfile
502 Profile* profile = GetProfile(profile_path.Append(profile_dir)); 463 // has custom implementation too.
503 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() : 464 // In case of multi-profiles we ignore "last used profile" preference
504 profile; 465 // since it may refer to profile that has been in use in previous session.
505 } 466 // That profile dir may not be mounted in this session so instead return
467 // active profile from current session.
468 base::FilePath profile_dir =
469 chromeos::ProfileHelper::Get()->GetActiveUserProfileDir();
470
471 Profile* profile = GetProfile(user_data_dir_.Append(profile_dir));
472 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile()
473 : profile;
474 #else
475 return GetProfile(GetLastUsedProfileDir());
506 #endif 476 #endif
507
508 return GetProfile(GetLastUsedProfileDir(user_data_dir));
509 } 477 }
510 478
511 base::FilePath ProfileManager::GetLastUsedProfileDir( 479 Profile* ProfileManager::GetLastUsedProfileAllowedByPolicy() {
512 const base::FilePath& user_data_dir) { 480 Profile* profile = GetLastUsedProfile();
513 return user_data_dir.AppendASCII(GetLastUsedProfileName()); 481 if (profile->IsGuestSession() ||
482 profile->IsSystemProfile() ||
483 IncognitoModePrefs::GetAvailability(profile->GetPrefs()) ==
484 IncognitoModePrefs::FORCED) {
485 return profile->GetOffTheRecordProfile();
486 }
487 return profile;
488 }
489
490 base::FilePath ProfileManager::GetLastUsedProfileDir() {
491 return user_data_dir_.AppendASCII(GetLastUsedProfileName());
514 } 492 }
515 493
516 std::string ProfileManager::GetLastUsedProfileName() { 494 std::string ProfileManager::GetLastUsedProfileName() {
517 PrefService* local_state = g_browser_process->local_state(); 495 PrefService* local_state = g_browser_process->local_state();
518 DCHECK(local_state); 496 DCHECK(local_state);
519 const std::string last_used_profile_name = 497 const std::string last_used_profile_name =
520 local_state->GetString(prefs::kProfileLastUsed); 498 local_state->GetString(prefs::kProfileLastUsed);
521 if (!last_used_profile_name.empty()) 499 if (!last_used_profile_name.empty())
522 return last_used_profile_name; 500 return last_used_profile_name;
523 501
524 return chrome::kInitialProfile; 502 return chrome::kInitialProfile;
525 } 503 }
526 504
527 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles( 505 std::vector<Profile*> ProfileManager::GetLastOpenedProfiles() {
528 const base::FilePath& user_data_dir) {
529 PrefService* local_state = g_browser_process->local_state(); 506 PrefService* local_state = g_browser_process->local_state();
530 DCHECK(local_state); 507 DCHECK(local_state);
531 508
532 std::vector<Profile*> to_return; 509 std::vector<Profile*> to_return;
533 if (local_state->HasPrefPath(prefs::kProfilesLastActive) && 510 if (local_state->HasPrefPath(prefs::kProfilesLastActive) &&
534 local_state->GetList(prefs::kProfilesLastActive)) { 511 local_state->GetList(prefs::kProfilesLastActive)) {
535 // Make a copy because the list might change in the calls to GetProfile. 512 // Make a copy because the list might change in the calls to GetProfile.
536 scoped_ptr<base::ListValue> profile_list( 513 scoped_ptr<base::ListValue> profile_list(
537 local_state->GetList(prefs::kProfilesLastActive)->DeepCopy()); 514 local_state->GetList(prefs::kProfilesLastActive)->DeepCopy());
538 base::ListValue::const_iterator it; 515 base::ListValue::const_iterator it;
539 std::string profile; 516 std::string profile;
540 for (it = profile_list->begin(); it != profile_list->end(); ++it) { 517 for (it = profile_list->begin(); it != profile_list->end(); ++it) {
541 if (!(*it)->GetAsString(&profile) || profile.empty()) { 518 if (!(*it)->GetAsString(&profile) || profile.empty()) {
542 LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive; 519 LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive;
543 continue; 520 continue;
544 } 521 }
545 to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile))); 522 to_return.push_back(GetProfile(user_data_dir_.AppendASCII(profile)));
546 } 523 }
547 } 524 }
548 return to_return; 525 return to_return;
549 } 526 }
550 527
551 std::vector<Profile*> ProfileManager::GetLoadedProfiles() const { 528 std::vector<Profile*> ProfileManager::GetLoadedProfiles() const {
552 std::vector<Profile*> profiles; 529 std::vector<Profile*> profiles;
553 for (ProfilesInfoMap::const_iterator iter = profiles_info_.begin(); 530 for (ProfilesInfoMap::const_iterator iter = profiles_info_.begin();
554 iter != profiles_info_.end(); ++iter) { 531 iter != profiles_info_.end(); ++iter) {
555 if (iter->second->created) 532 if (iter->second->created)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() { 592 base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() {
616 PrefService* local_state = g_browser_process->local_state(); 593 PrefService* local_state = g_browser_process->local_state();
617 DCHECK(local_state); 594 DCHECK(local_state);
618 595
619 DCHECK(profiles::IsMultipleProfilesEnabled()); 596 DCHECK(profiles::IsMultipleProfilesEnabled());
620 597
621 // Create the next profile in the next available directory slot. 598 // Create the next profile in the next available directory slot.
622 int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated); 599 int next_directory = local_state->GetInteger(prefs::kProfilesNumCreated);
623 std::string profile_name = chrome::kMultiProfileDirPrefix; 600 std::string profile_name = chrome::kMultiProfileDirPrefix;
624 profile_name.append(base::IntToString(next_directory)); 601 profile_name.append(base::IntToString(next_directory));
625 base::FilePath new_path = user_data_dir_; 602 base::FilePath new_path = user_data_dir_.AppendASCII(profile_name);
626 #if defined(OS_WIN)
627 new_path = new_path.Append(base::ASCIIToUTF16(profile_name));
628 #else
629 new_path = new_path.Append(profile_name);
630 #endif
631 local_state->SetInteger(prefs::kProfilesNumCreated, ++next_directory); 603 local_state->SetInteger(prefs::kProfilesNumCreated, ++next_directory);
632 return new_path; 604 return new_path;
633 } 605 }
634 606
635 ProfileInfoCache& ProfileManager::GetProfileInfoCache() { 607 ProfileInfoCache& ProfileManager::GetProfileInfoCache() {
636 TRACE_EVENT0("browser", "ProfileManager::GetProfileInfoCache"); 608 TRACE_EVENT0("browser", "ProfileManager::GetProfileInfoCache");
637 if (!profile_info_cache_) { 609 if (!profile_info_cache_) {
638 profile_info_cache_.reset(new ProfileInfoCache( 610 profile_info_cache_.reset(new ProfileInfoCache(
639 g_browser_process->local_state(), user_data_dir_)); 611 g_browser_process->local_state(), user_data_dir_));
640 } 612 }
(...skipping 29 matching lines...) Expand all
670 // Make sure that this profile is not pending deletion, and is not 642 // Make sure that this profile is not pending deletion, and is not
671 // legacy-supervised. 643 // legacy-supervised.
672 if (cur_path != profile_dir && 644 if (cur_path != profile_dir &&
673 !cache.ProfileIsLegacySupervisedAtIndex(i) && 645 !cache.ProfileIsLegacySupervisedAtIndex(i) &&
674 !IsProfileMarkedForDeletion(cur_path)) { 646 !IsProfileMarkedForDeletion(cur_path)) {
675 last_non_supervised_profile_path = cur_path; 647 last_non_supervised_profile_path = cur_path;
676 break; 648 break;
677 } 649 }
678 } 650 }
679 651
680 base::FilePath new_path;
681 if (last_non_supervised_profile_path.empty()) { 652 if (last_non_supervised_profile_path.empty()) {
682 // If we are using --new-avatar-menu, then assign the default 653 // If we are using --new-avatar-menu, then assign the default
683 // placeholder avatar and name. Otherwise, use random ones. 654 // placeholder avatar and name. Otherwise, use random ones.
684 bool is_new_avatar_menu = switches::IsNewAvatarMenu(); 655 base::string16 new_profile_name;
685 int avatar_index = profiles::GetPlaceholderAvatarIndex(); 656 base::string16 new_avatar_url;
686 base::string16 new_avatar_url = is_new_avatar_menu ? 657 if (switches::IsNewAvatarMenu()) {
687 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(avatar_index)) : 658 int avatar_index = profiles::GetPlaceholderAvatarIndex();
688 base::string16(); 659 new_profile_name = cache.ChooseNameForNewProfile(avatar_index);
689 base::string16 new_profile_name = is_new_avatar_menu ? 660 new_avatar_url =
690 cache.ChooseNameForNewProfile(avatar_index) : base::string16(); 661 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(avatar_index));
662 }
691 663
692 new_path = GenerateNextProfileDirectoryPath(); 664 base::FilePath new_path = GenerateNextProfileDirectoryPath();
693 CreateProfileAsync(new_path, 665 CreateProfileAsync(new_path,
694 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, 666 base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
695 base::Unretained(this), 667 base::Unretained(this),
696 profile_dir, 668 profile_dir,
697 new_path, 669 new_path,
698 callback), 670 callback),
699 new_profile_name, 671 new_profile_name,
700 new_avatar_url, 672 new_avatar_url,
701 std::string()); 673 std::string());
702 674
703 ProfileMetrics::LogProfileAddNewUser( 675 ProfileMetrics::LogProfileAddNewUser(
704 ProfileMetrics::ADD_NEW_USER_LAST_DELETED); 676 ProfileMetrics::ADD_NEW_USER_LAST_DELETED);
705 return; 677 return;
706 } 678 }
707 679
708 #if defined(OS_MACOSX) 680 #if defined(OS_MACOSX)
709 // On the Mac, the browser process is not killed when all browser windows are 681 // On the Mac, the browser process is not killed when all browser windows are
710 // closed, so just in case we are deleting the active profile, and no other 682 // closed, so just in case we are deleting the active profile, and no other
711 // profile has been loaded, we must pre-load a next one. 683 // profile has been loaded, we must pre-load a next one.
712 const base::FilePath last_used_profile = 684 const base::FilePath last_used_profile = GetLastUsedProfileDir();
713 GetLastUsedProfileDir(user_data_dir_);
714 if (last_used_profile == profile_dir || 685 if (last_used_profile == profile_dir ||
715 last_used_profile == GetGuestProfilePath()) { 686 last_used_profile == GetGuestProfilePath()) {
716 CreateProfileAsync(last_non_supervised_profile_path, 687 CreateProfileAsync(last_non_supervised_profile_path,
717 base::Bind(&ProfileManager::OnNewActiveProfileLoaded, 688 base::Bind(&ProfileManager::OnNewActiveProfileLoaded,
718 base::Unretained(this), 689 base::Unretained(this),
719 profile_dir, 690 profile_dir,
720 last_non_supervised_profile_path, 691 last_non_supervised_profile_path,
721 callback), 692 callback),
722 base::string16(), 693 base::string16(),
723 base::string16(), 694 base::string16(),
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 return Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); 1086 return Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
1116 } 1087 }
1117 1088
1118 Profile* ProfileManager::CreateProfileAsyncHelper(const base::FilePath& path, 1089 Profile* ProfileManager::CreateProfileAsyncHelper(const base::FilePath& path,
1119 Delegate* delegate) { 1090 Delegate* delegate) {
1120 return Profile::CreateProfile(path, 1091 return Profile::CreateProfile(path,
1121 delegate, 1092 delegate,
1122 Profile::CREATE_MODE_ASYNCHRONOUS); 1093 Profile::CREATE_MODE_ASYNCHRONOUS);
1123 } 1094 }
1124 1095
1125 Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath( 1096 Profile* ProfileManager::GetActiveUserOrOffTheRecordProfileFromPath() {
1126 const base::FilePath& user_data_dir) {
1127 #if defined(OS_CHROMEOS) 1097 #if defined(OS_CHROMEOS)
1128 base::FilePath default_profile_dir(user_data_dir);
1129 if (!logged_in_) { 1098 if (!logged_in_) {
1130 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); 1099 base::FilePath default_profile_dir =
1100 profiles::GetDefaultProfileDir(user_data_dir_);
1131 Profile* profile = GetProfile(default_profile_dir); 1101 Profile* profile = GetProfile(default_profile_dir);
1132 // For cros, return the OTR profile so we never accidentally keep 1102 // For cros, return the OTR profile so we never accidentally keep
1133 // user data in an unencrypted profile. But doing this makes 1103 // user data in an unencrypted profile. But doing this makes
1134 // many of the browser and ui tests fail. We do return the OTR profile 1104 // many of the browser and ui tests fail. We do return the OTR profile
1135 // if the login-profile switch is passed so that we can test this. 1105 // if the login-profile switch is passed so that we can test this.
1136 if (ShouldGoOffTheRecord(profile)) 1106 if (ShouldGoOffTheRecord(profile))
1137 return profile->GetOffTheRecordProfile(); 1107 return profile->GetOffTheRecordProfile();
1138 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest()); 1108 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest());
1139 return profile; 1109 return profile;
1140 } 1110 }
1141 1111
1142 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); 1112 base::FilePath default_profile_dir =
1113 user_data_dir_.Append(GetInitialProfileDir());
1143 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); 1114 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir);
1144 // Fallback to default off-the-record profile, if user profile has not fully 1115 // Fallback to default off-the-record profile, if user profile has not fully
1145 // loaded yet. 1116 // loaded yet.
1146 if (profile_info && !profile_info->created) 1117 if (profile_info && !profile_info->created)
1147 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); 1118 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir_);
1148 1119
1149 Profile* profile = GetProfile(default_profile_dir); 1120 Profile* profile = GetProfile(default_profile_dir);
1150 // Some unit tests didn't initialize the UserManager. 1121 // Some unit tests didn't initialize the UserManager.
1151 if (user_manager::UserManager::IsInitialized() && 1122 if (user_manager::UserManager::IsInitialized() &&
1152 user_manager::UserManager::Get()->IsLoggedInAsGuest()) 1123 user_manager::UserManager::Get()->IsLoggedInAsGuest())
1153 return profile->GetOffTheRecordProfile(); 1124 return profile->GetOffTheRecordProfile();
1154 return profile; 1125 return profile;
1155 #else 1126 #else
1156 base::FilePath default_profile_dir(user_data_dir); 1127 base::FilePath default_profile_dir =
1157 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); 1128 user_data_dir_.Append(GetInitialProfileDir());
1158 return GetProfile(default_profile_dir); 1129 return GetProfile(default_profile_dir);
1159 #endif 1130 #endif
1160 } 1131 }
1161 1132
1162 bool ProfileManager::AddProfile(Profile* profile) { 1133 bool ProfileManager::AddProfile(Profile* profile) {
1163 TRACE_EVENT0("browser", "ProfileManager::AddProfile"); 1134 TRACE_EVENT0("browser", "ProfileManager::AddProfile");
1164 TRACK_SCOPED_REGION("Startup", "ProfileManager::AddProfile"); 1135 TRACK_SCOPED_REGION("Startup", "ProfileManager::AddProfile");
1165 1136
1166 DCHECK(profile); 1137 DCHECK(profile);
1167 1138
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 } 1440 }
1470 1441
1471 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1442 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1472 if (!original_callback.is_null()) 1443 if (!original_callback.is_null())
1473 original_callback.Run(loaded_profile, status); 1444 original_callback.Run(loaded_profile, status);
1474 } 1445 }
1475 1446
1476 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1447 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1477 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1448 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1478 } 1449 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698