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

Side by Side 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 unified diff | Download patch
OLDNEW
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
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 void OnProfileLoaded(
259 const ProfileManager::ProfileLoadedCallback& client_callback,
260 bool incognito,
261 Profile* profile,
262 Profile::CreateStatus status) {
263 if (status == Profile::CREATE_STATUS_CREATED) {
264 // This is an intermediate state, we will be also called
265 // again with CREATE_STATUS_INITIALIZED once everything is ready
266 // 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.
267 return;
268 }
269 if (status != Profile::CREATE_STATUS_INITIALIZED) {
270 LOG(WARNING) << "Profile not loaded correctly";
271 client_callback.Run(nullptr);
272 return;
273 }
274 DCHECK(profile);
275 client_callback.Run(incognito ? profile->GetOffTheRecordProfile() : profile);
276 }
255 } // namespace 277 } // namespace
256 278
257 ProfileManager::ProfileManager(const base::FilePath& user_data_dir) 279 ProfileManager::ProfileManager(const base::FilePath& user_data_dir)
258 : user_data_dir_(user_data_dir), 280 : user_data_dir_(user_data_dir),
259 logged_in_(false), 281 logged_in_(false),
260 #if !defined(OS_ANDROID) 282 #if !defined(OS_ANDROID)
261 browser_list_observer_(this), 283 browser_list_observer_(this),
262 #endif 284 #endif
263 closing_all_browsers_(false) { 285 closing_all_browsers_(false) {
264 #if defined(OS_CHROMEOS) 286 #if defined(OS_CHROMEOS)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 Profile* profile = GetProfileByPath(profile_dir); 419 Profile* profile = GetProfileByPath(profile_dir);
398 if (profile) 420 if (profile)
399 return profile; 421 return profile;
400 return CreateAndInitializeProfile(profile_dir); 422 return CreateAndInitializeProfile(profile_dir);
401 } 423 }
402 424
403 size_t ProfileManager::GetNumberOfProfiles() { 425 size_t ProfileManager::GetNumberOfProfiles() {
404 return GetProfileInfoCache().GetNumberOfProfiles(); 426 return GetProfileInfoCache().GetNumberOfProfiles();
405 } 427 }
406 428
429 void ProfileManager::LoadProfile(const std::string& profile_name,
430 bool incognito,
431 const ProfileLoadedCallback& callback) {
432 const base::FilePath profile_path = user_data_dir().AppendASCII(profile_name);
433
434 ProfileAttributesEntry* entry = nullptr;
435 if (!GetProfileAttributesStorage().GetProfileAttributesWithPath(profile_path,
436 &entry)) {
437 callback.Run(nullptr);
438 LOG(ERROR) << "Loading a profile path that does not exist";
439 return;
440 }
441 CreateProfileAsync(profile_path,
442 base::Bind(&OnProfileLoaded, callback, incognito),
443 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.
444 }
445
407 void ProfileManager::CreateProfileAsync( 446 void ProfileManager::CreateProfileAsync(
408 const base::FilePath& profile_path, 447 const base::FilePath& profile_path,
409 const CreateCallback& callback, 448 const CreateCallback& callback,
410 const base::string16& name, 449 const base::string16& name,
411 const std::string& icon_url, 450 const std::string& icon_url,
412 const std::string& supervised_user_id) { 451 const std::string& supervised_user_id) {
413 DCHECK_CURRENTLY_ON(BrowserThread::UI); 452 DCHECK_CURRENTLY_ON(BrowserThread::UI);
414 TRACE_EVENT1("browser,startup", 453 TRACE_EVENT1("browser,startup",
415 "ProfileManager::CreateProfileAsync", 454 "ProfileManager::CreateProfileAsync",
416 "profile_path", 455 "profile_path",
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 1594
1556 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); 1595 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path);
1557 if (!original_callback.is_null()) 1596 if (!original_callback.is_null())
1558 original_callback.Run(loaded_profile, status); 1597 original_callback.Run(loaded_profile, status);
1559 } 1598 }
1560 #endif // !defined(OS_ANDROID) 1599 #endif // !defined(OS_ANDROID)
1561 1600
1562 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1601 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1563 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1602 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1564 } 1603 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698