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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 #endif | 496 #endif |
497 | 497 |
498 // Pending, need to insert it alphabetically. | 498 // Pending, need to insert it alphabetically. |
499 profiles.push_back(std::pair<FilePath, string16>(file_path, name)); | 499 profiles.push_back(std::pair<FilePath, string16>(file_path, name)); |
500 } | 500 } |
501 | 501 |
502 std::sort(profiles.begin(), profiles.end(), CompareProfilePathAndName); | 502 std::sort(profiles.begin(), profiles.end(), CompareProfilePathAndName); |
503 return profiles; | 503 return profiles; |
504 } | 504 } |
505 | 505 |
506 ProfileInfoCache& ProfileManager::GetProfileInfoCache() { | 506 ProfileInfoInterface& ProfileManager::GetProfileInfo() { |
| 507 return GetMutableProfileInfo(); |
| 508 } |
| 509 |
| 510 ProfileInfoCache& ProfileManager::GetMutableProfileInfo() { |
507 if (!profile_info_cache_.get()) { | 511 if (!profile_info_cache_.get()) { |
508 FilePath user_data_dir; | 512 FilePath user_data_dir; |
509 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 513 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
510 profile_info_cache_.reset(new ProfileInfoCache( | 514 profile_info_cache_.reset(new ProfileInfoCache( |
511 g_browser_process->local_state(), user_data_dir)); | 515 g_browser_process->local_state(), user_data_dir)); |
512 } | 516 } |
513 return *profile_info_cache_.get(); | 517 return *profile_info_cache_.get(); |
514 } | 518 } |
515 | 519 |
516 void ProfileManager::AddProfileToCache(Profile* profile) { | 520 void ProfileManager::AddProfileToCache(Profile* profile) { |
517 ProfileInfoCache& cache = GetProfileInfoCache(); | 521 ProfileInfoCache& cache = GetMutableProfileInfo(); |
518 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 522 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
519 return; | 523 return; |
520 | 524 |
521 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) | 525 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) |
522 return; | 526 return; |
523 | 527 |
524 if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) { | 528 if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) { |
525 cache.AddProfileToCache( | 529 cache.AddProfileToCache( |
526 profile->GetPath(), | 530 profile->GetPath(), |
527 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), 0); | 531 l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), 0); |
(...skipping 18 matching lines...) Expand all Loading... |
546 return go_off_the_record; | 550 return go_off_the_record; |
547 } | 551 } |
548 | 552 |
549 void ProfileManager::ScheduleProfileForDeletion(const FilePath& profile_dir) { | 553 void ProfileManager::ScheduleProfileForDeletion(const FilePath& profile_dir) { |
550 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we | 554 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we |
551 // start deleting the profile instance we need to close background apps too. | 555 // start deleting the profile instance we need to close background apps too. |
552 Profile* profile = GetProfileByPath(profile_dir); | 556 Profile* profile = GetProfileByPath(profile_dir); |
553 if (profile) | 557 if (profile) |
554 BrowserList::CloseAllBrowsersWithProfile(profile); | 558 BrowserList::CloseAllBrowsersWithProfile(profile); |
555 profiles_to_delete_.push_back(profile_dir); | 559 profiles_to_delete_.push_back(profile_dir); |
556 ProfileInfoCache& cache = GetProfileInfoCache(); | 560 GetMutableProfileInfo().DeleteProfileFromCache(profile_dir); |
557 cache.DeleteProfileFromCache(profile_dir); | |
558 } | 561 } |
559 | 562 |
560 // static | 563 // static |
561 bool ProfileManager::IsMultipleProfilesEnabled() { | 564 bool ProfileManager::IsMultipleProfilesEnabled() { |
562 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS) | 565 #if (defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) |
563 return true; | 566 return true; |
564 #endif | 567 #endif |
565 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); | 568 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles); |
566 } | 569 } |
OLD | NEW |