Chromium Code Reviews| 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..d35f29bea8aa9c8e4a03cf6e6208bbe94fb2460b 100644 |
| --- a/chrome/browser/profiles/profile_manager.cc |
| +++ b/chrome/browser/profiles/profile_manager.cc |
| @@ -252,6 +252,28 @@ 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. |
| +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, we will be also called |
| + // again with CREATE_STATUS_INITIALIZED once everything is ready |
| + // so ignore it. |
|
Peter Beverloo
2016/03/11 17:45:15
nit: avoid "we".
// This is an intermediate s
Peter Beverloo
2016/03/11 17:45:15
nit: the description for this function does not ma
Miguel Garcia
2016/03/14 18:29:00
Done.
Miguel Garcia
2016/03/14 18:29:00
Done.
|
| + 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 +426,23 @@ 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"; |
| + return; |
| + } |
| + CreateProfileAsync(profile_path, |
| + base::Bind(&OnProfileLoaded, callback, incognito), |
| + base::string16(), std::string(), std::string()); |
|
Peter Beverloo
2016/03/11 17:45:15
nit: this would benefit from inline comments about
Miguel Garcia
2016/03/14 18:29:00
Done.
|
| +} |
| + |
| void ProfileManager::CreateProfileAsync( |
| const base::FilePath& profile_path, |
| const CreateCallback& callback, |