| 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/test/base/testing_profile_manager.h" | 5 #include "chrome/test/base/testing_profile_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 9 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 10 #include "chrome/browser/prefs/pref_service_syncable.h" | 10 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 11 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 const std::string kGuestProfileName = "Guest"; |
| 17 |
| 16 namespace testing { | 18 namespace testing { |
| 17 | 19 |
| 18 class ProfileManager : public ::ProfileManagerWithoutInit { | 20 class ProfileManager : public ::ProfileManagerWithoutInit { |
| 19 public: | 21 public: |
| 20 explicit ProfileManager(const base::FilePath& user_data_dir) | 22 explicit ProfileManager(const base::FilePath& user_data_dir) |
| 21 : ::ProfileManagerWithoutInit(user_data_dir) {} | 23 : ::ProfileManagerWithoutInit(user_data_dir) {} |
| 22 | 24 |
| 23 protected: | 25 protected: |
| 24 virtual Profile* CreateProfileHelper( | 26 virtual Profile* CreateProfileHelper( |
| 25 const base::FilePath& file_path) OVERRIDE { | 27 const base::FilePath& file_path) OVERRIDE { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 88 } |
| 87 | 89 |
| 88 TestingProfile* TestingProfileManager::CreateTestingProfile( | 90 TestingProfile* TestingProfileManager::CreateTestingProfile( |
| 89 const std::string& name) { | 91 const std::string& name) { |
| 90 DCHECK(called_set_up_); | 92 DCHECK(called_set_up_); |
| 91 return CreateTestingProfile(name, scoped_ptr<PrefServiceSyncable>(), | 93 return CreateTestingProfile(name, scoped_ptr<PrefServiceSyncable>(), |
| 92 UTF8ToUTF16(name), 0, std::string(), | 94 UTF8ToUTF16(name), 0, std::string(), |
| 93 TestingProfile::TestingFactories()); | 95 TestingProfile::TestingFactories()); |
| 94 } | 96 } |
| 95 | 97 |
| 98 TestingProfile* TestingProfileManager::CreateGuestProfile() { |
| 99 DCHECK(called_set_up_); |
| 100 |
| 101 // Create the profile and register it. |
| 102 TestingProfile::Builder builder; |
| 103 builder.SetGuestSession(); |
| 104 builder.SetPath(ProfileManager::GetGuestProfilePath()); |
| 105 |
| 106 // Add the guest profile to the profile manager, but not to the info cache. |
| 107 TestingProfile* profile = builder.Build().release(); |
| 108 profile->set_profile_name(kGuestProfileName); |
| 109 profile_manager_->AddProfile(profile); // Takes ownership. |
| 110 profile_manager_->SetGuestProfilePrefs(profile); |
| 111 |
| 112 testing_profiles_.insert(std::make_pair(kGuestProfileName, profile)); |
| 113 |
| 114 return profile; |
| 115 } |
| 116 |
| 96 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { | 117 void TestingProfileManager::DeleteTestingProfile(const std::string& name) { |
| 97 DCHECK(called_set_up_); | 118 DCHECK(called_set_up_); |
| 98 | 119 |
| 99 TestingProfilesMap::iterator it = testing_profiles_.find(name); | 120 TestingProfilesMap::iterator it = testing_profiles_.find(name); |
| 100 DCHECK(it != testing_profiles_.end()); | 121 DCHECK(it != testing_profiles_.end()); |
| 101 | 122 |
| 102 TestingProfile* profile = it->second; | 123 TestingProfile* profile = it->second; |
| 103 | 124 |
| 104 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 125 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
| 105 cache.DeleteProfileFromCache(profile->GetPath()); | 126 cache.DeleteProfileFromCache(profile->GetPath()); |
| 106 | 127 |
| 107 profile_manager_->profiles_info_.erase(profile->GetPath()); | 128 profile_manager_->profiles_info_.erase(profile->GetPath()); |
| 108 } | 129 } |
| 109 | 130 |
| 131 void TestingProfileManager::DeleteGuestProfile() { |
| 132 DCHECK(called_set_up_); |
| 133 |
| 134 TestingProfilesMap::iterator it = testing_profiles_.find(kGuestProfileName); |
| 135 DCHECK(it != testing_profiles_.end()); |
| 136 |
| 137 profile_manager_->profiles_info_.erase(ProfileManager::GetGuestProfilePath()); |
| 138 } |
| 139 |
| 110 void TestingProfileManager::DeleteProfileInfoCache() { | 140 void TestingProfileManager::DeleteProfileInfoCache() { |
| 111 profile_manager_->profile_info_cache_.reset(NULL); | 141 profile_manager_->profile_info_cache_.reset(NULL); |
| 112 } | 142 } |
| 113 | 143 |
| 114 void TestingProfileManager::SetLoggedIn(bool logged_in) { | 144 void TestingProfileManager::SetLoggedIn(bool logged_in) { |
| 115 profile_manager_->logged_in_ = logged_in; | 145 profile_manager_->logged_in_ = logged_in; |
| 116 } | 146 } |
| 117 | 147 |
| 118 const base::FilePath& TestingProfileManager::profiles_dir() { | 148 const base::FilePath& TestingProfileManager::profiles_dir() { |
| 119 DCHECK(called_set_up_); | 149 DCHECK(called_set_up_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 135 << "ProfileManager already exists"; | 165 << "ProfileManager already exists"; |
| 136 | 166 |
| 137 // Set up the directory for profiles. | 167 // Set up the directory for profiles. |
| 138 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); | 168 ASSERT_TRUE(profiles_dir_.CreateUniqueTempDir()); |
| 139 | 169 |
| 140 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); | 170 profile_manager_ = new testing::ProfileManager(profiles_dir_.path()); |
| 141 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. | 171 browser_process_->SetProfileManager(profile_manager_); // Takes ownership. |
| 142 | 172 |
| 143 called_set_up_ = true; | 173 called_set_up_ = true; |
| 144 } | 174 } |
| OLD | NEW |