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

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

Issue 2918203002: cros: Fix loading user profile w/o UserSessionManager (Closed)
Patch Set: for #4 nits 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 // since it may refer to profile that has been in use in previous session. 638 // since it may refer to profile that has been in use in previous session.
632 // That profile dir may not be mounted in this session so instead return 639 // That profile dir may not be mounted in this session so instead return
633 // active profile from current session. 640 // active profile from current session.
634 profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir(); 641 profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir();
635 642
636 base::FilePath profile_path(user_data_dir); 643 base::FilePath profile_path(user_data_dir);
637 Profile* profile = GetProfileByPath(profile_path.Append(profile_dir)); 644 Profile* profile = GetProfileByPath(profile_path.Append(profile_dir));
638 // If we get here, it means the user has logged in but the profile has not 645 // If we get here, it means the user has logged in but the profile has not
639 // finished initializing, so treat the user as not having logged in. 646 // finished initializing, so treat the user as not having logged in.
640 if (!profile) { 647 if (!profile) {
641 DLOG(WARNING) << "Calling GetLastUsedProfile() before profile " 648 LOG(WARNING) << "Calling GetLastUsedProfile() before profile "
642 << "initialization is completed. Returning login profile."; 649 << "initialization is completed. Returning login profile.";
643 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir); 650 return GetActiveUserOrOffTheRecordProfileFromPath(user_data_dir);
644 } 651 }
645 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() : 652 return profile->IsGuestSession() ? profile->GetOffTheRecordProfile() :
646 profile; 653 profile;
647 } 654 }
648 #else 655 #else
649 656
650 return GetProfile(GetLastUsedProfileDir(user_data_dir)); 657 return GetProfile(GetLastUsedProfileDir(user_data_dir));
651 #endif 658 #endif
652 } 659 }
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 // many of the browser and ui tests fail. We do return the OTR profile 1322 // many of the browser and ui tests fail. We do return the OTR profile
1316 // if the login-profile switch is passed so that we can test this. 1323 // if the login-profile switch is passed so that we can test this.
1317 if (ShouldGoOffTheRecord(profile)) 1324 if (ShouldGoOffTheRecord(profile))
1318 return profile->GetOffTheRecordProfile(); 1325 return profile->GetOffTheRecordProfile();
1319 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest()); 1326 DCHECK(!user_manager::UserManager::Get()->IsLoggedInAsGuest());
1320 return profile; 1327 return profile;
1321 } 1328 }
1322 1329
1323 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir()); 1330 default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
1324 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir); 1331 ProfileInfo* profile_info = GetProfileInfoByPath(default_profile_dir);
1325 // Fallback to default off-the-record profile, if user profile has not fully 1332 // Fallback to default off-the-record profile, if user profile is not started
msarda 2017/06/08 23:49:19 ss/is/has
xiyuan 2017/06/12 15:32:54 Done.
1326 // loaded yet. 1333 // loading or has not fully loaded yet.
1327 if (profile_info && !profile_info->created) 1334 if (!profile_info || !profile_info->created)
1328 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir); 1335 default_profile_dir = profiles::GetDefaultProfileDir(user_data_dir);
1329 1336
1330 Profile* profile = GetProfile(default_profile_dir); 1337 Profile* profile = GetProfile(default_profile_dir);
1331 // Some unit tests didn't initialize the UserManager. 1338 // Some unit tests didn't initialize the UserManager.
1332 if (user_manager::UserManager::IsInitialized() && 1339 if (user_manager::UserManager::IsInitialized() &&
1333 user_manager::UserManager::Get()->IsLoggedInAsGuest()) 1340 user_manager::UserManager::Get()->IsLoggedInAsGuest())
1334 return profile->GetOffTheRecordProfile(); 1341 return profile->GetOffTheRecordProfile();
1335 return profile; 1342 return profile;
1336 #else 1343 #else
1337 base::FilePath default_profile_dir(user_data_dir); 1344 base::FilePath default_profile_dir(user_data_dir);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 1772
1766 const base::FilePath new_active_profile_dir = 1773 const base::FilePath new_active_profile_dir =
1767 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath(); 1774 found_entry ? found_entry->GetPath() : GenerateNextProfileDirectoryPath();
1768 FinishDeletingProfile(profile_dir, new_active_profile_dir); 1775 FinishDeletingProfile(profile_dir, new_active_profile_dir);
1769 } 1776 }
1770 #endif // !defined(OS_ANDROID) 1777 #endif // !defined(OS_ANDROID)
1771 1778
1772 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1779 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1773 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1780 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1774 } 1781 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698