| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 return profiles; | 312 return profiles; |
| 313 } | 313 } |
| 314 | 314 |
| 315 Profile* ProfileManager::GetProfile(const FilePath& profile_dir) { | 315 Profile* ProfileManager::GetProfile(const FilePath& profile_dir) { |
| 316 // If the profile is already loaded (e.g., chrome.exe launched twice), just | 316 // If the profile is already loaded (e.g., chrome.exe launched twice), just |
| 317 // return it. | 317 // return it. |
| 318 Profile* profile = GetProfileByPath(profile_dir); | 318 Profile* profile = GetProfileByPath(profile_dir); |
| 319 if (NULL != profile) | 319 if (NULL != profile) |
| 320 return profile; | 320 return profile; |
| 321 | 321 |
| 322 profile = CreateProfile(profile_dir); | 322 profile = CreateProfileHelper(profile_dir); |
| 323 DCHECK(profile); | 323 DCHECK(profile); |
| 324 if (profile) { | 324 if (profile) { |
| 325 bool result = AddProfile(profile); | 325 bool result = AddProfile(profile); |
| 326 DCHECK(result); | 326 DCHECK(result); |
| 327 } | 327 } |
| 328 return profile; | 328 return profile; |
| 329 } | 329 } |
| 330 | 330 |
| 331 void ProfileManager::CreateProfileAsync(const FilePath& user_data_dir, | 331 void ProfileManager::CreateProfileAsync(const FilePath& user_data_dir, |
| 332 ProfileManagerObserver* observer) { | 332 ProfileManagerObserver* observer) { |
| 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 334 ProfilesInfoMap::iterator iter = profiles_info_.find(user_data_dir); | 334 ProfilesInfoMap::iterator iter = profiles_info_.find(user_data_dir); |
| 335 if (iter != profiles_info_.end()) { | 335 if (iter != profiles_info_.end()) { |
| 336 ProfileInfo* info = iter->second.get(); | 336 ProfileInfo* info = iter->second.get(); |
| 337 if (info->created) { | 337 if (info->created) { |
| 338 // Profile has already been created. Call observer immediately. | 338 // Profile has already been created. Call observer immediately. |
| 339 observer->OnProfileCreated( | 339 observer->OnProfileCreated( |
| 340 info->profile.get(), ProfileManagerObserver::STATUS_INITIALIZED); | 340 info->profile.get(), ProfileManagerObserver::STATUS_INITIALIZED); |
| 341 if (observer->DeleteAfter()) | 341 if (observer->DeleteAfter()) |
| 342 delete observer; | 342 delete observer; |
| 343 } else { | 343 } else { |
| 344 // Profile is being created. Add observer to list. | 344 // Profile is being created. Add observer to list. |
| 345 info->observers.push_back(observer); | 345 info->observers.push_back(observer); |
| 346 } | 346 } |
| 347 } else { | 347 } else { |
| 348 // Initiate asynchronous creation process. | 348 // Initiate asynchronous creation process. |
| 349 ProfileInfo* info = | 349 ProfileInfo* info = |
| 350 RegisterProfile(Profile::CreateProfileAsync(user_data_dir, this), | 350 RegisterProfile(CreateProfileAsyncHelper(user_data_dir, this), |
| 351 false); | 351 false); |
| 352 info->observers.push_back(observer); | 352 info->observers.push_back(observer); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 // static | 356 // static |
| 357 void ProfileManager::CreateDefaultProfileAsync( | 357 void ProfileManager::CreateDefaultProfileAsync( |
| 358 ProfileManagerObserver* observer) { | 358 ProfileManagerObserver* observer) { |
| 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 360 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 360 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 if (!command_line.HasSwitch(switches::kDisableWebResources)) | 476 if (!command_line.HasSwitch(switches::kDisableWebResources)) |
| 477 profile->InitPromoResources(); | 477 profile->InitPromoResources(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 void ProfileManager::DoFinalInitLogging(Profile* profile) { | 480 void ProfileManager::DoFinalInitLogging(Profile* profile) { |
| 481 // Log the profile size after a reasonable startup delay. | 481 // Log the profile size after a reasonable startup delay. |
| 482 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, | 482 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, |
| 483 new ProfileSizeTask(profile), 112000); | 483 new ProfileSizeTask(profile), 112000); |
| 484 } | 484 } |
| 485 | 485 |
| 486 Profile* ProfileManager::CreateProfile(const FilePath& path) { | 486 Profile* ProfileManager::CreateProfileHelper(const FilePath& path) { |
| 487 return Profile::CreateProfile(path); | 487 return Profile::CreateProfile(path); |
| 488 } | 488 } |
| 489 | 489 |
| 490 Profile* ProfileManager::CreateProfileAsyncHelper(const FilePath& path, |
| 491 Delegate* delegate) { |
| 492 return Profile::CreateProfileAsync(path, delegate); |
| 493 } |
| 494 |
| 490 void ProfileManager::OnProfileCreated(Profile* profile, bool success) { | 495 void ProfileManager::OnProfileCreated(Profile* profile, bool success) { |
| 491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 492 | 497 |
| 493 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); | 498 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); |
| 494 DCHECK(iter != profiles_info_.end()); | 499 DCHECK(iter != profiles_info_.end()); |
| 495 ProfileInfo* info = iter->second.get(); | 500 ProfileInfo* info = iter->second.get(); |
| 496 | 501 |
| 497 std::vector<ProfileManagerObserver*> observers; | 502 std::vector<ProfileManagerObserver*> observers; |
| 498 info->observers.swap(observers); | 503 info->observers.swap(observers); |
| 499 | 504 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 681 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 677 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 682 const FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 678 } | 683 } |
| 679 | 684 |
| 680 void ProfileManager::RegisterTestingProfile(Profile* profile, | 685 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 681 bool add_to_cache) { | 686 bool add_to_cache) { |
| 682 RegisterProfile(profile, true); | 687 RegisterProfile(profile, true); |
| 683 if (add_to_cache) | 688 if (add_to_cache) |
| 684 AddProfileToCache(profile); | 689 AddProfileToCache(profile); |
| 685 } | 690 } |
| OLD | NEW |