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 |
| 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 } |
| 279 |
255 } // namespace | 280 } // namespace |
256 | 281 |
257 ProfileManager::ProfileManager(const base::FilePath& user_data_dir) | 282 ProfileManager::ProfileManager(const base::FilePath& user_data_dir) |
258 : user_data_dir_(user_data_dir), | 283 : user_data_dir_(user_data_dir), |
259 logged_in_(false), | 284 logged_in_(false), |
260 #if !defined(OS_ANDROID) | 285 #if !defined(OS_ANDROID) |
261 browser_list_observer_(this), | 286 browser_list_observer_(this), |
262 #endif | 287 #endif |
263 closing_all_browsers_(false) { | 288 closing_all_browsers_(false) { |
264 #if defined(OS_CHROMEOS) | 289 #if defined(OS_CHROMEOS) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 Profile* profile = GetProfileByPath(profile_dir); | 422 Profile* profile = GetProfileByPath(profile_dir); |
398 if (profile) | 423 if (profile) |
399 return profile; | 424 return profile; |
400 return CreateAndInitializeProfile(profile_dir); | 425 return CreateAndInitializeProfile(profile_dir); |
401 } | 426 } |
402 | 427 |
403 size_t ProfileManager::GetNumberOfProfiles() { | 428 size_t ProfileManager::GetNumberOfProfiles() { |
404 return GetProfileInfoCache().GetNumberOfProfiles(); | 429 return GetProfileInfoCache().GetNumberOfProfiles(); |
405 } | 430 } |
406 | 431 |
| 432 bool ProfileManager::LoadProfile(const std::string& profile_name, |
| 433 bool incognito, |
| 434 const ProfileLoadedCallback& callback) { |
| 435 const base::FilePath profile_path = user_data_dir().AppendASCII(profile_name); |
| 436 |
| 437 ProfileAttributesEntry* entry = nullptr; |
| 438 if (!GetProfileAttributesStorage().GetProfileAttributesWithPath(profile_path, |
| 439 &entry)) { |
| 440 callback.Run(nullptr); |
| 441 LOG(ERROR) << "Loading a profile path that does not exist"; |
| 442 return false; |
| 443 } |
| 444 CreateProfileAsync(profile_path, |
| 445 base::Bind(&OnProfileLoaded, callback, incognito), |
| 446 base::string16() /* name */, std::string() /* icon_url */, |
| 447 std::string() /* supervided_user_id */); |
| 448 return true; |
| 449 } |
| 450 |
407 void ProfileManager::CreateProfileAsync( | 451 void ProfileManager::CreateProfileAsync( |
408 const base::FilePath& profile_path, | 452 const base::FilePath& profile_path, |
409 const CreateCallback& callback, | 453 const CreateCallback& callback, |
410 const base::string16& name, | 454 const base::string16& name, |
411 const std::string& icon_url, | 455 const std::string& icon_url, |
412 const std::string& supervised_user_id) { | 456 const std::string& supervised_user_id) { |
413 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 457 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
414 TRACE_EVENT1("browser,startup", | 458 TRACE_EVENT1("browser,startup", |
415 "ProfileManager::CreateProfileAsync", | 459 "ProfileManager::CreateProfileAsync", |
416 "profile_path", | 460 "profile_path", |
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 | 1599 |
1556 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); | 1600 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); |
1557 if (!original_callback.is_null()) | 1601 if (!original_callback.is_null()) |
1558 original_callback.Run(loaded_profile, status); | 1602 original_callback.Run(loaded_profile, status); |
1559 } | 1603 } |
1560 #endif // !defined(OS_ANDROID) | 1604 #endif // !defined(OS_ANDROID) |
1561 | 1605 |
1562 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1606 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1563 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1607 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1564 } | 1608 } |
OLD | NEW |