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

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

Issue 929073002: Only return fully initialized profiles in ProfileManager::GetProfileByPath. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: cleanup Created 5 years, 10 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
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe(); 371 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe();
372 return profile; 372 return profile;
373 } 373 }
374 374
375 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { 375 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) {
376 TRACE_EVENT0("browser", "ProfileManager::GetProfile"); 376 TRACE_EVENT0("browser", "ProfileManager::GetProfile");
377 377
378 // If the profile is already loaded (e.g., chrome.exe launched twice), just 378 // If the profile is already loaded (e.g., chrome.exe launched twice), just
379 // return it. 379 // return it.
380 Profile* profile = GetProfileByPath(profile_dir); 380 Profile* profile = GetProfileByPath(profile_dir);
381 if (NULL != profile) 381 if (profile)
382 return profile; 382 return profile;
383 return CreateAndInitializeProfile(profile_dir); 383 return CreateAndInitializeProfile(profile_dir);
384 } 384 }
385 385
386 size_t ProfileManager::GetNumberOfProfiles() { 386 size_t ProfileManager::GetNumberOfProfiles() {
387 return GetProfileInfoCache().GetNumberOfProfiles(); 387 return GetProfileInfoCache().GetNumberOfProfiles();
388 } 388 }
389 389
390 void ProfileManager::CreateProfileAsync( 390 void ProfileManager::CreateProfileAsync(
391 const base::FilePath& profile_path, 391 const base::FilePath& profile_path,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 std::vector<Profile*> ProfileManager::GetLoadedProfiles() const { 545 std::vector<Profile*> ProfileManager::GetLoadedProfiles() const {
546 std::vector<Profile*> profiles; 546 std::vector<Profile*> profiles;
547 for (ProfilesInfoMap::const_iterator iter = profiles_info_.begin(); 547 for (ProfilesInfoMap::const_iterator iter = profiles_info_.begin();
548 iter != profiles_info_.end(); ++iter) { 548 iter != profiles_info_.end(); ++iter) {
549 if (iter->second->created) 549 if (iter->second->created)
550 profiles.push_back(iter->second->profile.get()); 550 profiles.push_back(iter->second->profile.get());
551 } 551 }
552 return profiles; 552 return profiles;
553 } 553 }
554 554
555 Profile* ProfileManager::GetProfileByPathInternal(
556 const base::FilePath& path) const {
557 TRACE_EVENT0("browser", "ProfileManager::GetProfileByPathInternal");
558 ProfileInfo* profile_info = GetProfileInfoByPath(path);
559 return profile_info ? profile_info->profile.get() : nullptr;
560 }
561
555 Profile* ProfileManager::GetProfileByPath(const base::FilePath& path) const { 562 Profile* ProfileManager::GetProfileByPath(const base::FilePath& path) const {
556 TRACE_EVENT0("browser", "ProfileManager::GetProfileByPath"); 563 TRACE_EVENT0("browser", "ProfileManager::GetProfileByPath");
557 ProfileInfo* profile_info = GetProfileInfoByPath(path); 564 ProfileInfo* profile_info = GetProfileInfoByPath(path);
558 return profile_info ? profile_info->profile.get() : NULL; 565 return profile_info && profile_info->created ? profile_info->profile.get()
Pam (message me for reviews) 2015/02/23 12:02:02 nit: This would be slightly clearer with the condi
Bernhard Bauer 2015/02/23 18:42:13 Done (in https://codereview.chromium.org/953453002
566 : nullptr;
559 } 567 }
560 568
561 // static 569 // static
562 base::FilePath ProfileManager::CreateMultiProfileAsync( 570 base::FilePath ProfileManager::CreateMultiProfileAsync(
563 const base::string16& name, 571 const base::string16& name,
564 const base::string16& icon_url, 572 const base::string16& icon_url,
565 const CreateCallback& callback, 573 const CreateCallback& callback,
566 const std::string& supervised_user_id) { 574 const std::string& supervised_user_id) {
567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
568 576
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // If we don't have a mounted profile directory we're in trouble. 858 // If we don't have a mounted profile directory we're in trouble.
851 // TODO(davemoore) Once we have better api this check should ensure that 859 // TODO(davemoore) Once we have better api this check should ensure that
852 // our profile directory is the one that's mounted, and that it's mounted 860 // our profile directory is the one that's mounted, and that it's mounted
853 // as the current user. 861 // as the current user.
854 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted( 862 chromeos::DBusThreadManager::Get()->GetCryptohomeClient()->IsMounted(
855 base::Bind(&CheckCryptohomeIsMounted)); 863 base::Bind(&CheckCryptohomeIsMounted));
856 864
857 // Confirm that we hadn't loaded the new profile previously. 865 // Confirm that we hadn't loaded the new profile previously.
858 base::FilePath default_profile_dir = user_data_dir_.Append( 866 base::FilePath default_profile_dir = user_data_dir_.Append(
859 GetInitialProfileDir()); 867 GetInitialProfileDir());
860 CHECK(!GetProfileByPath(default_profile_dir)) 868 CHECK(!GetProfileByPathInternal(default_profile_dir))
861 << "The default profile was loaded before we mounted the cryptohome."; 869 << "The default profile was loaded before we mounted the cryptohome.";
862 } 870 }
863 return; 871 return;
864 } 872 }
865 #endif 873 #endif
866 bool save_active_profiles = false; 874 bool save_active_profiles = false;
867 switch (type) { 875 switch (type) {
868 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: { 876 case chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST: {
869 // Ignore any browsers closing from now on. 877 // Ignore any browsers closing from now on.
870 closing_all_browsers_ = true; 878 closing_all_browsers_ = true;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 return GetProfile(default_profile_dir); 1124 return GetProfile(default_profile_dir);
1117 #endif 1125 #endif
1118 } 1126 }
1119 1127
1120 bool ProfileManager::AddProfile(Profile* profile) { 1128 bool ProfileManager::AddProfile(Profile* profile) {
1121 TRACE_EVENT0("browser", "ProfileManager::AddProfile"); 1129 TRACE_EVENT0("browser", "ProfileManager::AddProfile");
1122 DCHECK(profile); 1130 DCHECK(profile);
1123 1131
1124 // Make sure that we're not loading a profile with the same ID as a profile 1132 // Make sure that we're not loading a profile with the same ID as a profile
1125 // that's already loaded. 1133 // that's already loaded.
1126 if (GetProfileByPath(profile->GetPath())) { 1134 if (GetProfileByPathInternal(profile->GetPath())) {
1127 NOTREACHED() << "Attempted to add profile with the same path (" << 1135 NOTREACHED() << "Attempted to add profile with the same path (" <<
1128 profile->GetPath().value() << 1136 profile->GetPath().value() <<
1129 ") as an already-loaded profile."; 1137 ") as an already-loaded profile.";
1130 return false; 1138 return false;
1131 } 1139 }
1132 1140
1133 RegisterProfile(profile, true); 1141 RegisterProfile(profile, true);
1134 InitProfileUserPrefs(profile); 1142 InitProfileUserPrefs(profile);
1135 DoFinalInit(profile, ShouldGoOffTheRecord(profile)); 1143 DoFinalInit(profile, ShouldGoOffTheRecord(profile));
1136 return true; 1144 return true;
1137 } 1145 }
1138 1146
1139 Profile* ProfileManager::CreateAndInitializeProfile( 1147 Profile* ProfileManager::CreateAndInitializeProfile(
1140 const base::FilePath& profile_dir) { 1148 const base::FilePath& profile_dir) {
1141 TRACE_EVENT0("browser", "ProfileManager::CreateAndInitializeProfile"); 1149 TRACE_EVENT0("browser", "ProfileManager::CreateAndInitializeProfile");
1142 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Profile.CreateAndInitializeProfile"); 1150 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Profile.CreateAndInitializeProfile");
1151
1152 // CHECK that we are not trying to load the same profile twice, to prevent
1153 // profile corruption. Note that this check also covers the case when we have
1154 // already started loading the profile but it is not fully initialized yet,
1155 // which would make Bad Things happen if we returned it.
1156 CHECK(!GetProfileByPathInternal(profile_dir));
1143 Profile* profile = CreateProfileHelper(profile_dir); 1157 Profile* profile = CreateProfileHelper(profile_dir);
1144 DCHECK(profile); 1158 DCHECK(profile);
1145 if (profile) { 1159 if (profile) {
1146 bool result = AddProfile(profile); 1160 bool result = AddProfile(profile);
1147 DCHECK(result); 1161 DCHECK(result);
1148 } 1162 }
1149 return profile; 1163 return profile;
1150 } 1164 }
1151 1165
1152 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { 1166 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); 1399 last_non_supervised_profile_path.BaseName().MaybeAsASCII());
1386 FinishDeletingProfile(profile_to_delete_path); 1400 FinishDeletingProfile(profile_to_delete_path);
1387 } 1401 }
1388 } 1402 }
1389 } 1403 }
1390 #endif 1404 #endif
1391 1405
1392 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1406 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1393 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1407 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1394 } 1408 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698