| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 int64 running_size = 0; | 120 int64 running_size = 0; |
| 121 base::FileEnumerator iter(directory, false, base::FileEnumerator::FILES, | 121 base::FileEnumerator iter(directory, false, base::FileEnumerator::FILES, |
| 122 pattern); | 122 pattern); |
| 123 while (!iter.Next().empty()) | 123 while (!iter.Next().empty()) |
| 124 running_size += iter.GetInfo().GetSize(); | 124 running_size += iter.GetInfo().GetSize(); |
| 125 return running_size; | 125 return running_size; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Simple task to log the size of the current profile. | 128 // Simple task to log the size of the current profile. |
| 129 void ProfileSizeTask(const base::FilePath& path, int enabled_app_count) { | 129 void ProfileSizeTask(const base::FilePath& path, int enabled_app_count) { |
| 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 130 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 131 const int64 kBytesInOneMB = 1024 * 1024; | 131 const int64 kBytesInOneMB = 1024 * 1024; |
| 132 | 132 |
| 133 int64 size = ComputeFilesSize(path, FILE_PATH_LITERAL("*")); | 133 int64 size = ComputeFilesSize(path, FILE_PATH_LITERAL("*")); |
| 134 int size_MB = static_cast<int>(size / kBytesInOneMB); | 134 int size_MB = static_cast<int>(size / kBytesInOneMB); |
| 135 UMA_HISTOGRAM_COUNTS_10000("Profile.TotalSize", size_MB); | 135 UMA_HISTOGRAM_COUNTS_10000("Profile.TotalSize", size_MB); |
| 136 | 136 |
| 137 size = ComputeFilesSize(path, FILE_PATH_LITERAL("History")); | 137 size = ComputeFilesSize(path, FILE_PATH_LITERAL("History")); |
| 138 size_MB = static_cast<int>(size / kBytesInOneMB); | 138 size_MB = static_cast<int>(size / kBytesInOneMB); |
| 139 UMA_HISTOGRAM_COUNTS_10000("Profile.HistorySize", size_MB); | 139 UMA_HISTOGRAM_COUNTS_10000("Profile.HistorySize", size_MB); |
| 140 | 140 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 size_t ProfileManager::GetNumberOfProfiles() { | 390 size_t ProfileManager::GetNumberOfProfiles() { |
| 391 return GetProfileInfoCache().GetNumberOfProfiles(); | 391 return GetProfileInfoCache().GetNumberOfProfiles(); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void ProfileManager::CreateProfileAsync( | 394 void ProfileManager::CreateProfileAsync( |
| 395 const base::FilePath& profile_path, | 395 const base::FilePath& profile_path, |
| 396 const CreateCallback& callback, | 396 const CreateCallback& callback, |
| 397 const base::string16& name, | 397 const base::string16& name, |
| 398 const base::string16& icon_url, | 398 const base::string16& icon_url, |
| 399 const std::string& supervised_user_id) { | 399 const std::string& supervised_user_id) { |
| 400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 400 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 401 TRACE_EVENT1("browser,startup", | 401 TRACE_EVENT1("browser,startup", |
| 402 "ProfileManager::CreateProfileAsync", | 402 "ProfileManager::CreateProfileAsync", |
| 403 "profile_path", | 403 "profile_path", |
| 404 profile_path.AsUTF8Unsafe()); | 404 profile_path.AsUTF8Unsafe()); |
| 405 | 405 |
| 406 // Make sure that this profile is not pending deletion. | 406 // Make sure that this profile is not pending deletion. |
| 407 if (IsProfileMarkedForDeletion(profile_path)) { | 407 if (IsProfileMarkedForDeletion(profile_path)) { |
| 408 if (!callback.is_null()) | 408 if (!callback.is_null()) |
| 409 callback.Run(NULL, Profile::CREATE_STATUS_LOCAL_FAIL); | 409 callback.Run(NULL, Profile::CREATE_STATUS_LOCAL_FAIL); |
| 410 return; | 410 return; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 return (profile_info && profile_info->created) ? profile_info->profile.get() | 569 return (profile_info && profile_info->created) ? profile_info->profile.get() |
| 570 : nullptr; | 570 : nullptr; |
| 571 } | 571 } |
| 572 | 572 |
| 573 // static | 573 // static |
| 574 base::FilePath ProfileManager::CreateMultiProfileAsync( | 574 base::FilePath ProfileManager::CreateMultiProfileAsync( |
| 575 const base::string16& name, | 575 const base::string16& name, |
| 576 const base::string16& icon_url, | 576 const base::string16& icon_url, |
| 577 const CreateCallback& callback, | 577 const CreateCallback& callback, |
| 578 const std::string& supervised_user_id) { | 578 const std::string& supervised_user_id) { |
| 579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 579 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 580 | 580 |
| 581 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 581 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 582 | 582 |
| 583 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); | 583 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); |
| 584 | 584 |
| 585 profile_manager->CreateProfileAsync(new_path, | 585 profile_manager->CreateProfileAsync(new_path, |
| 586 callback, | 586 callback, |
| 587 name, | 587 name, |
| 588 icon_url, | 588 icon_url, |
| 589 supervised_user_id); | 589 supervised_user_id); |
| 590 return new_path; | 590 return new_path; |
| 591 } | 591 } |
| 592 | 592 |
| 593 // static | 593 // static |
| 594 base::FilePath ProfileManager::GetGuestProfilePath() { | 594 base::FilePath ProfileManager::GetGuestProfilePath() { |
| 595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 595 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 596 | 596 |
| 597 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 597 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 598 | 598 |
| 599 base::FilePath guest_path = profile_manager->user_data_dir(); | 599 base::FilePath guest_path = profile_manager->user_data_dir(); |
| 600 return guest_path.Append(chrome::kGuestProfileDir); | 600 return guest_path.Append(chrome::kGuestProfileDir); |
| 601 } | 601 } |
| 602 | 602 |
| 603 // static | 603 // static |
| 604 base::FilePath ProfileManager::GetSystemProfilePath() { | 604 base::FilePath ProfileManager::GetSystemProfilePath() { |
| 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 605 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 606 | 606 |
| 607 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 607 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 608 | 608 |
| 609 base::FilePath system_path = profile_manager->user_data_dir(); | 609 base::FilePath system_path = profile_manager->user_data_dir(); |
| 610 return system_path.Append(chrome::kSystemProfileDir); | 610 return system_path.Append(chrome::kSystemProfileDir); |
| 611 } | 611 } |
| 612 | 612 |
| 613 base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() { | 613 base::FilePath ProfileManager::GenerateNextProfileDirectoryPath() { |
| 614 PrefService* local_state = g_browser_process->local_state(); | 614 PrefService* local_state = g_browser_process->local_state(); |
| 615 DCHECK(local_state); | 615 DCHECK(local_state); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 return; | 723 return; |
| 724 } | 724 } |
| 725 #endif // defined(OS_MACOSX) | 725 #endif // defined(OS_MACOSX) |
| 726 | 726 |
| 727 FinishDeletingProfile(profile_dir, last_non_supervised_profile_path); | 727 FinishDeletingProfile(profile_dir, last_non_supervised_profile_path); |
| 728 } | 728 } |
| 729 | 729 |
| 730 // static | 730 // static |
| 731 void ProfileManager::CleanUpStaleProfiles( | 731 void ProfileManager::CleanUpStaleProfiles( |
| 732 const std::vector<base::FilePath>& profile_paths) { | 732 const std::vector<base::FilePath>& profile_paths) { |
| 733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 733 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 734 | 734 |
| 735 for (std::vector<base::FilePath>::const_iterator it = profile_paths.begin(); | 735 for (std::vector<base::FilePath>::const_iterator it = profile_paths.begin(); |
| 736 it != profile_paths.end(); ++it) { | 736 it != profile_paths.end(); ++it) { |
| 737 NukeProfileFromDisk(*it); | 737 NukeProfileFromDisk(*it); |
| 738 } | 738 } |
| 739 } | 739 } |
| 740 | 740 |
| 741 void ProfileManager::AutoloadProfiles() { | 741 void ProfileManager::AutoloadProfiles() { |
| 742 // If running in the background is disabled for the browser, do not autoload | 742 // If running in the background is disabled for the browser, do not autoload |
| 743 // any profiles. | 743 // any profiles. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 profile_paths.insert(profile_path); | 940 profile_paths.insert(profile_path); |
| 941 profile_list->Append(new base::StringValue(profile_path)); | 941 profile_list->Append(new base::StringValue(profile_path)); |
| 942 } | 942 } |
| 943 } | 943 } |
| 944 } | 944 } |
| 945 } | 945 } |
| 946 | 946 |
| 947 void ProfileManager::OnProfileCreated(Profile* profile, | 947 void ProfileManager::OnProfileCreated(Profile* profile, |
| 948 bool success, | 948 bool success, |
| 949 bool is_new_profile) { | 949 bool is_new_profile) { |
| 950 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 950 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 951 | 951 |
| 952 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); | 952 ProfilesInfoMap::iterator iter = profiles_info_.find(profile->GetPath()); |
| 953 DCHECK(iter != profiles_info_.end()); | 953 DCHECK(iter != profiles_info_.end()); |
| 954 ProfileInfo* info = iter->second.get(); | 954 ProfileInfo* info = iter->second.get(); |
| 955 | 955 |
| 956 std::vector<CreateCallback> callbacks; | 956 std::vector<CreateCallback> callbacks; |
| 957 info->callbacks.swap(callbacks); | 957 info->callbacks.swap(callbacks); |
| 958 | 958 |
| 959 // Invoke CREATED callback for normal profiles. | 959 // Invoke CREATED callback for normal profiles. |
| 960 bool go_off_the_record = ShouldGoOffTheRecord(profile); | 960 bool go_off_the_record = ShouldGoOffTheRecord(profile); |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); | 1419 FinishDeletingProfile(profile_to_delete_path, new_active_profile_path); |
| 1420 if (!original_callback.is_null()) | 1420 if (!original_callback.is_null()) |
| 1421 original_callback.Run(loaded_profile, status); | 1421 original_callback.Run(loaded_profile, status); |
| 1422 } | 1422 } |
| 1423 | 1423 |
| 1424 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1424 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 1425 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1425 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 1426 } | 1426 } |
| OLD | NEW |