OLD | NEW |
---|---|
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 <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 if ((*iter)->is_app() && | 245 if ((*iter)->is_app() && |
246 (*iter)->location() != extensions::Manifest::COMPONENT) { | 246 (*iter)->location() != extensions::Manifest::COMPONENT) { |
247 ++installed_apps; | 247 ++installed_apps; |
248 } | 248 } |
249 } | 249 } |
250 return installed_apps; | 250 return installed_apps; |
251 } | 251 } |
252 | 252 |
253 #endif // ENABLE_EXTENSIONS | 253 #endif // ENABLE_EXTENSIONS |
254 | 254 |
255 // Once a profile is loaded through LoadProfile this method is executed. | |
256 // 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.
| |
257 // unable to load it. | |
258 // It might get called more than once with different values of | |
259 // |status| but only once the profile is fully initialized will | |
260 // |client_callback| be run. | |
261 void OnProfileLoaded( | |
262 const ProfileManager::ProfileLoadedCallback& client_callback, | |
263 bool incognito, | |
264 Profile* profile, | |
265 Profile::CreateStatus status) { | |
266 if (status == Profile::CREATE_STATUS_CREATED) { | |
267 // This is an intermediate state where the profile has been created, but is | |
268 // not yet initialized. Ignore this and wait for the next state change. | |
269 return; | |
270 } | |
271 if (status != Profile::CREATE_STATUS_INITIALIZED) { | |
272 LOG(WARNING) << "Profile not loaded correctly"; | |
273 client_callback.Run(nullptr); | |
274 return; | |
275 } | |
276 DCHECK(profile); | |
277 client_callback.Run(incognito ? profile->GetOffTheRecordProfile() : profile); | |
278 } | |
Bernhard Bauer
2016/03/14 19:05:34
Nit: empty line after this one.
Miguel Garcia
2016/03/17 20:04:07
Done.
| |
255 } // namespace | 279 } // namespace |
256 | 280 |
257 ProfileManager::ProfileManager(const base::FilePath& user_data_dir) | 281 ProfileManager::ProfileManager(const base::FilePath& user_data_dir) |
258 : user_data_dir_(user_data_dir), | 282 : user_data_dir_(user_data_dir), |
259 logged_in_(false), | 283 logged_in_(false), |
260 #if !defined(OS_ANDROID) | 284 #if !defined(OS_ANDROID) |
261 browser_list_observer_(this), | 285 browser_list_observer_(this), |
262 #endif | 286 #endif |
263 closing_all_browsers_(false) { | 287 closing_all_browsers_(false) { |
264 #if defined(OS_CHROMEOS) | 288 #if defined(OS_CHROMEOS) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 Profile* profile = GetProfileByPath(profile_dir); | 421 Profile* profile = GetProfileByPath(profile_dir); |
398 if (profile) | 422 if (profile) |
399 return profile; | 423 return profile; |
400 return CreateAndInitializeProfile(profile_dir); | 424 return CreateAndInitializeProfile(profile_dir); |
401 } | 425 } |
402 | 426 |
403 size_t ProfileManager::GetNumberOfProfiles() { | 427 size_t ProfileManager::GetNumberOfProfiles() { |
404 return GetProfileInfoCache().GetNumberOfProfiles(); | 428 return GetProfileInfoCache().GetNumberOfProfiles(); |
405 } | 429 } |
406 | 430 |
431 void ProfileManager::LoadProfile(const std::string& profile_name, | |
432 bool incognito, | |
433 const ProfileLoadedCallback& callback) { | |
434 const base::FilePath profile_path = user_data_dir().AppendASCII(profile_name); | |
435 | |
436 ProfileAttributesEntry* entry = nullptr; | |
437 if (!GetProfileAttributesStorage().GetProfileAttributesWithPath(profile_path, | |
438 &entry)) { | |
439 callback.Run(nullptr); | |
440 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
| |
441 return; | |
442 } | |
443 CreateProfileAsync(profile_path, | |
444 base::Bind(&OnProfileLoaded, callback, incognito), | |
445 base::string16() /* name */, std::string() /* icon_url */, | |
446 std::string() /* supervided_user_id */); | |
447 } | |
448 | |
407 void ProfileManager::CreateProfileAsync( | 449 void ProfileManager::CreateProfileAsync( |
408 const base::FilePath& profile_path, | 450 const base::FilePath& profile_path, |
409 const CreateCallback& callback, | 451 const CreateCallback& callback, |
410 const base::string16& name, | 452 const base::string16& name, |
411 const std::string& icon_url, | 453 const std::string& icon_url, |
412 const std::string& supervised_user_id) { | 454 const std::string& supervised_user_id) { |
413 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 455 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
414 TRACE_EVENT1("browser,startup", | 456 TRACE_EVENT1("browser,startup", |
415 "ProfileManager::CreateProfileAsync", | 457 "ProfileManager::CreateProfileAsync", |
416 "profile_path", | 458 "profile_path", |
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1555 | 1597 |
1556 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); | 1598 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); |
1557 if (!original_callback.is_null()) | 1599 if (!original_callback.is_null()) |
1558 original_callback.Run(loaded_profile, status); | 1600 original_callback.Run(loaded_profile, status); |
1559 } | 1601 } |
1560 #endif // !defined(OS_ANDROID) | 1602 #endif // !defined(OS_ANDROID) |
1561 | 1603 |
1562 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1604 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1563 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1605 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1564 } | 1606 } |
OLD | NEW |