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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // is on a read-only volume (preventing Chrome from making a new one). | 367 // is on a read-only volume (preventing Chrome from making a new one). |
368 // However, most callers of this function immediately dereference the result | 368 // However, most callers of this function immediately dereference the result |
369 // which would lead to crashes in a variety of call sites. Assert here to | 369 // which would lead to crashes in a variety of call sites. Assert here to |
370 // figure out how common this is. http://crbug.com/383019 | 370 // figure out how common this is. http://crbug.com/383019 |
371 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe(); | 371 CHECK(profile) << profile_manager->user_data_dir().AsUTF8Unsafe(); |
372 return profile; | 372 return profile; |
373 } | 373 } |
374 | 374 |
375 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { | 375 Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { |
376 TRACE_EVENT0("browser", "ProfileManager::GetProfile"); | 376 TRACE_EVENT0("browser", "ProfileManager::GetProfile"); |
377 SCOPED_UMA_HISTOGRAM_TIMER("Profile.GetProfile"); | |
378 | 377 |
379 // If the profile is already loaded (e.g., chrome.exe launched twice), just | 378 // If the profile is already loaded (e.g., chrome.exe launched twice), just |
380 // return it. | 379 // return it. |
381 Profile* profile = GetProfileByPath(profile_dir); | 380 Profile* profile = GetProfileByPath(profile_dir); |
382 if (NULL != profile) | 381 if (NULL != profile) |
383 return profile; | 382 return profile; |
384 | 383 return CreateAndInitializeProfile(profile_dir); |
385 profile = CreateProfileHelper(profile_dir); | |
386 DCHECK(profile); | |
387 if (profile) { | |
388 bool result = AddProfile(profile); | |
389 DCHECK(result); | |
390 } | |
391 return profile; | |
392 } | 384 } |
393 | 385 |
394 size_t ProfileManager::GetNumberOfProfiles() { | 386 size_t ProfileManager::GetNumberOfProfiles() { |
395 return GetProfileInfoCache().GetNumberOfProfiles(); | 387 return GetProfileInfoCache().GetNumberOfProfiles(); |
396 } | 388 } |
397 | 389 |
398 void ProfileManager::CreateProfileAsync( | 390 void ProfileManager::CreateProfileAsync( |
399 const base::FilePath& profile_path, | 391 const base::FilePath& profile_path, |
400 const CreateCallback& callback, | 392 const CreateCallback& callback, |
401 const base::string16& name, | 393 const base::string16& name, |
402 const base::string16& icon_url, | 394 const base::string16& icon_url, |
403 const std::string& supervised_user_id) { | 395 const std::string& supervised_user_id) { |
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
405 TRACE_EVENT1("startup", | 397 TRACE_EVENT1("browser,startup", |
406 "ProfileManager::CreateProfileAsync", | 398 "ProfileManager::CreateProfileAsync", |
407 "profile_path", | 399 "profile_path", |
408 profile_path.value().c_str()); | 400 profile_path.MaybeAsASCII()); |
409 | 401 |
410 // Make sure that this profile is not pending deletion. | 402 // Make sure that this profile is not pending deletion. |
411 if (IsProfileMarkedForDeletion(profile_path)) { | 403 if (IsProfileMarkedForDeletion(profile_path)) { |
412 if (!callback.is_null()) | 404 if (!callback.is_null()) |
413 callback.Run(NULL, Profile::CREATE_STATUS_LOCAL_FAIL); | 405 callback.Run(NULL, Profile::CREATE_STATUS_LOCAL_FAIL); |
414 return; | 406 return; |
415 } | 407 } |
416 | 408 |
417 // Create the profile if needed and collect its ProfileInfo. | 409 // Create the profile if needed and collect its ProfileInfo. |
418 ProfilesInfoMap::iterator iter = profiles_info_.find(profile_path); | 410 ProfilesInfoMap::iterator iter = profiles_info_.find(profile_path); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 | 1061 |
1070 // Log the profile size after a reasonable startup delay. | 1062 // Log the profile size after a reasonable startup delay. |
1071 BrowserThread::PostDelayedTask( | 1063 BrowserThread::PostDelayedTask( |
1072 BrowserThread::FILE, FROM_HERE, | 1064 BrowserThread::FILE, FROM_HERE, |
1073 base::Bind(&ProfileSizeTask, profile->GetPath(), enabled_app_count), | 1065 base::Bind(&ProfileSizeTask, profile->GetPath(), enabled_app_count), |
1074 base::TimeDelta::FromSeconds(112)); | 1066 base::TimeDelta::FromSeconds(112)); |
1075 } | 1067 } |
1076 | 1068 |
1077 Profile* ProfileManager::CreateProfileHelper(const base::FilePath& path) { | 1069 Profile* ProfileManager::CreateProfileHelper(const base::FilePath& path) { |
1078 TRACE_EVENT0("browser", "ProfileManager::CreateProfileHelper"); | 1070 TRACE_EVENT0("browser", "ProfileManager::CreateProfileHelper"); |
| 1071 SCOPED_UMA_HISTOGRAM_TIMER("Profile.CreateProfileHelperTime"); |
| 1072 |
1079 return Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); | 1073 return Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); |
1080 } | 1074 } |
1081 | 1075 |
1082 Profile* ProfileManager::CreateProfileAsyncHelper(const base::FilePath& path, | 1076 Profile* ProfileManager::CreateProfileAsyncHelper(const base::FilePath& path, |
1083 Delegate* delegate) { | 1077 Delegate* delegate) { |
1084 return Profile::CreateProfile(path, | 1078 return Profile::CreateProfile(path, |
1085 delegate, | 1079 delegate, |
1086 Profile::CREATE_MODE_ASYNCHRONOUS); | 1080 Profile::CREATE_MODE_ASYNCHRONOUS); |
1087 } | 1081 } |
1088 | 1082 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 ") as an already-loaded profile."; | 1129 ") as an already-loaded profile."; |
1136 return false; | 1130 return false; |
1137 } | 1131 } |
1138 | 1132 |
1139 RegisterProfile(profile, true); | 1133 RegisterProfile(profile, true); |
1140 InitProfileUserPrefs(profile); | 1134 InitProfileUserPrefs(profile); |
1141 DoFinalInit(profile, ShouldGoOffTheRecord(profile)); | 1135 DoFinalInit(profile, ShouldGoOffTheRecord(profile)); |
1142 return true; | 1136 return true; |
1143 } | 1137 } |
1144 | 1138 |
| 1139 Profile* ProfileManager::CreateAndInitializeProfile( |
| 1140 const base::FilePath& profile_dir) { |
| 1141 TRACE_EVENT0("browser", "ProfileManager::CreateAndInitializeProfile"); |
| 1142 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Profile.CreateAndInitializeProfile"); |
| 1143 Profile* profile = CreateProfileHelper(profile_dir); |
| 1144 DCHECK(profile); |
| 1145 if (profile) { |
| 1146 bool result = AddProfile(profile); |
| 1147 DCHECK(result); |
| 1148 } |
| 1149 return profile; |
| 1150 } |
| 1151 |
1145 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { | 1152 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { |
1146 ProfileInfoCache& cache = GetProfileInfoCache(); | 1153 ProfileInfoCache& cache = GetProfileInfoCache(); |
1147 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 1154 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
1148 // start deleting the profile instance we need to close background apps too. | 1155 // start deleting the profile instance we need to close background apps too. |
1149 Profile* profile = GetProfileByPath(profile_dir); | 1156 Profile* profile = GetProfileByPath(profile_dir); |
1150 | 1157 |
1151 if (profile) { | 1158 if (profile) { |
1152 // TODO: Migrate additional code in this block to observe this notification | 1159 // TODO: Migrate additional code in this block to observe this notification |
1153 // instead of being implemented here. | 1160 // instead of being implemented here. |
1154 content::NotificationService::current()->Notify( | 1161 content::NotificationService::current()->Notify( |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); | 1385 last_non_supervised_profile_path.BaseName().MaybeAsASCII()); |
1379 FinishDeletingProfile(profile_to_delete_path); | 1386 FinishDeletingProfile(profile_to_delete_path); |
1380 } | 1387 } |
1381 } | 1388 } |
1382 } | 1389 } |
1383 #endif | 1390 #endif |
1384 | 1391 |
1385 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1392 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
1386 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1393 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
1387 } | 1394 } |
OLD | NEW |