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

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

Issue 9959040: Reland 125805 - Reland 124817 - A profile-keyed service for Extensions, ExtensionSystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « chrome/test/base/testing_profile.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
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" 20 #include "chrome/browser/extensions/extension_pref_value_map.h"
21 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/extension_special_storage_policy.h" 22 #include "chrome/browser/extensions/extension_special_storage_policy.h"
23 #include "chrome/browser/extensions/extension_system.h"
24 #include "chrome/browser/extensions/extension_system_factory.h"
25 #include "chrome/browser/extensions/test_extension_system.h"
23 #include "chrome/browser/favicon/favicon_service.h" 26 #include "chrome/browser/favicon/favicon_service.h"
24 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" 27 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
25 #include "chrome/browser/history/history.h" 28 #include "chrome/browser/history/history.h"
26 #include "chrome/browser/history/history_backend.h" 29 #include "chrome/browser/history/history_backend.h"
27 #include "chrome/browser/history/top_sites.h" 30 #include "chrome/browser/history/top_sites.h"
28 #include "chrome/browser/net/proxy_service_factory.h" 31 #include "chrome/browser/net/proxy_service_factory.h"
29 #include "chrome/browser/notifications/desktop_notification_service.h" 32 #include "chrome/browser/notifications/desktop_notification_service.h"
30 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 33 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
31 #include "chrome/browser/prefs/browser_prefs.h" 34 #include "chrome/browser/prefs/browser_prefs.h"
32 #include "chrome/browser/prefs/testing_pref_store.h" 35 #include "chrome/browser/prefs/testing_pref_store.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (delegate_) { 191 if (delegate_) {
189 MessageLoop::current()->PostTask(FROM_HERE, 192 MessageLoop::current()->PostTask(FROM_HERE,
190 base::Bind(&TestingProfile::FinishInit, 193 base::Bind(&TestingProfile::FinishInit,
191 base::Unretained(this))); 194 base::Unretained(this)));
192 } else { 195 } else {
193 FinishInit(); 196 FinishInit();
194 } 197 }
195 } 198 }
196 199
197 void TestingProfile::Init() { 200 void TestingProfile::Init() {
201 ExtensionSystemFactory::GetInstance()->SetTestingFactory(
202 this, TestExtensionSystem::Build);
203
198 profile_dependency_manager_->CreateProfileServices(this, true); 204 profile_dependency_manager_->CreateProfileServices(this, true);
199 205
200 #if defined(ENABLE_NOTIFICATIONS) 206 #if defined(ENABLE_NOTIFICATIONS)
201 // Install profile keyed service factory hooks for dummy/test services 207 // Install profile keyed service factory hooks for dummy/test services
202 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( 208 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
203 this, CreateTestDesktopNotificationService); 209 this, CreateTestDesktopNotificationService);
204 #endif 210 #endif
205 } 211 }
206 212
207 void TestingProfile::FinishInit() { 213 void TestingProfile::FinishInit() {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 if (turl_model->loaded()) 385 if (turl_model->loaded())
380 return; 386 return;
381 387
382 ui_test_utils::WindowedNotificationObserver turl_service_load_observer( 388 ui_test_utils::WindowedNotificationObserver turl_service_load_observer(
383 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 389 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
384 content::NotificationService::AllSources()); 390 content::NotificationService::AllSources());
385 turl_model->Load(); 391 turl_model->Load();
386 turl_service_load_observer.Wait(); 392 turl_service_load_observer.Wait();
387 } 393 }
388 394
389 void TestingProfile::CreateExtensionProcessManager() {
390 extension_process_manager_.reset(ExtensionProcessManager::Create(this));
391 }
392
393 ExtensionService* TestingProfile::CreateExtensionService(
394 const CommandLine* command_line,
395 const FilePath& install_directory,
396 bool autoupdate_enabled) {
397 // Extension pref store, created for use by |extension_prefs_|.
398
399 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
400
401 bool extensions_disabled =
402 command_line && command_line->HasSwitch(switches::kDisableExtensions);
403
404 // Note that the GetPrefs() creates a TestingPrefService, therefore
405 // the extension controlled pref values set in extension_prefs_
406 // are not reflected in the pref service. One would need to
407 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false).
408 extension_prefs_.reset(
409 new ExtensionPrefs(GetPrefs(),
410 install_directory,
411 extension_pref_value_map_.get()));
412 extension_prefs_->Init(extensions_disabled);
413 extension_service_.reset(new ExtensionService(this,
414 command_line,
415 install_directory,
416 extension_prefs_.get(),
417 autoupdate_enabled,
418 true));
419 return extension_service_.get();
420 }
421
422 FilePath TestingProfile::GetPath() { 395 FilePath TestingProfile::GetPath() {
423 return profile_path_; 396 return profile_path_;
424 } 397 }
425 398
426 TestingPrefService* TestingProfile::GetTestingPrefService() { 399 TestingPrefService* TestingProfile::GetTestingPrefService() {
427 if (!prefs_.get()) 400 if (!prefs_.get())
428 CreateTestingPrefService(); 401 CreateTestingPrefService();
429 DCHECK(testing_prefs_); 402 DCHECK(testing_prefs_);
430 return testing_prefs_; 403 return testing_prefs_;
431 } 404 }
(...skipping 27 matching lines...) Expand all
459 } 432 }
460 433
461 Profile* TestingProfile::GetOriginalProfile() { 434 Profile* TestingProfile::GetOriginalProfile() {
462 return this; 435 return this;
463 } 436 }
464 437
465 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { 438 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
466 return NULL; 439 return NULL;
467 } 440 }
468 441
442 ExtensionPrefValueMap* TestingProfile::GetExtensionPrefValueMap() {
443 return NULL;
444 }
445
469 ExtensionService* TestingProfile::GetExtensionService() { 446 ExtensionService* TestingProfile::GetExtensionService() {
470 return extension_service_.get(); 447 return ExtensionSystemFactory::GetForProfile(this)->extension_service();
471 } 448 }
472 449
473 UserScriptMaster* TestingProfile::GetUserScriptMaster() { 450 UserScriptMaster* TestingProfile::GetUserScriptMaster() {
474 return NULL; 451 return ExtensionSystemFactory::GetForProfile(this)->user_script_master();
475 }
476
477 ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() {
478 return NULL;
479 } 452 }
480 453
481 ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() { 454 ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() {
482 return extension_process_manager_.get(); 455 return ExtensionSystemFactory::GetForProfile(this)->process_manager();
483 }
484
485 ExtensionMessageService* TestingProfile::GetExtensionMessageService() {
486 return NULL;
487 } 456 }
488 457
489 ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() { 458 ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() {
490 return NULL; 459 return ExtensionSystemFactory::GetForProfile(this)->event_router();
491 } 460 }
492 461
493 void TestingProfile::SetExtensionSpecialStoragePolicy( 462 void TestingProfile::SetExtensionSpecialStoragePolicy(
494 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { 463 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
495 extension_special_storage_policy_ = extension_special_storage_policy; 464 extension_special_storage_policy_ = extension_special_storage_policy;
496 } 465 }
497 466
498 ExtensionSpecialStoragePolicy* 467 ExtensionSpecialStoragePolicy*
499 TestingProfile::GetExtensionSpecialStoragePolicy() { 468 TestingProfile::GetExtensionSpecialStoragePolicy() {
500 if (!extension_special_storage_policy_.get()) 469 if (!extension_special_storage_policy_.get())
501 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); 470 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
502 return extension_special_storage_policy_.get(); 471 return extension_special_storage_policy_.get();
503 } 472 }
504 473
505 LazyBackgroundTaskQueue* TestingProfile::GetLazyBackgroundTaskQueue() {
506 return NULL;
507 }
508
509 FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) { 474 FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) {
510 return favicon_service_.get(); 475 return favicon_service_.get();
511 } 476 }
512 477
513 HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) { 478 HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) {
514 return history_service_.get(); 479 return history_service_.get();
515 } 480 }
516 481
517 HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() { 482 HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() {
518 return history_service_.get(); 483 return history_service_.get();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 DownloadManager* TestingProfile::GetDownloadManager() { 548 DownloadManager* TestingProfile::GetDownloadManager() {
584 return NULL; 549 return NULL;
585 } 550 }
586 551
587 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { 552 net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
588 return request_context_.get(); 553 return request_context_.get();
589 } 554 }
590 555
591 net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( 556 net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
592 int renderer_child_id) { 557 int renderer_child_id) {
593 if (extension_service_.get()) { 558 ExtensionService* extension_service =
594 const Extension* installed_app = extension_service_-> 559 ExtensionSystemFactory::GetForProfile(this)->extension_service();
560 if (extension_service) {
561 const Extension* installed_app = extension_service->
595 GetInstalledAppForRenderer(renderer_child_id); 562 GetInstalledAppForRenderer(renderer_child_id);
596 if (installed_app != NULL && installed_app->is_storage_isolated()) 563 if (installed_app != NULL && installed_app->is_storage_isolated())
597 return GetRequestContextForIsolatedApp(installed_app->id()); 564 return GetRequestContextForIsolatedApp(installed_app->id());
598 } 565 }
599 566
600 return GetRequestContext(); 567 return GetRequestContext();
601 } 568 }
602 569
603 void TestingProfile::CreateRequestContext() { 570 void TestingProfile::CreateRequestContext() {
604 if (!request_context_) 571 if (!request_context_)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 692
726 void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { 693 void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
727 DCHECK(history_service_.get()); 694 DCHECK(history_service_.get());
728 DCHECK(MessageLoop::current()); 695 DCHECK(MessageLoop::current());
729 696
730 CancelableRequestConsumer consumer; 697 CancelableRequestConsumer consumer;
731 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); 698 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
732 MessageLoop::current()->Run(); 699 MessageLoop::current()->Run();
733 } 700 }
734 701
735 ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() {
736 return NULL;
737 }
738
739 PromoCounter* TestingProfile::GetInstantPromoCounter() { 702 PromoCounter* TestingProfile::GetInstantPromoCounter() {
740 return NULL; 703 return NULL;
741 } 704 }
742 705
743 ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() { 706 ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() {
744 if (!chrome_url_data_manager_.get()) 707 if (!chrome_url_data_manager_.get())
745 chrome_url_data_manager_.reset( 708 chrome_url_data_manager_.reset(
746 new ChromeURLDataManager( 709 new ChromeURLDataManager(
747 base::Callback<ChromeURLDataManagerBackend*(void)>())); 710 base::Callback<ChromeURLDataManagerBackend*(void)>()));
748 return chrome_url_data_manager_.get(); 711 return chrome_url_data_manager_.get();
(...skipping 22 matching lines...) Expand all
771 void TestingProfile::DestroyWebDataService() { 734 void TestingProfile::DestroyWebDataService() {
772 if (!web_data_service_.get()) 735 if (!web_data_service_.get())
773 return; 736 return;
774 737
775 web_data_service_->Shutdown(); 738 web_data_service_->Shutdown();
776 } 739 }
777 740
778 bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) { 741 bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
779 return true; 742 return true;
780 } 743 }
OLDNEW
« no previous file with comments | « chrome/test/base/testing_profile.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698