Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: chrome/test/base/testing_profile.cc

Issue 15517005: Remove references to Profile from browser_context_keyed_service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 139 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
140 } 140 }
141 141
142 protected: 142 protected:
143 virtual ~TestExtensionURLRequestContextGetter() {} 143 virtual ~TestExtensionURLRequestContextGetter() {}
144 144
145 private: 145 private:
146 scoped_ptr<net::URLRequestContext> context_; 146 scoped_ptr<net::URLRequestContext> context_;
147 }; 147 };
148 148
149 ProfileKeyedService* CreateTestDesktopNotificationService( 149 BrowserContextKeyedService* CreateTestDesktopNotificationService(
150 content::BrowserContext* profile) { 150 content::BrowserContext* profile) {
151 #if defined(ENABLE_NOTIFICATIONS) 151 #if defined(ENABLE_NOTIFICATIONS)
152 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL); 152 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
153 #else 153 #else
154 return NULL; 154 return NULL;
155 #endif 155 #endif
156 } 156 }
157 157
158 } // namespace 158 } // namespace
159 159
160 // static 160 // static
161 #if defined(OS_CHROMEOS) 161 #if defined(OS_CHROMEOS)
162 // Must be kept in sync with 162 // Must be kept in sync with
163 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. 163 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
164 const char TestingProfile::kTestUserProfileDir[] = "test-user"; 164 const char TestingProfile::kTestUserProfileDir[] = "test-user";
165 #else 165 #else
166 const char TestingProfile::kTestUserProfileDir[] = "Default"; 166 const char TestingProfile::kTestUserProfileDir[] = "Default";
167 #endif 167 #endif
168 168
169 TestingProfile::TestingProfile() 169 TestingProfile::TestingProfile()
170 : start_time_(Time::Now()), 170 : start_time_(Time::Now()),
171 testing_prefs_(NULL), 171 testing_prefs_(NULL),
172 incognito_(false), 172 incognito_(false),
173 original_profile_(NULL), 173 original_profile_(NULL),
174 last_session_exited_cleanly_(true), 174 last_session_exited_cleanly_(true),
175 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), 175 profile_dependency_manager_(BrowserContextDependencyManager::GetInstance() ),
176 delegate_(NULL) { 176 delegate_(NULL) {
177 CreateTempProfileDir(); 177 CreateTempProfileDir();
178 profile_path_ = temp_dir_.path(); 178 profile_path_ = temp_dir_.path();
179 179
180 Init(); 180 Init();
181 FinishInit(); 181 FinishInit();
182 } 182 }
183 183
184 TestingProfile::TestingProfile(const base::FilePath& path) 184 TestingProfile::TestingProfile(const base::FilePath& path)
185 : start_time_(Time::Now()), 185 : start_time_(Time::Now()),
186 testing_prefs_(NULL), 186 testing_prefs_(NULL),
187 incognito_(false), 187 incognito_(false),
188 original_profile_(NULL), 188 original_profile_(NULL),
189 last_session_exited_cleanly_(true), 189 last_session_exited_cleanly_(true),
190 profile_path_(path), 190 profile_path_(path),
191 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), 191 profile_dependency_manager_(BrowserContextDependencyManager::GetInstance() ),
192 delegate_(NULL) { 192 delegate_(NULL) {
193 Init(); 193 Init();
194 FinishInit(); 194 FinishInit();
195 } 195 }
196 196
197 TestingProfile::TestingProfile(const base::FilePath& path, 197 TestingProfile::TestingProfile(const base::FilePath& path,
198 Delegate* delegate) 198 Delegate* delegate)
199 : start_time_(Time::Now()), 199 : start_time_(Time::Now()),
200 testing_prefs_(NULL), 200 testing_prefs_(NULL),
201 incognito_(false), 201 incognito_(false),
202 original_profile_(NULL), 202 original_profile_(NULL),
203 last_session_exited_cleanly_(true), 203 last_session_exited_cleanly_(true),
204 profile_path_(path), 204 profile_path_(path),
205 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), 205 profile_dependency_manager_(BrowserContextDependencyManager::GetInstance() ),
206 delegate_(delegate) { 206 delegate_(delegate) {
207 Init(); 207 Init();
208 if (delegate_) { 208 if (delegate_) {
209 base::MessageLoop::current()->PostTask( 209 base::MessageLoop::current()->PostTask(
210 FROM_HERE, 210 FROM_HERE,
211 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); 211 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
212 } else { 212 } else {
213 FinishInit(); 213 FinishInit();
214 } 214 }
215 } 215 }
216 216
217 TestingProfile::TestingProfile( 217 TestingProfile::TestingProfile(
218 const base::FilePath& path, 218 const base::FilePath& path,
219 Delegate* delegate, 219 Delegate* delegate,
220 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, 220 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
221 scoped_ptr<PrefServiceSyncable> prefs) 221 scoped_ptr<PrefServiceSyncable> prefs)
222 : start_time_(Time::Now()), 222 : start_time_(Time::Now()),
223 prefs_(prefs.release()), 223 prefs_(prefs.release()),
224 testing_prefs_(NULL), 224 testing_prefs_(NULL),
225 incognito_(false), 225 incognito_(false),
226 original_profile_(NULL), 226 original_profile_(NULL),
227 last_session_exited_cleanly_(true), 227 last_session_exited_cleanly_(true),
228 extension_special_storage_policy_(extension_policy), 228 extension_special_storage_policy_(extension_policy),
229 profile_path_(path), 229 profile_path_(path),
230 profile_dependency_manager_(ProfileDependencyManager::GetInstance()), 230 profile_dependency_manager_(BrowserContextDependencyManager::GetInstance() ),
231 delegate_(delegate) { 231 delegate_(delegate) {
232 232
233 // If no profile path was supplied, create one. 233 // If no profile path was supplied, create one.
234 if (profile_path_.empty()) { 234 if (profile_path_.empty()) {
235 CreateTempProfileDir(); 235 CreateTempProfileDir();
236 profile_path_ = temp_dir_.path(); 236 profile_path_ = temp_dir_.path();
237 } 237 }
238 238
239 Init(); 239 Init();
240 // If caller supplied a delegate, delay the FinishInit invocation until other 240 // If caller supplied a delegate, delay the FinishInit invocation until other
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // We're screwed if this fails, see CHECK above. 274 // We're screwed if this fails, see CHECK above.
275 CHECK(temp_dir_.Set(system_tmp_dir)); 275 CHECK(temp_dir_.Set(system_tmp_dir));
276 } 276 }
277 } 277 }
278 } 278 }
279 279
280 void TestingProfile::Init() { 280 void TestingProfile::Init() {
281 // Normally this would happen during browser startup, but for tests 281 // Normally this would happen during browser startup, but for tests
282 // we need to trigger creation of Profile-related services. 282 // we need to trigger creation of Profile-related services.
283 ChromeBrowserMainExtraPartsProfiles:: 283 ChromeBrowserMainExtraPartsProfiles::
284 EnsureProfileKeyedServiceFactoriesBuilt(); 284 EnsureBrowserContextKeyedServiceFactoriesBuilt();
285 285
286 if (prefs_.get()) 286 if (prefs_.get())
287 components::UserPrefs::Set(this, prefs_.get()); 287 components::UserPrefs::Set(this, prefs_.get());
288 else 288 else
289 CreateTestingPrefService(); 289 CreateTestingPrefService();
290 290
291 if (!file_util::PathExists(profile_path_)) 291 if (!file_util::PathExists(profile_path_))
292 file_util::CreateDirectory(profile_path_); 292 file_util::CreateDirectory(profile_path_);
293 293
294 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl 294 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
295 // anymore, after converting the PrefService to a PKS. Until then it must 295 // anymore, after converting the PrefService to a PKS. Until then it must
296 // be associated with a TestingProfile too. 296 // be associated with a TestingProfile too.
297 CreateProfilePolicyConnector(); 297 CreateProfilePolicyConnector();
298 298
299 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( 299 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
300 this, extensions::TestExtensionSystem::Build); 300 this, extensions::TestExtensionSystem::Build);
301 301
302 profile_dependency_manager_->CreateProfileServices(this, true); 302 profile_dependency_manager_->CreateBrowserContextServices(this, true);
303 303
304 #if defined(ENABLE_NOTIFICATIONS) 304 #if defined(ENABLE_NOTIFICATIONS)
305 // Install profile keyed service factory hooks for dummy/test services 305 // Install profile keyed service factory hooks for dummy/test services
306 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( 306 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
307 this, CreateTestDesktopNotificationService); 307 this, CreateTestDesktopNotificationService);
308 #endif 308 #endif
309 } 309 }
310 310
311 void TestingProfile::FinishInit() { 311 void TestingProfile::FinishInit() {
312 DCHECK(content::NotificationService::current()); 312 DCHECK(content::NotificationService::current());
313 content::NotificationService::current()->Notify( 313 content::NotificationService::current()->Notify(
314 chrome::NOTIFICATION_PROFILE_CREATED, 314 chrome::NOTIFICATION_PROFILE_CREATED,
315 content::Source<Profile>(static_cast<Profile*>(this)), 315 content::Source<Profile>(static_cast<Profile*>(this)),
316 content::NotificationService::NoDetails()); 316 content::NotificationService::NoDetails());
317 317
318 if (delegate_) 318 if (delegate_)
319 delegate_->OnProfileCreated(this, true, false); 319 delegate_->OnProfileCreated(this, true, false);
320 } 320 }
321 321
322 TestingProfile::~TestingProfile() { 322 TestingProfile::~TestingProfile() {
323 MaybeSendDestroyedNotification(); 323 MaybeSendDestroyedNotification();
324 324
325 profile_dependency_manager_->DestroyProfileServices(this); 325 profile_dependency_manager_->DestroyBrowserContextServices(this);
326 326
327 if (host_content_settings_map_) 327 if (host_content_settings_map_)
328 host_content_settings_map_->ShutdownOnUIThread(); 328 host_content_settings_map_->ShutdownOnUIThread();
329 329
330 DestroyTopSites(); 330 DestroyTopSites();
331 331
332 if (pref_proxy_config_tracker_.get()) 332 if (pref_proxy_config_tracker_.get())
333 pref_proxy_config_tracker_->DetachFromPrefService(); 333 pref_proxy_config_tracker_->DetachFromPrefService();
334 } 334 }
335 335
336 static ProfileKeyedService* BuildFaviconService( 336 static BrowserContextKeyedService* BuildFaviconService(
337 content::BrowserContext* profile) { 337 content::BrowserContext* profile) {
338 return new FaviconService( 338 return new FaviconService(
339 HistoryServiceFactory::GetForProfileWithoutCreating( 339 HistoryServiceFactory::GetForProfileWithoutCreating(
340 static_cast<Profile*>(profile))); 340 static_cast<Profile*>(profile)));
341 } 341 }
342 342
343 void TestingProfile::CreateFaviconService() { 343 void TestingProfile::CreateFaviconService() {
344 // It is up to the caller to create the history service if one is needed. 344 // It is up to the caller to create the history service if one is needed.
345 FaviconServiceFactory::GetInstance()->SetTestingFactory( 345 FaviconServiceFactory::GetInstance()->SetTestingFactory(
346 this, BuildFaviconService); 346 this, BuildFaviconService);
347 } 347 }
348 348
349 static ProfileKeyedService* BuildHistoryService( 349 static BrowserContextKeyedService* BuildHistoryService(
350 content::BrowserContext* profile) { 350 content::BrowserContext* profile) {
351 return new HistoryService(static_cast<Profile*>(profile)); 351 return new HistoryService(static_cast<Profile*>(profile));
352 } 352 }
353 353
354 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { 354 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
355 DestroyHistoryService(); 355 DestroyHistoryService();
356 if (delete_file) { 356 if (delete_file) {
357 base::FilePath path = GetPath(); 357 base::FilePath path = GetPath();
358 path = path.Append(chrome::kHistoryFilename); 358 path = path.Append(chrome::kHistoryFilename);
359 file_util::Delete(path, false); 359 file_util::Delete(path, false);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 top_sites_->Shutdown(); 406 top_sites_->Shutdown();
407 top_sites_ = NULL; 407 top_sites_ = NULL;
408 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that 408 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
409 // need to be run to properly shutdown. Run all pending tasks now. This is 409 // need to be run to properly shutdown. Run all pending tasks now. This is
410 // normally handled by browser_process shutdown. 410 // normally handled by browser_process shutdown.
411 if (base::MessageLoop::current()) 411 if (base::MessageLoop::current())
412 base::MessageLoop::current()->RunUntilIdle(); 412 base::MessageLoop::current()->RunUntilIdle();
413 } 413 }
414 } 414 }
415 415
416 static ProfileKeyedService* BuildBookmarkModel( 416 static BrowserContextKeyedService* BuildBookmarkModel(
417 content::BrowserContext* context) { 417 content::BrowserContext* context) {
418 Profile* profile = static_cast<Profile*>(context); 418 Profile* profile = static_cast<Profile*>(context);
419 BookmarkModel* bookmark_model = new BookmarkModel(profile); 419 BookmarkModel* bookmark_model = new BookmarkModel(profile);
420 bookmark_model->Load(profile->GetIOTaskRunner()); 420 bookmark_model->Load(profile->GetIOTaskRunner());
421 return bookmark_model; 421 return bookmark_model;
422 } 422 }
423 423
424 424
425 void TestingProfile::CreateBookmarkModel(bool delete_file) { 425 void TestingProfile::CreateBookmarkModel(bool delete_file) {
426 if (delete_file) { 426 if (delete_file) {
427 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName); 427 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName);
428 file_util::Delete(path, false); 428 file_util::Delete(path, false);
429 } 429 }
430 // This will create a bookmark model. 430 // This will create a bookmark model.
431 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>( 431 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>(
432 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( 432 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
433 this, BuildBookmarkModel)); 433 this, BuildBookmarkModel));
434 434
435 HistoryService* history_service = 435 HistoryService* history_service =
436 HistoryServiceFactory::GetForProfileWithoutCreating(this); 436 HistoryServiceFactory::GetForProfileWithoutCreating(this);
437 if (history_service) { 437 if (history_service) {
438 history_service->history_backend_->bookmark_service_ = bookmark_service; 438 history_service->history_backend_->bookmark_service_ = bookmark_service;
439 history_service->history_backend_->expirer_.bookmark_service_ = 439 history_service->history_backend_->expirer_.bookmark_service_ =
440 bookmark_service; 440 bookmark_service;
441 } 441 }
442 } 442 }
443 443
444 static ProfileKeyedService* BuildWebDataService( 444 static BrowserContextKeyedService* BuildWebDataService(
445 content::BrowserContext* profile) { 445 content::BrowserContext* profile) {
446 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); 446 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
447 } 447 }
448 448
449 void TestingProfile::CreateWebDataService() { 449 void TestingProfile::CreateWebDataService() {
450 WebDataServiceFactory::GetInstance()->SetTestingFactory( 450 WebDataServiceFactory::GetInstance()->SetTestingFactory(
451 this, BuildWebDataService); 451 this, BuildWebDataService);
452 } 452 }
453 453
454 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() { 454 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 804
805 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { 805 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
806 DCHECK(!build_called_); 806 DCHECK(!build_called_);
807 build_called_ = true; 807 build_called_ = true;
808 return scoped_ptr<TestingProfile>(new TestingProfile( 808 return scoped_ptr<TestingProfile>(new TestingProfile(
809 path_, 809 path_,
810 delegate_, 810 delegate_,
811 extension_policy_, 811 extension_policy_,
812 pref_service_.Pass())); 812 pref_service_.Pass()));
813 } 813 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698