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

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

Issue 815983002: Topsites become keyedService based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: For trybot Created 5 years, 11 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 "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/prefs/testing_pref_store.h" 12 #include "base/prefs/testing_pref_store.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/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_factory.h" 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
17 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 17 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
18 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" 18 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chrome_notification_types.h" 20 #include "chrome/browser/chrome_notification_types.h"
21 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" 21 #include "chrome/browser/favicon/chrome_favicon_client_factory.h"
22 #include "chrome/browser/favicon/favicon_service.h" 22 #include "chrome/browser/favicon/favicon_service.h"
23 #include "chrome/browser/favicon/favicon_service_factory.h" 23 #include "chrome/browser/favicon/favicon_service_factory.h"
24 #include "chrome/browser/history/chrome_history_client.h" 24 #include "chrome/browser/history/chrome_history_client.h"
25 #include "chrome/browser/history/chrome_history_client_factory.h" 25 #include "chrome/browser/history/chrome_history_client_factory.h"
26 #include "chrome/browser/history/history_backend.h" 26 #include "chrome/browser/history/history_backend.h"
27 #include "chrome/browser/history/history_service.h" 27 #include "chrome/browser/history/history_service.h"
28 #include "chrome/browser/history/history_service_factory.h" 28 #include "chrome/browser/history/history_service_factory.h"
29 #include "chrome/browser/history/top_sites.h" 29 #include "chrome/browser/history/top_sites.h"
30 #include "chrome/browser/history/top_sites_impl.h"
31 #include "chrome/browser/history/top_sites_factory.h"
30 #include "chrome/browser/history/web_history_service_factory.h" 32 #include "chrome/browser/history/web_history_service_factory.h"
31 #include "chrome/browser/net/pref_proxy_config_tracker.h" 33 #include "chrome/browser/net/pref_proxy_config_tracker.h"
32 #include "chrome/browser/net/proxy_service_factory.h" 34 #include "chrome/browser/net/proxy_service_factory.h"
33 #include "chrome/browser/notifications/desktop_notification_service.h" 35 #include "chrome/browser/notifications/desktop_notification_service.h"
34 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 36 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
35 #include "chrome/browser/policy/profile_policy_connector.h" 37 #include "chrome/browser/policy/profile_policy_connector.h"
36 #include "chrome/browser/policy/profile_policy_connector_factory.h" 38 #include "chrome/browser/policy/profile_policy_connector_factory.h"
37 #include "chrome/browser/prefs/browser_prefs.h" 39 #include "chrome/browser/prefs/browser_prefs.h"
38 #include "chrome/browser/prefs/pref_service_syncable.h" 40 #include "chrome/browser/prefs/pref_service_syncable.h"
39 #include "chrome/browser/prerender/prerender_manager.h" 41 #include "chrome/browser/prerender/prerender_manager.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 219 }
218 220
219 KeyedService* BuildChromeBookmarkClient( 221 KeyedService* BuildChromeBookmarkClient(
220 content::BrowserContext* context) { 222 content::BrowserContext* context) {
221 return new ChromeBookmarkClient(static_cast<Profile*>(context)); 223 return new ChromeBookmarkClient(static_cast<Profile*>(context));
222 } 224 }
223 225
224 KeyedService* BuildChromeHistoryClient( 226 KeyedService* BuildChromeHistoryClient(
225 content::BrowserContext* context) { 227 content::BrowserContext* context) {
226 Profile* profile = static_cast<Profile*>(context); 228 Profile* profile = static_cast<Profile*>(context);
229 scoped_refptr<history::TopSites> top_sites =
230 TopSitesFactory::GetForProfile(profile);
227 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile), 231 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile),
228 profile, 232 profile, top_sites);
229 profile->GetTopSites());
230 } 233 }
231 234
232 void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, 235 void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type,
233 sql::InitStatus status) { 236 sql::InitStatus status) {
234 NOTREACHED(); 237 NOTREACHED();
235 } 238 }
236 239
237 KeyedService* BuildWebDataService(content::BrowserContext* context) { 240 KeyedService* BuildWebDataService(content::BrowserContext* context) {
238 const base::FilePath& context_path = context->GetPath(); 241 const base::FilePath& context_path = context->GetPath();
239 return new WebDataServiceWrapper( 242 return new WebDataServiceWrapper(
240 context_path, g_browser_process->GetApplicationLocale(), 243 context_path, g_browser_process->GetApplicationLocale(),
241 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 244 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
242 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), 245 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
243 sync_start_util::GetFlareForSyncableService(context_path), 246 sync_start_util::GetFlareForSyncableService(context_path),
244 &TestProfileErrorCallback); 247 &TestProfileErrorCallback);
245 } 248 }
246 249
250 scoped_refptr<RefcountedKeyedService> BuildTopSites(
251 content::BrowserContext* profile) {
252 history::TopSitesImpl* top_sites =
253 new history::TopSitesImpl(static_cast<Profile*>(profile));
254 top_sites->Init(profile->GetPath().Append(chrome::kTopSitesFilename));
255 return make_scoped_refptr(top_sites);
256 }
257
247 } // namespace 258 } // namespace
248 259
249 // static 260 // static
250 #if defined(OS_CHROMEOS) 261 #if defined(OS_CHROMEOS)
251 // Must be kept in sync with 262 // Must be kept in sync with
252 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. 263 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
253 const char TestingProfile::kTestUserProfileDir[] = "test-user"; 264 const char TestingProfile::kTestUserProfileDir[] = "test-user";
254 #else 265 #else
255 const char TestingProfile::kTestUserProfileDir[] = "Default"; 266 const char TestingProfile::kTestUserProfileDir[] = "Default";
256 #endif 267 #endif
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 458
448 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( 459 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
449 this); 460 this);
450 461
451 #if defined(ENABLE_NOTIFICATIONS) 462 #if defined(ENABLE_NOTIFICATIONS)
452 // Install profile keyed service factory hooks for dummy/test services 463 // Install profile keyed service factory hooks for dummy/test services
453 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( 464 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
454 this, CreateTestDesktopNotificationService); 465 this, CreateTestDesktopNotificationService);
455 #endif 466 #endif
456 467
468 CreateTopSites();
sdefresne 2015/01/21 17:57:24 This is incorrect, we do not want to unconditional
469
457 #if defined(ENABLE_SUPERVISED_USERS) 470 #if defined(ENABLE_SUPERVISED_USERS)
458 if (!IsOffTheRecord()) { 471 if (!IsOffTheRecord()) {
459 SupervisedUserSettingsService* settings_service = 472 SupervisedUserSettingsService* settings_service =
460 SupervisedUserSettingsServiceFactory::GetForProfile(this); 473 SupervisedUserSettingsServiceFactory::GetForProfile(this);
461 TestingPrefStore* store = new TestingPrefStore(); 474 TestingPrefStore* store = new TestingPrefStore();
462 settings_service->Init(store); 475 settings_service->Init(store);
463 store->SetInitializationCompleted(); 476 store->SetInitializationCompleted();
464 } 477 }
465 #endif 478 #endif
466 479
(...skipping 25 matching lines...) Expand all
492 // Any objects holding live URLFetchers should be deleted before teardown. 505 // Any objects holding live URLFetchers should be deleted before teardown.
493 TemplateURLFetcherFactory::ShutdownForProfile(this); 506 TemplateURLFetcherFactory::ShutdownForProfile(this);
494 507
495 MaybeSendDestroyedNotification(); 508 MaybeSendDestroyedNotification();
496 509
497 browser_context_dependency_manager_->DestroyBrowserContextServices(this); 510 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
498 511
499 if (host_content_settings_map_.get()) 512 if (host_content_settings_map_.get())
500 host_content_settings_map_->ShutdownOnUIThread(); 513 host_content_settings_map_->ShutdownOnUIThread();
501 514
502 DestroyTopSites();
sdefresne 2015/01/21 17:57:24 Here too we need to cleanup if an instance of "Top
503
504 if (pref_proxy_config_tracker_.get()) 515 if (pref_proxy_config_tracker_.get())
505 pref_proxy_config_tracker_->DetachFromPrefService(); 516 pref_proxy_config_tracker_->DetachFromPrefService();
506 // Failing a post == leaks == heapcheck failure. Make that an immediate test 517 // Failing a post == leaks == heapcheck failure. Make that an immediate test
507 // failure. 518 // failure.
508 if (resource_context_) { 519 if (resource_context_) {
509 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, 520 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
510 resource_context_)); 521 resource_context_));
511 resource_context_ = NULL; 522 resource_context_ = NULL;
512 content::RunAllPendingInMessageLoop(BrowserThread::IO); 523 content::RunAllPendingInMessageLoop(BrowserThread::IO);
513 } 524 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 base::MessageLoop::current()->Run(); 575 base::MessageLoop::current()->Run();
565 576
566 // Make sure we don't have any event pending that could disrupt the next 577 // Make sure we don't have any event pending that could disrupt the next
567 // test. 578 // test.
568 base::MessageLoop::current()->PostTask(FROM_HERE, 579 base::MessageLoop::current()->PostTask(FROM_HERE,
569 base::MessageLoop::QuitClosure()); 580 base::MessageLoop::QuitClosure());
570 base::MessageLoop::current()->Run(); 581 base::MessageLoop::current()->Run();
571 } 582 }
572 583
573 void TestingProfile::CreateTopSites() { 584 void TestingProfile::CreateTopSites() {
574 DestroyTopSites(); 585 // TODO Jitu
575 top_sites_ = history::TopSites::Create( 586 // TopSitesFactory::GetInstance()->SetTestingFactory(this, BuildTopSites);
sdefresne 2015/01/21 17:57:24 If you comment this line, then the "BuildTopSites"
576 this, GetPath().Append(chrome::kTopSitesFilename));
577 }
578
579 void TestingProfile::SetTopSites(history::TopSites* top_sites) {
580 DestroyTopSites();
581 top_sites_ = top_sites;
582 }
583
584 void TestingProfile::DestroyTopSites() {
585 if (top_sites_.get()) {
sdefresne 2015/01/21 17:57:24 Once the "TopSites::ShutdownOnUIThread" is correct
586 top_sites_->Shutdown();
587 top_sites_ = NULL;
588 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
589 // need to be run to properly shutdown. Run all pending tasks now. This is
590 // normally handled by browser_process shutdown.
591 if (base::MessageLoop::current())
592 base::MessageLoop::current()->RunUntilIdle();
593 }
594 } 587 }
595 588
596 void TestingProfile::CreateBookmarkModel(bool delete_file) { 589 void TestingProfile::CreateBookmarkModel(bool delete_file) {
597 if (delete_file) { 590 if (delete_file) {
598 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); 591 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
599 base::DeleteFile(path, false); 592 base::DeleteFile(path, false);
600 } 593 }
601 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( 594 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory(
602 this, BuildChromeHistoryClient); 595 this, BuildChromeHistoryClient);
603 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( 596 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory(
(...skipping 24 matching lines...) Expand all
628 run_loop.Run(); 621 run_loop.Run();
629 index->set_restore_cache_observer(NULL); 622 index->set_restore_cache_observer(NULL);
630 DCHECK(index->restored()); 623 DCHECK(index->restored());
631 } 624 }
632 625
633 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? 626 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
634 void TestingProfile::BlockUntilTopSitesLoaded() { 627 void TestingProfile::BlockUntilTopSitesLoaded() {
635 scoped_refptr<content::MessageLoopRunner> runner = 628 scoped_refptr<content::MessageLoopRunner> runner =
636 new content::MessageLoopRunner; 629 new content::MessageLoopRunner;
637 WaitTopSitesLoadedObserver observer(runner.get()); 630 WaitTopSitesLoadedObserver observer(runner.get());
638 top_sites_->AddObserver(&observer); 631 scoped_refptr<history::TopSites> top_sites =
632 TopSitesFactory::GetForProfile(this);
633 top_sites->AddObserver(&observer);
639 runner->Run(); 634 runner->Run();
640 top_sites_->RemoveObserver(&observer); 635 top_sites->RemoveObserver(&observer);
641 } 636 }
642 637
643 void TestingProfile::SetGuestSession(bool guest) { 638 void TestingProfile::SetGuestSession(bool guest) {
644 guest_session_ = guest; 639 guest_session_ = guest;
645 } 640 }
646 641
647 base::FilePath TestingProfile::GetPath() const { 642 base::FilePath TestingProfile::GetPath() const {
648 return profile_path_; 643 return profile_path_;
649 } 644 }
650 645
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 this, profile_policy_connector_.get()); 783 this, profile_policy_connector_.get());
789 CHECK_EQ(profile_policy_connector_.get(), 784 CHECK_EQ(profile_policy_connector_.get(),
790 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); 785 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
791 } 786 }
792 787
793 PrefService* TestingProfile::GetPrefs() { 788 PrefService* TestingProfile::GetPrefs() {
794 DCHECK(prefs_); 789 DCHECK(prefs_);
795 return prefs_.get(); 790 return prefs_.get();
796 } 791 }
797 792
798 history::TopSites* TestingProfile::GetTopSites() {
799 return top_sites_.get();
800 }
801
802 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
803 return top_sites_.get();
804 }
805
806 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { 793 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
807 return NULL; 794 return NULL;
808 } 795 }
809 796
810 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { 797 net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
811 return GetDefaultStoragePartition(this)->GetURLRequestContext(); 798 return GetDefaultStoragePartition(this)->GetURLRequestContext();
812 } 799 }
813 800
814 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( 801 net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
815 content::ProtocolHandlerMap* protocol_handlers, 802 content::ProtocolHandlerMap* protocol_handlers,
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 #if defined(ENABLE_EXTENSIONS) 1052 #if defined(ENABLE_EXTENSIONS)
1066 extension_policy_, 1053 extension_policy_,
1067 #endif 1054 #endif
1068 pref_service_.Pass(), 1055 pref_service_.Pass(),
1069 original_profile, 1056 original_profile,
1070 guest_session_, 1057 guest_session_,
1071 supervised_user_id_, 1058 supervised_user_id_,
1072 policy_service_.Pass(), 1059 policy_service_.Pass(),
1073 testing_factories_); 1060 testing_factories_);
1074 } 1061 }
OLDNEW
« chrome/browser/ui/webui/ntp/suggestions_page_handler.cc ('K') | « chrome/test/base/testing_profile.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698