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

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

Issue 285233012: Abstract history dependencies on bookmarks through HistoryClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 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
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 11 matching lines...) Expand all
22 #include "chrome/browser/content_settings/host_content_settings_map.h" 22 #include "chrome/browser/content_settings/host_content_settings_map.h"
23 #include "chrome/browser/extensions/extension_service.h" 23 #include "chrome/browser/extensions/extension_service.h"
24 #include "chrome/browser/extensions/extension_special_storage_policy.h" 24 #include "chrome/browser/extensions/extension_special_storage_policy.h"
25 #include "chrome/browser/extensions/extension_system_factory.h" 25 #include "chrome/browser/extensions/extension_system_factory.h"
26 #include "chrome/browser/extensions/test_extension_system.h" 26 #include "chrome/browser/extensions/test_extension_system.h"
27 #include "chrome/browser/favicon/favicon_service.h" 27 #include "chrome/browser/favicon/favicon_service.h"
28 #include "chrome/browser/favicon/favicon_service_factory.h" 28 #include "chrome/browser/favicon/favicon_service_factory.h"
29 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" 29 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
30 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h" 30 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h"
31 #include "chrome/browser/guest_view/guest_view_manager.h" 31 #include "chrome/browser/guest_view/guest_view_manager.h"
32 #include "chrome/browser/history/chrome_history_client.h"
32 #include "chrome/browser/history/history_backend.h" 33 #include "chrome/browser/history/history_backend.h"
33 #include "chrome/browser/history/history_db_task.h" 34 #include "chrome/browser/history/history_db_task.h"
34 #include "chrome/browser/history/history_service.h" 35 #include "chrome/browser/history/history_service.h"
35 #include "chrome/browser/history/history_service_factory.h" 36 #include "chrome/browser/history/history_service_factory.h"
36 #include "chrome/browser/history/top_sites.h" 37 #include "chrome/browser/history/top_sites.h"
37 #include "chrome/browser/history/web_history_service_factory.h" 38 #include "chrome/browser/history/web_history_service_factory.h"
38 #include "chrome/browser/net/pref_proxy_config_tracker.h" 39 #include "chrome/browser/net/pref_proxy_config_tracker.h"
39 #include "chrome/browser/net/proxy_service_factory.h" 40 #include "chrome/browser/net/proxy_service_factory.h"
40 #include "chrome/browser/notifications/desktop_notification_service.h" 41 #include "chrome/browser/notifications/desktop_notification_service.h"
41 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 42 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 #endif // defined(ENABLE_CONFIGURATION_POLICY) 89 #endif // defined(ENABLE_CONFIGURATION_POLICY)
89 90
90 #if defined(ENABLE_MANAGED_USERS) 91 #if defined(ENABLE_MANAGED_USERS)
91 #include "chrome/browser/managed_mode/managed_user_settings_service.h" 92 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
92 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" 93 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
93 #endif 94 #endif
94 95
95 using base::Time; 96 using base::Time;
96 using content::BrowserThread; 97 using content::BrowserThread;
97 using content::DownloadManagerDelegate; 98 using content::DownloadManagerDelegate;
99 using history::ChromeHistoryClient;
98 using testing::NiceMock; 100 using testing::NiceMock;
99 using testing::Return; 101 using testing::Return;
100 102
101 namespace { 103 namespace {
102 104
103 // Task used to make sure history has finished processing a request. Intended 105 // Task used to make sure history has finished processing a request. Intended
104 // for use with BlockUntilHistoryProcessesPendingRequests. 106 // for use with BlockUntilHistoryProcessesPendingRequests.
105 107
106 class QuittingHistoryDBTask : public history::HistoryDBTask { 108 class QuittingHistoryDBTask : public history::HistoryDBTask {
107 public: 109 public:
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 return new FaviconService(static_cast<Profile*>(profile)); 422 return new FaviconService(static_cast<Profile*>(profile));
421 } 423 }
422 424
423 void TestingProfile::CreateFaviconService() { 425 void TestingProfile::CreateFaviconService() {
424 // It is up to the caller to create the history service if one is needed. 426 // It is up to the caller to create the history service if one is needed.
425 FaviconServiceFactory::GetInstance()->SetTestingFactory( 427 FaviconServiceFactory::GetInstance()->SetTestingFactory(
426 this, BuildFaviconService); 428 this, BuildFaviconService);
427 } 429 }
428 430
429 static KeyedService* BuildHistoryService(content::BrowserContext* profile) { 431 static KeyedService* BuildHistoryService(content::BrowserContext* profile) {
430 return new HistoryService(static_cast<Profile*>(profile)); 432 return new ChromeHistoryClient(static_cast<Profile*>(profile));
431 } 433 }
432 434
433 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { 435 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
434 DestroyHistoryService(); 436 DestroyHistoryService();
435 if (delete_file) { 437 if (delete_file) {
436 base::FilePath path = GetPath(); 438 base::FilePath path = GetPath();
437 path = path.Append(chrome::kHistoryFilename); 439 path = path.Append(chrome::kHistoryFilename);
438 if (!base::DeleteFile(path, false) || base::PathExists(path)) 440 if (!base::DeleteFile(path, false) || base::PathExists(path))
439 return false; 441 return false;
440 } 442 }
441 // This will create and init the history service. 443 // This will create and init the history service.
442 HistoryService* history_service = static_cast<HistoryService*>( 444 ChromeHistoryClient* history_client = static_cast<ChromeHistoryClient*>(
443 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( 445 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
444 this, BuildHistoryService)); 446 this, BuildHistoryService));
445 if (!history_service->Init(this->GetPath(), 447 HistoryService* history_service = history_client->history_service();
446 BookmarkModelFactory::GetForProfile(this), 448 if (!history_service->Init(this->GetPath(), no_db)) {
447 no_db)) {
448 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); 449 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
449 } 450 }
450 // Disable WebHistoryService by default, since it makes network requests. 451 // Disable WebHistoryService by default, since it makes network requests.
451 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); 452 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
452 return true; 453 return true;
453 } 454 }
454 455
455 void TestingProfile::DestroyHistoryService() { 456 void TestingProfile::DestroyHistoryService() {
456 HistoryService* history_service = 457 HistoryService* history_service =
457 HistoryServiceFactory::GetForProfileWithoutCreating(this); 458 HistoryServiceFactory::GetForProfileWithoutCreating(this);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 content::BrowserThread::UI)); 508 content::BrowserThread::UI));
508 return bookmark_client; 509 return bookmark_client;
509 } 510 }
510 511
511 void TestingProfile::CreateBookmarkModel(bool delete_file) { 512 void TestingProfile::CreateBookmarkModel(bool delete_file) {
512 if (delete_file) { 513 if (delete_file) {
513 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); 514 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
514 base::DeleteFile(path, false); 515 base::DeleteFile(path, false);
515 } 516 }
516 // This will create a bookmark model. 517 // This will create a bookmark model.
517 BookmarkModel* bookmark_service = 518 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
518 static_cast<ChromeBookmarkClient*>( 519 this, BuildBookmarkModel);
519 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
520 this, BuildBookmarkModel))->model();
521
522 HistoryService* history_service =
523 HistoryServiceFactory::GetForProfileWithoutCreating(this);
524 if (history_service) {
525 history_service->history_backend_->bookmark_service_ = bookmark_service;
526 history_service->history_backend_->expirer_.bookmark_service_ =
527 bookmark_service;
528 }
529 } 520 }
530 521
531 static KeyedService* BuildWebDataService(content::BrowserContext* profile) { 522 static KeyedService* BuildWebDataService(content::BrowserContext* profile) {
532 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); 523 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
533 } 524 }
534 525
535 void TestingProfile::CreateWebDataService() { 526 void TestingProfile::CreateWebDataService() {
536 WebDataServiceFactory::GetInstance()->SetTestingFactory( 527 WebDataServiceFactory::GetInstance()->SetTestingFactory(
537 this, BuildWebDataService); 528 this, BuildWebDataService);
538 } 529 }
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 path_, 976 path_,
986 delegate_, 977 delegate_,
987 extension_policy_, 978 extension_policy_,
988 pref_service_.Pass(), 979 pref_service_.Pass(),
989 incognito_, 980 incognito_,
990 guest_session_, 981 guest_session_,
991 managed_user_id_, 982 managed_user_id_,
992 policy_service_.Pass(), 983 policy_service_.Pass(),
993 testing_factories_)); 984 testing_factories_));
994 } 985 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698