| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/content_settings/host_content_settings_map.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 19 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 19 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 20 #include "chrome/browser/extensions/extension_pref_value_map.h" | |
| 21 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 22 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 21 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 22 #include "chrome/browser/extensions/extension_system.h" |
| 23 #include "chrome/browser/extensions/extension_system_factory.h" |
| 24 #include "chrome/browser/extensions/test_extension_system.h" |
| 23 #include "chrome/browser/favicon/favicon_service.h" | 25 #include "chrome/browser/favicon/favicon_service.h" |
| 24 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 26 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
| 25 #include "chrome/browser/history/history.h" | 27 #include "chrome/browser/history/history.h" |
| 26 #include "chrome/browser/history/history_backend.h" | 28 #include "chrome/browser/history/history_backend.h" |
| 27 #include "chrome/browser/history/top_sites.h" | 29 #include "chrome/browser/history/top_sites.h" |
| 28 #include "chrome/browser/net/proxy_service_factory.h" | 30 #include "chrome/browser/net/proxy_service_factory.h" |
| 29 #include "chrome/browser/notifications/desktop_notification_service.h" | 31 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 30 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 32 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 31 #include "chrome/browser/prefs/browser_prefs.h" | 33 #include "chrome/browser/prefs/browser_prefs.h" |
| 32 #include "chrome/browser/prefs/testing_pref_store.h" | 34 #include "chrome/browser/prefs/testing_pref_store.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 base::Bind(&TestingProfile::FinishInit, | 203 base::Bind(&TestingProfile::FinishInit, |
| 202 base::Unretained(this))); | 204 base::Unretained(this))); |
| 203 } else { | 205 } else { |
| 204 FinishInit(); | 206 FinishInit(); |
| 205 } | 207 } |
| 206 } | 208 } |
| 207 | 209 |
| 208 void TestingProfile::Init() { | 210 void TestingProfile::Init() { |
| 209 profile_dependency_manager_->CreateProfileServices(this, true); | 211 profile_dependency_manager_->CreateProfileServices(this, true); |
| 210 | 212 |
| 213 ExtensionSystemFactory::GetInstance()->SetTestingFactory( |
| 214 this, TestExtensionSystem::Build); |
| 215 |
| 211 // Install profile keyed service factory hooks for dummy/test services | 216 // Install profile keyed service factory hooks for dummy/test services |
| 212 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( | 217 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
| 213 this, CreateTestDesktopNotificationService); | 218 this, CreateTestDesktopNotificationService); |
| 214 } | 219 } |
| 215 | 220 |
| 216 void TestingProfile::FinishInit() { | 221 void TestingProfile::FinishInit() { |
| 217 DCHECK(content::NotificationService::current()); | 222 DCHECK(content::NotificationService::current()); |
| 218 content::NotificationService::current()->Notify( | 223 content::NotificationService::current()->Notify( |
| 219 chrome::NOTIFICATION_PROFILE_CREATED, | 224 chrome::NOTIFICATION_PROFILE_CREATED, |
| 220 content::Source<Profile>(static_cast<Profile*>(this)), | 225 content::Source<Profile>(static_cast<Profile*>(this)), |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 if (turl_model->loaded()) | 396 if (turl_model->loaded()) |
| 392 return; | 397 return; |
| 393 | 398 |
| 394 ui_test_utils::WindowedNotificationObserver turl_service_load_observer( | 399 ui_test_utils::WindowedNotificationObserver turl_service_load_observer( |
| 395 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 400 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 396 content::NotificationService::AllSources()); | 401 content::NotificationService::AllSources()); |
| 397 turl_model->Load(); | 402 turl_model->Load(); |
| 398 turl_service_load_observer.Wait(); | 403 turl_service_load_observer.Wait(); |
| 399 } | 404 } |
| 400 | 405 |
| 401 void TestingProfile::CreateExtensionProcessManager() { | |
| 402 extension_process_manager_.reset(ExtensionProcessManager::Create(this)); | |
| 403 } | |
| 404 | |
| 405 ExtensionService* TestingProfile::CreateExtensionService( | |
| 406 const CommandLine* command_line, | |
| 407 const FilePath& install_directory, | |
| 408 bool autoupdate_enabled) { | |
| 409 // Extension pref store, created for use by |extension_prefs_|. | |
| 410 | |
| 411 extension_pref_value_map_.reset(new ExtensionPrefValueMap); | |
| 412 | |
| 413 bool extensions_disabled = | |
| 414 command_line && command_line->HasSwitch(switches::kDisableExtensions); | |
| 415 | |
| 416 // Note that the GetPrefs() creates a TestingPrefService, therefore | |
| 417 // the extension controlled pref values set in extension_prefs_ | |
| 418 // are not reflected in the pref service. One would need to | |
| 419 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false). | |
| 420 extension_prefs_.reset( | |
| 421 new ExtensionPrefs(GetPrefs(), | |
| 422 install_directory, | |
| 423 extension_pref_value_map_.get())); | |
| 424 extension_prefs_->Init(extensions_disabled); | |
| 425 extension_service_.reset(new ExtensionService(this, | |
| 426 command_line, | |
| 427 install_directory, | |
| 428 extension_prefs_.get(), | |
| 429 autoupdate_enabled, | |
| 430 true)); | |
| 431 return extension_service_.get(); | |
| 432 } | |
| 433 | |
| 434 FilePath TestingProfile::GetPath() { | 406 FilePath TestingProfile::GetPath() { |
| 435 return profile_path_; | 407 return profile_path_; |
| 436 } | 408 } |
| 437 | 409 |
| 438 TestingPrefService* TestingProfile::GetTestingPrefService() { | 410 TestingPrefService* TestingProfile::GetTestingPrefService() { |
| 439 if (!prefs_.get()) | 411 if (!prefs_.get()) |
| 440 CreateTestingPrefService(); | 412 CreateTestingPrefService(); |
| 441 DCHECK(testing_prefs_); | 413 DCHECK(testing_prefs_); |
| 442 return testing_prefs_; | 414 return testing_prefs_; |
| 443 } | 415 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 NULL, NULL); | 462 NULL, NULL); |
| 491 } | 463 } |
| 492 return db_tracker_; | 464 return db_tracker_; |
| 493 } | 465 } |
| 494 | 466 |
| 495 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { | 467 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { |
| 496 return NULL; | 468 return NULL; |
| 497 } | 469 } |
| 498 | 470 |
| 499 ExtensionService* TestingProfile::GetExtensionService() { | 471 ExtensionService* TestingProfile::GetExtensionService() { |
| 500 return extension_service_.get(); | 472 return ExtensionSystemFactory::GetForProfile(this)->extension_service(); |
| 501 } | 473 } |
| 502 | 474 |
| 503 UserScriptMaster* TestingProfile::GetUserScriptMaster() { | 475 UserScriptMaster* TestingProfile::GetUserScriptMaster() { |
| 504 return NULL; | 476 return ExtensionSystemFactory::GetForProfile(this)->user_script_master(); |
| 505 } | |
| 506 | |
| 507 ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() { | |
| 508 return NULL; | |
| 509 } | 477 } |
| 510 | 478 |
| 511 ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() { | 479 ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() { |
| 512 return extension_process_manager_.get(); | 480 return ExtensionSystemFactory::GetForProfile(this)->process_manager(); |
| 513 } | |
| 514 | |
| 515 ExtensionMessageService* TestingProfile::GetExtensionMessageService() { | |
| 516 return NULL; | |
| 517 } | 481 } |
| 518 | 482 |
| 519 ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() { | 483 ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() { |
| 520 return NULL; | 484 return ExtensionSystemFactory::GetForProfile(this)->event_router(); |
| 521 } | 485 } |
| 522 | 486 |
| 523 void TestingProfile::SetExtensionSpecialStoragePolicy( | 487 void TestingProfile::SetExtensionSpecialStoragePolicy( |
| 524 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { | 488 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
| 525 extension_special_storage_policy_ = extension_special_storage_policy; | 489 extension_special_storage_policy_ = extension_special_storage_policy; |
| 526 } | 490 } |
| 527 | 491 |
| 528 ExtensionSpecialStoragePolicy* | 492 ExtensionSpecialStoragePolicy* |
| 529 TestingProfile::GetExtensionSpecialStoragePolicy() { | 493 TestingProfile::GetExtensionSpecialStoragePolicy() { |
| 530 if (!extension_special_storage_policy_.get()) | 494 if (!extension_special_storage_policy_.get()) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 quota::QuotaManager* TestingProfile::GetQuotaManager() { | 594 quota::QuotaManager* TestingProfile::GetQuotaManager() { |
| 631 return quota_manager_.get(); | 595 return quota_manager_.get(); |
| 632 } | 596 } |
| 633 | 597 |
| 634 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { | 598 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { |
| 635 return request_context_.get(); | 599 return request_context_.get(); |
| 636 } | 600 } |
| 637 | 601 |
| 638 net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( | 602 net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( |
| 639 int renderer_child_id) { | 603 int renderer_child_id) { |
| 640 if (extension_service_.get()) { | 604 ExtensionService* extension_service = |
| 641 const Extension* installed_app = extension_service_-> | 605 ExtensionSystemFactory::GetForProfile(this)->extension_service(); |
| 606 if (extension_service) { |
| 607 const Extension* installed_app = extension_service-> |
| 642 GetInstalledAppForRenderer(renderer_child_id); | 608 GetInstalledAppForRenderer(renderer_child_id); |
| 643 if (installed_app != NULL && installed_app->is_storage_isolated()) | 609 if (installed_app != NULL && installed_app->is_storage_isolated()) |
| 644 return GetRequestContextForIsolatedApp(installed_app->id()); | 610 return GetRequestContextForIsolatedApp(installed_app->id()); |
| 645 } | 611 } |
| 646 | 612 |
| 647 return GetRequestContext(); | 613 return GetRequestContext(); |
| 648 } | 614 } |
| 649 | 615 |
| 650 void TestingProfile::CreateRequestContext() { | 616 void TestingProfile::CreateRequestContext() { |
| 651 if (!request_context_) | 617 if (!request_context_) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 if (!token_service_.get()) { | 753 if (!token_service_.get()) { |
| 788 token_service_.reset(new TokenService()); | 754 token_service_.reset(new TokenService()); |
| 789 } | 755 } |
| 790 return token_service_.get(); | 756 return token_service_.get(); |
| 791 } | 757 } |
| 792 | 758 |
| 793 ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() { | 759 ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() { |
| 794 return NULL; | 760 return NULL; |
| 795 } | 761 } |
| 796 | 762 |
| 797 ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() { | |
| 798 return NULL; | |
| 799 } | |
| 800 | |
| 801 PromoCounter* TestingProfile::GetInstantPromoCounter() { | 763 PromoCounter* TestingProfile::GetInstantPromoCounter() { |
| 802 return NULL; | 764 return NULL; |
| 803 } | 765 } |
| 804 | 766 |
| 805 ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() { | 767 ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() { |
| 806 if (!chrome_url_data_manager_.get()) | 768 if (!chrome_url_data_manager_.get()) |
| 807 chrome_url_data_manager_.reset( | 769 chrome_url_data_manager_.reset( |
| 808 new ChromeURLDataManager( | 770 new ChromeURLDataManager( |
| 809 base::Callback<ChromeURLDataManagerBackend*(void)>())); | 771 base::Callback<ChromeURLDataManagerBackend*(void)>())); |
| 810 return chrome_url_data_manager_.get(); | 772 return chrome_url_data_manager_.get(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 829 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { | 791 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
| 830 return GetExtensionSpecialStoragePolicy(); | 792 return GetExtensionSpecialStoragePolicy(); |
| 831 } | 793 } |
| 832 | 794 |
| 833 void TestingProfile::DestroyWebDataService() { | 795 void TestingProfile::DestroyWebDataService() { |
| 834 if (!web_data_service_.get()) | 796 if (!web_data_service_.get()) |
| 835 return; | 797 return; |
| 836 | 798 |
| 837 web_data_service_->Shutdown(); | 799 web_data_service_->Shutdown(); |
| 838 } | 800 } |
| OLD | NEW |