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 11 matching lines...) Expand all Loading... | |
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" | |
33 #include "chrome/browser/history/chrome_history_client_factory.h" | |
32 #include "chrome/browser/history/history_backend.h" | 34 #include "chrome/browser/history/history_backend.h" |
33 #include "chrome/browser/history/history_db_task.h" | 35 #include "chrome/browser/history/history_db_task.h" |
34 #include "chrome/browser/history/history_service.h" | 36 #include "chrome/browser/history/history_service.h" |
35 #include "chrome/browser/history/history_service_factory.h" | 37 #include "chrome/browser/history/history_service_factory.h" |
36 #include "chrome/browser/history/top_sites.h" | 38 #include "chrome/browser/history/top_sites.h" |
37 #include "chrome/browser/history/web_history_service_factory.h" | 39 #include "chrome/browser/history/web_history_service_factory.h" |
38 #include "chrome/browser/net/pref_proxy_config_tracker.h" | 40 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
39 #include "chrome/browser/net/proxy_service_factory.h" | 41 #include "chrome/browser/net/proxy_service_factory.h" |
40 #include "chrome/browser/notifications/desktop_notification_service.h" | 42 #include "chrome/browser/notifications/desktop_notification_service.h" |
41 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 43 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 static KeyedService* BuildFaviconService(content::BrowserContext* profile) { | 420 static KeyedService* BuildFaviconService(content::BrowserContext* profile) { |
419 return new FaviconService(static_cast<Profile*>(profile)); | 421 return new FaviconService(static_cast<Profile*>(profile)); |
420 } | 422 } |
421 | 423 |
422 void TestingProfile::CreateFaviconService() { | 424 void TestingProfile::CreateFaviconService() { |
423 // It is up to the caller to create the history service if one is needed. | 425 // It is up to the caller to create the history service if one is needed. |
424 FaviconServiceFactory::GetInstance()->SetTestingFactory( | 426 FaviconServiceFactory::GetInstance()->SetTestingFactory( |
425 this, BuildFaviconService); | 427 this, BuildFaviconService); |
426 } | 428 } |
427 | 429 |
428 static KeyedService* BuildHistoryService(content::BrowserContext* profile) { | 430 static KeyedService* BuildHistoryService(content::BrowserContext* context) { |
429 return new HistoryService(NULL, static_cast<Profile*>(profile)); | 431 Profile* profile = static_cast<Profile*>(context); |
432 return new HistoryService( | |
433 ChromeHistoryClientFactory::GetForProfile(profile), profile); | |
430 } | 434 } |
431 | 435 |
432 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 436 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
433 DestroyHistoryService(); | 437 DestroyHistoryService(); |
434 if (delete_file) { | 438 if (delete_file) { |
435 base::FilePath path = GetPath(); | 439 base::FilePath path = GetPath(); |
436 path = path.Append(chrome::kHistoryFilename); | 440 path = path.Append(chrome::kHistoryFilename); |
437 if (!base::DeleteFile(path, false) || base::PathExists(path)) | 441 if (!base::DeleteFile(path, false) || base::PathExists(path)) |
438 return false; | 442 return false; |
439 } | 443 } |
440 // This will create and init the history service. | 444 // This will create and init the history service. |
441 HistoryService* history_service = static_cast<HistoryService*>( | 445 HistoryService* history_service = static_cast<HistoryService*>( |
442 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 446 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
443 this, BuildHistoryService)); | 447 this, BuildHistoryService)); |
444 if (!history_service->Init(this->GetPath(), | 448 if (!history_service->Init(this->GetPath(), no_db)) { |
445 BookmarkModelFactory::GetForProfile(this), | |
446 no_db)) { | |
447 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); | 449 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); |
448 } | 450 } |
449 // Disable WebHistoryService by default, since it makes network requests. | 451 // Disable WebHistoryService by default, since it makes network requests. |
450 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); | 452 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); |
451 return true; | 453 return true; |
452 } | 454 } |
453 | 455 |
454 void TestingProfile::DestroyHistoryService() { | 456 void TestingProfile::DestroyHistoryService() { |
455 HistoryService* history_service = | 457 HistoryService* history_service = |
456 HistoryServiceFactory::GetForProfileWithoutCreating(this); | 458 HistoryServiceFactory::GetForProfileWithoutCreating(this); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 bookmark_client->model()->Load( | 502 bookmark_client->model()->Load( |
501 profile->GetPrefs(), | 503 profile->GetPrefs(), |
502 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), | 504 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), |
503 profile->GetPath(), | 505 profile->GetPath(), |
504 profile->GetIOTaskRunner(), | 506 profile->GetIOTaskRunner(), |
505 content::BrowserThread::GetMessageLoopProxyForThread( | 507 content::BrowserThread::GetMessageLoopProxyForThread( |
506 content::BrowserThread::UI)); | 508 content::BrowserThread::UI)); |
507 return bookmark_client; | 509 return bookmark_client; |
508 } | 510 } |
509 | 511 |
512 static KeyedService* BuildChromeHistoryClient( | |
513 content::BrowserContext* context) { | |
514 Profile* profile = static_cast<Profile*>(context); | |
515 return new ChromeHistoryClient( | |
516 BookmarkModelFactory::GetForProfile(profile)); | |
blundell
2014/06/02 13:02:36
Is this needed? i.e., is it different from what Ch
sdefresne
2014/06/03 10:42:04
Yes this is required, since ChromeHistoryClientFac
| |
517 } | |
518 | |
510 void TestingProfile::CreateBookmarkModel(bool delete_file) { | 519 void TestingProfile::CreateBookmarkModel(bool delete_file) { |
511 if (delete_file) { | 520 if (delete_file) { |
512 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); | 521 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); |
513 base::DeleteFile(path, false); | 522 base::DeleteFile(path, false); |
514 } | 523 } |
515 // This will create a bookmark model. | 524 // This will create a bookmark model. |
516 BookmarkModel* bookmark_service = | 525 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( |
517 static_cast<ChromeBookmarkClient*>( | 526 this, BuildChromeHistoryClient); |
518 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( | 527 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( |
519 this, BuildBookmarkModel))->model(); | 528 this, BuildBookmarkModel); |
520 | |
521 HistoryService* history_service = | |
522 HistoryServiceFactory::GetForProfileWithoutCreating(this); | |
523 if (history_service) { | |
524 history_service->history_backend_->bookmark_service_ = bookmark_service; | |
525 history_service->history_backend_->expirer_.bookmark_service_ = | |
526 bookmark_service; | |
527 } | |
528 } | 529 } |
529 | 530 |
530 static KeyedService* BuildWebDataService(content::BrowserContext* profile) { | 531 static KeyedService* BuildWebDataService(content::BrowserContext* profile) { |
531 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); | 532 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); |
532 } | 533 } |
533 | 534 |
534 void TestingProfile::CreateWebDataService() { | 535 void TestingProfile::CreateWebDataService() { |
535 WebDataServiceFactory::GetInstance()->SetTestingFactory( | 536 WebDataServiceFactory::GetInstance()->SetTestingFactory( |
536 this, BuildWebDataService); | 537 this, BuildWebDataService); |
537 } | 538 } |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
972 path_, | 973 path_, |
973 delegate_, | 974 delegate_, |
974 extension_policy_, | 975 extension_policy_, |
975 pref_service_.Pass(), | 976 pref_service_.Pass(), |
976 incognito_, | 977 incognito_, |
977 guest_session_, | 978 guest_session_, |
978 managed_user_id_, | 979 managed_user_id_, |
979 policy_service_.Pass(), | 980 policy_service_.Pass(), |
980 testing_factories_)); | 981 testing_factories_)); |
981 } | 982 } |
OLD | NEW |