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

Unified Diff: chrome/browser/profiles/profile_manager.cc

Issue 1782443006: Create LoadProfile method in profile_manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_manager.cc
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index a5de32353bfd31510a41fb5424bf5be5538b831b..795c00b7c3237379eea7f730b1bd0011b7c230d9 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -252,6 +252,31 @@ size_t GetEnabledAppCount(Profile* profile) {
#endif // ENABLE_EXTENSIONS
+// Once a profile is loaded through LoadProfile this method is executed.
+// It will then run |client_callback| with the right profile or null if it was
+// unable to load it.
+// It might get called more than once with different values of
+// |status| but only once the profile is fully initialized will
+// |client_callback| be run.
+void OnProfileLoaded(
+ const ProfileManager::ProfileLoadedCallback& client_callback,
+ bool incognito,
+ Profile* profile,
+ Profile::CreateStatus status) {
+ if (status == Profile::CREATE_STATUS_CREATED) {
+ // This is an intermediate state where the profile has been created, but is
+ // not yet initialized. Ignore this and wait for the next state change.
+ return;
+ }
+ if (status != Profile::CREATE_STATUS_INITIALIZED) {
+ LOG(WARNING) << "Profile not loaded correctly";
+ client_callback.Run(nullptr);
+ return;
+ }
+ DCHECK(profile);
+ client_callback.Run(incognito ? profile->GetOffTheRecordProfile() : profile);
+}
+
} // namespace
ProfileManager::ProfileManager(const base::FilePath& user_data_dir)
@@ -404,6 +429,25 @@ size_t ProfileManager::GetNumberOfProfiles() {
return GetProfileInfoCache().GetNumberOfProfiles();
}
+bool ProfileManager::LoadProfile(const std::string& profile_name,
+ bool incognito,
+ const ProfileLoadedCallback& callback) {
+ const base::FilePath profile_path = user_data_dir().AppendASCII(profile_name);
+
+ ProfileAttributesEntry* entry = nullptr;
+ if (!GetProfileAttributesStorage().GetProfileAttributesWithPath(profile_path,
+ &entry)) {
+ callback.Run(nullptr);
+ LOG(ERROR) << "Loading a profile path that does not exist";
+ return false;
+ }
+ CreateProfileAsync(profile_path,
+ base::Bind(&OnProfileLoaded, callback, incognito),
+ base::string16() /* name */, std::string() /* icon_url */,
+ std::string() /* supervided_user_id */);
+ return true;
+}
+
void ProfileManager::CreateProfileAsync(
const base::FilePath& profile_path,
const CreateCallback& callback,
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | chrome/browser/profiles/profile_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698