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