| 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.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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 134 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 135 } | 135 } |
| 136 | 136 |
| 137 protected: | 137 protected: |
| 138 virtual ~TestExtensionURLRequestContextGetter() {} | 138 virtual ~TestExtensionURLRequestContextGetter() {} |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 scoped_ptr<net::URLRequestContext> context_; | 141 scoped_ptr<net::URLRequestContext> context_; |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) { | 144 ProfileKeyedService* CreateTestDesktopNotificationService( |
| 145 content::BrowserContext* profile) { |
| 145 #if defined(ENABLE_NOTIFICATIONS) | 146 #if defined(ENABLE_NOTIFICATIONS) |
| 146 return new DesktopNotificationService(profile, NULL); | 147 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL); |
| 147 #else | 148 #else |
| 148 return NULL; | 149 return NULL; |
| 149 #endif | 150 #endif |
| 150 } | 151 } |
| 151 | 152 |
| 152 } // namespace | 153 } // namespace |
| 153 | 154 |
| 154 // static | 155 // static |
| 155 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
| 156 // Must be kept in sync with | 157 // Must be kept in sync with |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 309 |
| 309 if (host_content_settings_map_) | 310 if (host_content_settings_map_) |
| 310 host_content_settings_map_->ShutdownOnUIThread(); | 311 host_content_settings_map_->ShutdownOnUIThread(); |
| 311 | 312 |
| 312 DestroyTopSites(); | 313 DestroyTopSites(); |
| 313 | 314 |
| 314 if (pref_proxy_config_tracker_.get()) | 315 if (pref_proxy_config_tracker_.get()) |
| 315 pref_proxy_config_tracker_->DetachFromPrefService(); | 316 pref_proxy_config_tracker_->DetachFromPrefService(); |
| 316 } | 317 } |
| 317 | 318 |
| 318 static ProfileKeyedService* BuildFaviconService(Profile* profile) { | 319 static ProfileKeyedService* BuildFaviconService( |
| 320 content::BrowserContext* profile) { |
| 319 return new FaviconService( | 321 return new FaviconService( |
| 320 HistoryServiceFactory::GetForProfileWithoutCreating(profile)); | 322 HistoryServiceFactory::GetForProfileWithoutCreating( |
| 323 static_cast<Profile*>(profile))); |
| 321 } | 324 } |
| 322 | 325 |
| 323 void TestingProfile::CreateFaviconService() { | 326 void TestingProfile::CreateFaviconService() { |
| 324 // It is up to the caller to create the history service if one is needed. | 327 // It is up to the caller to create the history service if one is needed. |
| 325 FaviconServiceFactory::GetInstance()->SetTestingFactory( | 328 FaviconServiceFactory::GetInstance()->SetTestingFactory( |
| 326 this, BuildFaviconService); | 329 this, BuildFaviconService); |
| 327 } | 330 } |
| 328 | 331 |
| 329 static ProfileKeyedService* BuildHistoryService(Profile* profile) { | 332 static ProfileKeyedService* BuildHistoryService( |
| 330 return new HistoryService(profile); | 333 content::BrowserContext* profile) { |
| 334 return new HistoryService(static_cast<Profile*>(profile)); |
| 331 } | 335 } |
| 332 | 336 |
| 333 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 337 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
| 334 DestroyHistoryService(); | 338 DestroyHistoryService(); |
| 335 if (delete_file) { | 339 if (delete_file) { |
| 336 base::FilePath path = GetPath(); | 340 base::FilePath path = GetPath(); |
| 337 path = path.Append(chrome::kHistoryFilename); | 341 path = path.Append(chrome::kHistoryFilename); |
| 338 file_util::Delete(path, false); | 342 file_util::Delete(path, false); |
| 339 } | 343 } |
| 340 // This will create and init the history service. | 344 // This will create and init the history service. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 top_sites_->Shutdown(); | 387 top_sites_->Shutdown(); |
| 384 top_sites_ = NULL; | 388 top_sites_ = NULL; |
| 385 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need | 389 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need |
| 386 // to be run to properly shutdown. Run all pending tasks now. This is | 390 // to be run to properly shutdown. Run all pending tasks now. This is |
| 387 // normally handled by browser_process shutdown. | 391 // normally handled by browser_process shutdown. |
| 388 if (MessageLoop::current()) | 392 if (MessageLoop::current()) |
| 389 MessageLoop::current()->RunUntilIdle(); | 393 MessageLoop::current()->RunUntilIdle(); |
| 390 } | 394 } |
| 391 } | 395 } |
| 392 | 396 |
| 393 static ProfileKeyedService* BuildBookmarkModel(Profile* profile) { | 397 static ProfileKeyedService* BuildBookmarkModel( |
| 398 content::BrowserContext* context) { |
| 399 Profile* profile = static_cast<Profile*>(context); |
| 394 BookmarkModel* bookmark_model = new BookmarkModel(profile); | 400 BookmarkModel* bookmark_model = new BookmarkModel(profile); |
| 395 bookmark_model->Load(profile->GetIOTaskRunner()); | 401 bookmark_model->Load(profile->GetIOTaskRunner()); |
| 396 return bookmark_model; | 402 return bookmark_model; |
| 397 } | 403 } |
| 398 | 404 |
| 399 | 405 |
| 400 void TestingProfile::CreateBookmarkModel(bool delete_file) { | 406 void TestingProfile::CreateBookmarkModel(bool delete_file) { |
| 401 if (delete_file) { | 407 if (delete_file) { |
| 402 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName); | 408 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName); |
| 403 file_util::Delete(path, false); | 409 file_util::Delete(path, false); |
| 404 } | 410 } |
| 405 // This will create a bookmark model. | 411 // This will create a bookmark model. |
| 406 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>( | 412 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>( |
| 407 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( | 413 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( |
| 408 this, BuildBookmarkModel)); | 414 this, BuildBookmarkModel)); |
| 409 | 415 |
| 410 HistoryService* history_service = | 416 HistoryService* history_service = |
| 411 HistoryServiceFactory::GetForProfileWithoutCreating(this); | 417 HistoryServiceFactory::GetForProfileWithoutCreating(this); |
| 412 if (history_service) { | 418 if (history_service) { |
| 413 history_service->history_backend_->bookmark_service_ = bookmark_service; | 419 history_service->history_backend_->bookmark_service_ = bookmark_service; |
| 414 history_service->history_backend_->expirer_.bookmark_service_ = | 420 history_service->history_backend_->expirer_.bookmark_service_ = |
| 415 bookmark_service; | 421 bookmark_service; |
| 416 } | 422 } |
| 417 } | 423 } |
| 418 | 424 |
| 419 static ProfileKeyedService* BuildWebDataService( | 425 static ProfileKeyedService* BuildWebDataService( |
| 420 Profile* profile) { | 426 content::BrowserContext* profile) { |
| 421 return new WebDataServiceWrapper(profile); | 427 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); |
| 422 } | 428 } |
| 423 | 429 |
| 424 void TestingProfile::CreateWebDataService() { | 430 void TestingProfile::CreateWebDataService() { |
| 425 WebDataServiceFactory::GetInstance()->SetTestingFactory( | 431 WebDataServiceFactory::GetInstance()->SetTestingFactory( |
| 426 this, BuildWebDataService); | 432 this, BuildWebDataService); |
| 427 } | 433 } |
| 428 | 434 |
| 429 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() { | 435 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() { |
| 430 // Only get the history service if it actually exists since the caller of the | 436 // Only get the history service if it actually exists since the caller of the |
| 431 // test should explicitly call CreateHistoryService to build it. | 437 // test should explicitly call CreateHistoryService to build it. |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 785 |
| 780 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { | 786 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 781 DCHECK(!build_called_); | 787 DCHECK(!build_called_); |
| 782 build_called_ = true; | 788 build_called_ = true; |
| 783 return scoped_ptr<TestingProfile>(new TestingProfile( | 789 return scoped_ptr<TestingProfile>(new TestingProfile( |
| 784 path_, | 790 path_, |
| 785 delegate_, | 791 delegate_, |
| 786 extension_policy_, | 792 extension_policy_, |
| 787 pref_service_.Pass())); | 793 pref_service_.Pass())); |
| 788 } | 794 } |
| OLD | NEW |