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 "chrome/test/base/testing_profile.h" | 5 #include "chrome/test/base/testing_profile.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 return new DesktopNotificationService(profile, NULL); | 125 return new DesktopNotificationService(profile, NULL); |
126 } | 126 } |
127 | 127 |
128 } // namespace | 128 } // namespace |
129 | 129 |
130 TestingProfile::TestingProfile() | 130 TestingProfile::TestingProfile() |
131 : start_time_(Time::Now()), | 131 : start_time_(Time::Now()), |
132 testing_prefs_(NULL), | 132 testing_prefs_(NULL), |
133 incognito_(false), | 133 incognito_(false), |
134 last_session_exited_cleanly_(true), | 134 last_session_exited_cleanly_(true), |
135 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { | 135 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 136 delegate_(NULL) { |
136 if (!temp_dir_.CreateUniqueTempDir()) { | 137 if (!temp_dir_.CreateUniqueTempDir()) { |
137 LOG(ERROR) << "Failed to create unique temporary directory."; | 138 LOG(ERROR) << "Failed to create unique temporary directory."; |
138 | 139 |
139 // Fallback logic in case we fail to create unique temporary directory. | 140 // Fallback logic in case we fail to create unique temporary directory. |
140 FilePath system_tmp_dir; | 141 FilePath system_tmp_dir; |
141 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); | 142 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); |
142 | 143 |
143 // We're severly screwed if we can't get the system temporary | 144 // We're severly screwed if we can't get the system temporary |
144 // directory. Die now to avoid writing to the filesystem root | 145 // directory. Die now to avoid writing to the filesystem root |
145 // or other bad places. | 146 // or other bad places. |
146 CHECK(success); | 147 CHECK(success); |
147 | 148 |
148 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath")); | 149 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath")); |
149 file_util::Delete(fallback_dir, true); | 150 file_util::Delete(fallback_dir, true); |
150 file_util::CreateDirectory(fallback_dir); | 151 file_util::CreateDirectory(fallback_dir); |
151 if (!temp_dir_.Set(fallback_dir)) { | 152 if (!temp_dir_.Set(fallback_dir)) { |
152 // That shouldn't happen, but if it does, try to recover. | 153 // That shouldn't happen, but if it does, try to recover. |
153 LOG(ERROR) << "Failed to use a fallback temporary directory."; | 154 LOG(ERROR) << "Failed to use a fallback temporary directory."; |
154 | 155 |
155 // We're screwed if this fails, see CHECK above. | 156 // We're screwed if this fails, see CHECK above. |
156 CHECK(temp_dir_.Set(system_tmp_dir)); | 157 CHECK(temp_dir_.Set(system_tmp_dir)); |
157 } | 158 } |
158 } | 159 } |
159 | 160 |
160 profile_path_ = temp_dir_.path(); | 161 profile_path_ = temp_dir_.path(); |
161 | 162 |
162 Init(); | 163 Init(); |
| 164 FinishInit(); |
163 } | 165 } |
164 | 166 |
165 TestingProfile::TestingProfile(const FilePath& path) | 167 TestingProfile::TestingProfile(const FilePath& path) |
166 : start_time_(Time::Now()), | 168 : start_time_(Time::Now()), |
167 testing_prefs_(NULL), | 169 testing_prefs_(NULL), |
168 incognito_(false), | 170 incognito_(false), |
169 last_session_exited_cleanly_(true), | 171 last_session_exited_cleanly_(true), |
170 profile_path_(path), | 172 profile_path_(path), |
171 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { | 173 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 174 delegate_(NULL) { |
172 Init(); | 175 Init(); |
| 176 FinishInit(); |
| 177 } |
| 178 |
| 179 TestingProfile::TestingProfile(const FilePath& path, |
| 180 Delegate* delegate) |
| 181 : start_time_(Time::Now()), |
| 182 testing_prefs_(NULL), |
| 183 incognito_(false), |
| 184 last_session_exited_cleanly_(true), |
| 185 profile_path_(path), |
| 186 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 187 delegate_(delegate) { |
| 188 Init(); |
| 189 if (delegate_) { |
| 190 MessageLoop::current()->PostTask(FROM_HERE, |
| 191 base::Bind(&TestingProfile::FinishInit, |
| 192 base::Unretained(this))); |
| 193 } else { |
| 194 FinishInit(); |
| 195 } |
173 } | 196 } |
174 | 197 |
175 void TestingProfile::Init() { | 198 void TestingProfile::Init() { |
176 profile_dependency_manager_->CreateProfileServices(this, true); | 199 profile_dependency_manager_->CreateProfileServices(this, true); |
177 | 200 |
178 // Install profile keyed service factory hooks for dummy/test services | 201 // Install profile keyed service factory hooks for dummy/test services |
179 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( | 202 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
180 this, CreateTestDesktopNotificationService); | 203 this, CreateTestDesktopNotificationService); |
| 204 } |
181 | 205 |
| 206 void TestingProfile::FinishInit() { |
182 content::NotificationService::current()->Notify( | 207 content::NotificationService::current()->Notify( |
183 chrome::NOTIFICATION_PROFILE_CREATED, | 208 chrome::NOTIFICATION_PROFILE_CREATED, |
184 content::Source<Profile>(static_cast<Profile*>(this)), | 209 content::Source<Profile>(static_cast<Profile*>(this)), |
185 content::NotificationService::NoDetails()); | 210 content::NotificationService::NoDetails()); |
| 211 |
| 212 if (delegate_) |
| 213 delegate_->OnProfileCreated(this, true); |
186 } | 214 } |
187 | 215 |
188 TestingProfile::~TestingProfile() { | 216 TestingProfile::~TestingProfile() { |
189 content::NotificationService::current()->Notify( | 217 content::NotificationService::current()->Notify( |
190 chrome::NOTIFICATION_PROFILE_DESTROYED, | 218 chrome::NOTIFICATION_PROFILE_DESTROYED, |
191 content::Source<Profile>(static_cast<Profile*>(this)), | 219 content::Source<Profile>(static_cast<Profile*>(this)), |
192 content::NotificationService::NoDetails()); | 220 content::NotificationService::NoDetails()); |
193 | 221 |
194 profile_dependency_manager_->DestroyProfileServices(this); | 222 profile_dependency_manager_->DestroyProfileServices(this); |
195 | 223 |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { | 850 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
823 return GetExtensionSpecialStoragePolicy(); | 851 return GetExtensionSpecialStoragePolicy(); |
824 } | 852 } |
825 | 853 |
826 void TestingProfile::DestroyWebDataService() { | 854 void TestingProfile::DestroyWebDataService() { |
827 if (!web_data_service_.get()) | 855 if (!web_data_service_.get()) |
828 return; | 856 return; |
829 | 857 |
830 web_data_service_->Shutdown(); | 858 web_data_service_->Shutdown(); |
831 } | 859 } |
OLD | NEW |