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

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

Issue 777863002: Introduce new component webdata_services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix component build & gn build Created 6 years 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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "chrome/browser/profiles/profile_manager.h" 42 #include "chrome/browser/profiles/profile_manager.h"
43 #include "chrome/browser/profiles/storage_partition_descriptor.h" 43 #include "chrome/browser/profiles/storage_partition_descriptor.h"
44 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" 44 #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
45 #include "chrome/browser/webdata/web_data_service_factory.h" 45 #include "chrome/browser/webdata/web_data_service_factory.h"
46 #include "chrome/common/chrome_constants.h" 46 #include "chrome/common/chrome_constants.h"
47 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
48 #include "chrome/common/pref_names.h" 48 #include "chrome/common/pref_names.h"
49 #include "chrome/common/url_constants.h" 49 #include "chrome/common/url_constants.h"
50 #include "chrome/test/base/history_index_restore_observer.h" 50 #include "chrome/test/base/history_index_restore_observer.h"
51 #include "chrome/test/base/testing_pref_service_syncable.h" 51 #include "chrome/test/base/testing_pref_service_syncable.h"
52 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
52 #include "components/bookmarks/browser/bookmark_model.h" 53 #include "components/bookmarks/browser/bookmark_model.h"
53 #include "components/bookmarks/common/bookmark_constants.h" 54 #include "components/bookmarks/common/bookmark_constants.h"
54 #include "components/content_settings/core/browser/host_content_settings_map.h" 55 #include "components/content_settings/core/browser/host_content_settings_map.h"
55 #include "components/history/core/browser/history_constants.h" 56 #include "components/history/core/browser/history_constants.h"
56 #include "components/history/core/browser/top_sites_observer.h" 57 #include "components/history/core/browser/top_sites_observer.h"
57 #include "components/keyed_service/content/browser_context_dependency_manager.h" 58 #include "components/keyed_service/content/browser_context_dependency_manager.h"
58 #include "components/policy/core/common/policy_service.h" 59 #include "components/policy/core/common/policy_service.h"
59 #include "components/user_prefs/user_prefs.h" 60 #include "components/user_prefs/user_prefs.h"
61 #include "components/webdata_services/web_data_service_wrapper.h"
60 #include "content/public/browser/browser_thread.h" 62 #include "content/public/browser/browser_thread.h"
61 #include "content/public/browser/cookie_store_factory.h" 63 #include "content/public/browser/cookie_store_factory.h"
62 #include "content/public/browser/notification_service.h" 64 #include "content/public/browser/notification_service.h"
63 #include "content/public/browser/render_process_host.h" 65 #include "content/public/browser/render_process_host.h"
64 #include "content/public/browser/storage_partition.h" 66 #include "content/public/browser/storage_partition.h"
65 #include "content/public/test/mock_resource_context.h" 67 #include "content/public/test/mock_resource_context.h"
66 #include "content/public/test/test_utils.h" 68 #include "content/public/test/test_utils.h"
67 #include "extensions/common/constants.h" 69 #include "extensions/common/constants.h"
68 #include "net/cookies/cookie_monster.h" 70 #include "net/cookies/cookie_monster.h"
69 #include "net/url_request/url_request_context.h" 71 #include "net/url_request/url_request_context.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 scoped_ptr<net::URLRequestContext> context_; 178 scoped_ptr<net::URLRequestContext> context_;
177 }; 179 };
178 180
179 #if defined(ENABLE_NOTIFICATIONS) 181 #if defined(ENABLE_NOTIFICATIONS)
180 KeyedService* CreateTestDesktopNotificationService( 182 KeyedService* CreateTestDesktopNotificationService(
181 content::BrowserContext* profile) { 183 content::BrowserContext* profile) {
182 return new DesktopNotificationService(static_cast<Profile*>(profile)); 184 return new DesktopNotificationService(static_cast<Profile*>(profile));
183 } 185 }
184 #endif 186 #endif
185 187
188 KeyedService* BuildFaviconService(content::BrowserContext* profile) {
189 FaviconClient* favicon_client =
190 ChromeFaviconClientFactory::GetForProfile(static_cast<Profile*>(profile));
191 return new FaviconService(static_cast<Profile*>(profile), favicon_client);
192 }
193
194 KeyedService* BuildHistoryService(content::BrowserContext* context) {
195 Profile* profile = static_cast<Profile*>(context);
196 HistoryService* history_service = new HistoryService(
197 ChromeHistoryClientFactory::GetForProfile(profile), profile);
198 return history_service;
199 }
200
201 KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
202 Profile* profile = static_cast<Profile*>(context);
203 ChromeBookmarkClient* bookmark_client =
204 ChromeBookmarkClientFactory::GetForProfile(profile);
205 BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client);
206 bookmark_client->Init(bookmark_model);
207 bookmark_model->Load(profile->GetPrefs(),
208 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
209 profile->GetPath(),
210 profile->GetIOTaskRunner(),
211 content::BrowserThread::GetMessageLoopProxyForThread(
212 content::BrowserThread::UI));
213 return bookmark_model;
214 }
215
216 KeyedService* BuildChromeBookmarkClient(
217 content::BrowserContext* context) {
218 return new ChromeBookmarkClient(static_cast<Profile*>(context));
219 }
220
221 KeyedService* BuildChromeHistoryClient(
222 content::BrowserContext* context) {
223 Profile* profile = static_cast<Profile*>(context);
224 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile),
225 profile,
226 profile->GetTopSites());
227 }
228
229 void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type,
230 sql::InitStatus status) {
231 NOTREACHED();
232 }
233
234 KeyedService* BuildWebDataService(content::BrowserContext* profile) {
235 WebDataServiceWrapper* web_data_service_wrapper = new WebDataServiceWrapper(
236 static_cast<Profile*>(profile)->GetPath(),
237 g_browser_process->GetApplicationLocale(),
238 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
239 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
240 &TestProfileErrorCallback);
241 web_data_service_wrapper->GetAutofillWebData()->GetAutofillBackend(
242 base::Bind(&InitSyncableServicesOnDBThread,
243 web_data_service_wrapper->GetAutofillWebData(),
244 static_cast<Profile*>(profile)->GetPath(),
245 g_browser_process->GetApplicationLocale()));
246 return web_data_service_wrapper;
247 }
248
186 } // namespace 249 } // namespace
187 250
188 // static 251 // static
189 #if defined(OS_CHROMEOS) 252 #if defined(OS_CHROMEOS)
190 // Must be kept in sync with 253 // Must be kept in sync with
191 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. 254 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
192 const char TestingProfile::kTestUserProfileDir[] = "test-user"; 255 const char TestingProfile::kTestUserProfileDir[] = "test-user";
193 #else 256 #else
194 const char TestingProfile::kTestUserProfileDir[] = "Default"; 257 const char TestingProfile::kTestUserProfileDir[] = "Default";
195 #endif 258 #endif
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // Failing a post == leaks == heapcheck failure. Make that an immediate test 508 // Failing a post == leaks == heapcheck failure. Make that an immediate test
446 // failure. 509 // failure.
447 if (resource_context_) { 510 if (resource_context_) {
448 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, 511 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
449 resource_context_)); 512 resource_context_));
450 resource_context_ = NULL; 513 resource_context_ = NULL;
451 content::RunAllPendingInMessageLoop(BrowserThread::IO); 514 content::RunAllPendingInMessageLoop(BrowserThread::IO);
452 } 515 }
453 } 516 }
454 517
455 static KeyedService* BuildFaviconService(content::BrowserContext* profile) {
456 FaviconClient* favicon_client =
457 ChromeFaviconClientFactory::GetForProfile(static_cast<Profile*>(profile));
458 return new FaviconService(static_cast<Profile*>(profile), favicon_client);
459 }
460
461 void TestingProfile::CreateFaviconService() { 518 void TestingProfile::CreateFaviconService() {
462 // It is up to the caller to create the history service if one is needed. 519 // It is up to the caller to create the history service if one is needed.
463 FaviconServiceFactory::GetInstance()->SetTestingFactory( 520 FaviconServiceFactory::GetInstance()->SetTestingFactory(
464 this, BuildFaviconService); 521 this, BuildFaviconService);
465 } 522 }
466 523
467 static KeyedService* BuildHistoryService(content::BrowserContext* context) {
468 Profile* profile = static_cast<Profile*>(context);
469 HistoryService* history_service = new HistoryService(
470 ChromeHistoryClientFactory::GetForProfile(profile), profile);
471 return history_service;
472 }
473
474 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { 524 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
475 DestroyHistoryService(); 525 DestroyHistoryService();
476 if (delete_file) { 526 if (delete_file) {
477 base::FilePath path = GetPath(); 527 base::FilePath path = GetPath();
478 path = path.Append(history::kHistoryFilename); 528 path = path.Append(history::kHistoryFilename);
479 if (!base::DeleteFile(path, false) || base::PathExists(path)) 529 if (!base::DeleteFile(path, false) || base::PathExists(path))
480 return false; 530 return false;
481 } 531 }
482 // This will create and init the history service. 532 // This will create and init the history service.
483 HistoryService* history_service = static_cast<HistoryService*>( 533 HistoryService* history_service = static_cast<HistoryService*>(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 top_sites_->Shutdown(); 588 top_sites_->Shutdown();
539 top_sites_ = NULL; 589 top_sites_ = NULL;
540 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that 590 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
541 // need to be run to properly shutdown. Run all pending tasks now. This is 591 // need to be run to properly shutdown. Run all pending tasks now. This is
542 // normally handled by browser_process shutdown. 592 // normally handled by browser_process shutdown.
543 if (base::MessageLoop::current()) 593 if (base::MessageLoop::current())
544 base::MessageLoop::current()->RunUntilIdle(); 594 base::MessageLoop::current()->RunUntilIdle();
545 } 595 }
546 } 596 }
547 597
548 static KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
549 Profile* profile = static_cast<Profile*>(context);
550 ChromeBookmarkClient* bookmark_client =
551 ChromeBookmarkClientFactory::GetForProfile(profile);
552 BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client);
553 bookmark_client->Init(bookmark_model);
554 bookmark_model->Load(profile->GetPrefs(),
555 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
556 profile->GetPath(),
557 profile->GetIOTaskRunner(),
558 content::BrowserThread::GetMessageLoopProxyForThread(
559 content::BrowserThread::UI));
560 return bookmark_model;
561 }
562
563 static KeyedService* BuildChromeBookmarkClient(
564 content::BrowserContext* context) {
565 return new ChromeBookmarkClient(static_cast<Profile*>(context));
566 }
567
568 static KeyedService* BuildChromeHistoryClient(
569 content::BrowserContext* context) {
570 Profile* profile = static_cast<Profile*>(context);
571 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile),
572 profile,
573 profile->GetTopSites());
574 }
575
576 void TestingProfile::CreateBookmarkModel(bool delete_file) { 598 void TestingProfile::CreateBookmarkModel(bool delete_file) {
577 if (delete_file) { 599 if (delete_file) {
578 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); 600 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
579 base::DeleteFile(path, false); 601 base::DeleteFile(path, false);
580 } 602 }
581 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( 603 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory(
582 this, BuildChromeHistoryClient); 604 this, BuildChromeHistoryClient);
583 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( 605 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory(
584 this, BuildChromeBookmarkClient); 606 this, BuildChromeBookmarkClient);
585 // This creates the BookmarkModel. 607 // This creates the BookmarkModel.
586 ignore_result(BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( 608 ignore_result(BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
587 this, BuildBookmarkModel)); 609 this, BuildBookmarkModel));
588 } 610 }
589 611
590 static KeyedService* BuildWebDataService(content::BrowserContext* profile) {
591 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
592 }
593
594 void TestingProfile::CreateWebDataService() { 612 void TestingProfile::CreateWebDataService() {
595 WebDataServiceFactory::GetInstance()->SetTestingFactory( 613 WebDataServiceFactory::GetInstance()->SetTestingFactory(
596 this, BuildWebDataService); 614 this, BuildWebDataService);
597 } 615 }
598 616
599 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() { 617 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
600 // Only get the history service if it actually exists since the caller of the 618 // Only get the history service if it actually exists since the caller of the
601 // test should explicitly call CreateHistoryService to build it. 619 // test should explicitly call CreateHistoryService to build it.
602 HistoryService* history_service = 620 HistoryService* history_service =
603 HistoryServiceFactory::GetForProfileWithoutCreating(this); 621 HistoryServiceFactory::GetForProfileWithoutCreating(this);
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 #if defined(ENABLE_EXTENSIONS) 1060 #if defined(ENABLE_EXTENSIONS)
1043 extension_policy_, 1061 extension_policy_,
1044 #endif 1062 #endif
1045 pref_service_.Pass(), 1063 pref_service_.Pass(),
1046 original_profile, 1064 original_profile,
1047 guest_session_, 1065 guest_session_,
1048 supervised_user_id_, 1066 supervised_user_id_,
1049 policy_service_.Pass(), 1067 policy_service_.Pass(),
1050 testing_factories_); 1068 testing_factories_);
1051 } 1069 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698