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..0adc31e88a79dc40e19eb45a5e5bf408c69769a1 100644 |
--- a/chrome/browser/profiles/profile_manager.cc |
+++ b/chrome/browser/profiles/profile_manager.cc |
@@ -252,6 +252,30 @@ 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 |
Bernhard Bauer
2016/03/14 19:05:34
Nit: Now that NULL is deprecated, use "null" for a
Miguel Garcia
2016/03/17 20:04:07
Done.
|
+// 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); |
+} |
Bernhard Bauer
2016/03/14 19:05:34
Nit: empty line after this one.
Miguel Garcia
2016/03/17 20:04:07
Done.
|
} // namespace |
ProfileManager::ProfileManager(const base::FilePath& user_data_dir) |
@@ -404,6 +428,24 @@ size_t ProfileManager::GetNumberOfProfiles() { |
return GetProfileInfoCache().GetNumberOfProfiles(); |
} |
+void 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"; |
Bernhard Bauer
2016/03/14 19:05:34
This would be a programmer error (i.e. a bug), rig
Miguel Garcia
2016/03/17 20:04:07
I believe this can still happen if there is a prob
Bernhard Bauer
2016/03/18 09:56:12
No, that's the status != Profile::CREATE_STATUS_IN
|
+ return; |
+ } |
+ CreateProfileAsync(profile_path, |
+ base::Bind(&OnProfileLoaded, callback, incognito), |
+ base::string16() /* name */, std::string() /* icon_url */, |
+ std::string() /* supervided_user_id */); |
+} |
+ |
void ProfileManager::CreateProfileAsync( |
const base::FilePath& profile_path, |
const CreateCallback& callback, |