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

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

Issue 2918203002: cros: Fix loading user profile w/o UserSessionManager (Closed)
Patch Set: fix tests, round 2 Created 3 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 profile_manager->user_data_dir()); 480 profile_manager->user_data_dir());
481 // |profile| could be null if the user doesn't have a profile yet and the path 481 // |profile| could be null if the user doesn't have a profile yet and the path
482 // is on a read-only volume (preventing Chrome from making a new one). 482 // is on a read-only volume (preventing Chrome from making a new one).
483 // However, most callers of this function immediately dereference the result 483 // However, most callers of this function immediately dereference the result
484 // which would lead to crashes in a variety of call sites. Assert here to 484 // which would lead to crashes in a variety of call sites. Assert here to
485 // figure out how common this is. http://crbug.com/383019 485 // figure out how common this is. http://crbug.com/383019
486 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe(); 486 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe();
487 return profile; 487 return profile;
488 } 488 }
489 489
490 // static
491 Profile* ProfileManager::CreateInitialProfile() {
492 ProfileManager* const profile_manager = g_browser_process->profile_manager();
493 return profile_manager->GetProfile(profile_manager->user_data_dir().Append(
494 profile_manager->GetInitialProfileDir()));
495 }
496
490 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { 497 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) {
491 TRACE_EVENT0("browser", "ProfileManager::GetProfile"); 498 TRACE_EVENT0("browser", "ProfileManager::GetProfile");
492 499
493 // If the profile is already loaded (e.g., chrome.exe launched twice), just 500 // If the profile is already loaded (e.g., chrome.exe launched twice), just
494 // return it. 501 // return it.
495 Profile* profile = GetProfileByPath(profile_dir); 502 Profile* profile = GetProfileByPath(profile_dir);
496 if (profile) 503 if (profile)
497 return profile; 504 return profile;
498 return CreateAndInitializeProfile(profile_dir); 505 return CreateAndInitializeProfile(profile_dir);
499 } 506 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // since it may refer to profile that has been in use in previous session. 633 // since it may refer to profile that has been in use in previous session.
627 // That profile dir may not be mounted in this session so instead return 634 // That profile dir may not be mounted in this session so instead return
628 // active profile from current session. 635 // active profile from current session.
629 profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir(); 636 profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir();
630 637
631 base::FilePath profile_path(user_data_dir); 638 base::FilePath profile_path(user_data_dir);
632 Profile* profile = GetProfileByPath(profile_path.Append(profile_dir)); 639 Profile* profile = GetProfileByPath(profile_path.Append(profile_dir));
633 // If we get here, it means the user has logged in but the profile has not 640 // If we get here, it means the user has logged in but the profile has not
634 // finished initializing, so treat the user as not having logged in. 641 // finished initializing, so treat the user as not having logged in.
635 if (!profile) { 642 if (!profile) {
636 DLOG(WARNING) << "Calling GetLastUsedProfile() before profile " 643 LOG(WARNING) << "Calling GetLastUsedProfile() before profile "
637 << "initialization is completed. Returning login profile."; 644 << "initialization is completed. Returning login profile.";
638 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir); 645 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir);
639 } 646 }
640 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() : 647 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() :
641 profile; 648 profile;
642 } 649 }
643 #else 650 #else
644 651
645 return GetProfile(GetLastUsedProfileDir(user_data_dir)); 652 return GetProfile(GetLastUsedProfileDir(user_data_dir));
646 #endif 653 #endif
647 } 654 }
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 // many of the browser and ui tests fail. We do return the OTR profile 1328 // many of the browser and ui tests fail. We do return the OTR profile
1322 // if the login-profile switch is passed so that we can test this. 1329 // if the login-profile switch is passed so that we can test this.
1323 if (ShouldGoOffTheRecord(profile)) 1330 if (ShouldGoOffTheRecord(profile))
1324 return profile->GetOffTheRecordProfile(); 1331 return profile->GetOffTheRecordProfile();
1325 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest()); 1332 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest());
1326 return profile; 1333 return profile;
1327 } 1334 }
1328 1335
1329 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); 1336 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
1330 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); 1337 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir);
1331 // Fallback to default off-the-record profile, if user profile has not fully 1338 // Fallback to default off-the-record profile, if user profile is not loaded
1332 // loaded yet. 1339 // or has not fully loaded yet.
emaxx 2017/06/08 19:43:54 nit: "not loaded or has not fully loaded" sounds l
xiyuan 2017/06/08 20:30:40 Changed to "is not started loading or has not full
1333 if (profile_info && !profile_info->created) 1340 if (!profile_info || !profile_info->created)
1334 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); 1341 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir);
1335 1342
1336 Profile* profile = GetProfile(default_profile_dir); 1343 Profile* profile = GetProfile(default_profile_dir);
1337 // Some unit tests didn't initialize the UserManager. 1344 // Some unit tests didn't initialize the UserManager.
1338 if (user_manager::UserManager::IsInitialized() && 1345 if (user_manager::UserManager::IsInitialized() &&
1339 user_manager::UserManager::Get()->IsLoggedInAsGuest()) 1346 user_manager::UserManager::Get()->IsLoggedInAsGuest())
1340 return profile->GetOffTheRecordProfile(); 1347 return profile->GetOffTheRecordProfile();
1341 return profile; 1348 return profile;
1342 #else 1349 #else
1343 base::FilePath default_profile_dir(user_data_dir); 1350 base::FilePath default_profile_dir(user_data_dir);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 1788
1782 const base::FilePath new_active_profile_dir = 1789 const base::FilePath new_active_profile_dir =
1783 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath(); 1790 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath();
1784 FinishDeletingProfile(profile_dir, new_active_profile_dir); 1791 FinishDeletingProfile(profile_dir, new_active_profile_dir);
1785 } 1792 }
1786 #endif // !defined(OS_ANDROID) 1793 #endif // !defined(OS_ANDROID)
1787 1794
1788 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1795 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1789 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1796 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1790 } 1797 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698