OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 5 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "components/webdata_services/web_data_service_wrapper.h" | 30 #include "components/webdata_services/web_data_service_wrapper.h" |
31 #include "ios/chrome/browser/application_context.h" | 31 #include "ios/chrome/browser/application_context.h" |
32 #include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h" | 32 #include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h" |
33 #include "ios/chrome/browser/bookmarks/bookmark_client_impl.h" | 33 #include "ios/chrome/browser/bookmarks/bookmark_client_impl.h" |
34 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 34 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
35 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories
.h" | 35 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories
.h" |
36 #include "ios/chrome/browser/history/history_client_impl.h" | 36 #include "ios/chrome/browser/history/history_client_impl.h" |
37 #include "ios/chrome/browser/history/history_service_factory.h" | 37 #include "ios/chrome/browser/history/history_service_factory.h" |
38 #include "ios/chrome/browser/history/top_sites_factory.h" | 38 #include "ios/chrome/browser/history/top_sites_factory.h" |
39 #include "ios/chrome/browser/history/web_history_service_factory.h" | 39 #include "ios/chrome/browser/history/web_history_service_factory.h" |
40 #include "ios/chrome/browser/pref_names.h" | |
41 #include "ios/chrome/browser/prefs/browser_prefs.h" | 40 #include "ios/chrome/browser/prefs/browser_prefs.h" |
42 #include "ios/chrome/browser/prefs/ios_chrome_pref_service_factory.h" | 41 #include "ios/chrome/browser/prefs/ios_chrome_pref_service_factory.h" |
43 #include "ios/chrome/browser/sync/glue/sync_start_util.h" | 42 #include "ios/chrome/browser/sync/glue/sync_start_util.h" |
44 #include "ios/chrome/browser/web_data_service_factory.h" | 43 #include "ios/chrome/browser/web_data_service_factory.h" |
45 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 44 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
46 #include "ios/web/public/web_thread.h" | 45 #include "ios/web/public/web_thread.h" |
47 #include "net/url_request/url_request_test_util.h" | 46 #include "net/url_request/url_request_test_util.h" |
48 | 47 |
49 namespace { | 48 namespace { |
50 scoped_ptr<KeyedService> BuildHistoryService(web::BrowserState* context) { | 49 scoped_ptr<KeyedService> BuildHistoryService(web::BrowserState* context) { |
51 ios::ChromeBrowserState* browser_state = | 50 ios::ChromeBrowserState* browser_state = |
52 ios::ChromeBrowserState::FromBrowserState(context); | 51 ios::ChromeBrowserState::FromBrowserState(context); |
53 return make_scoped_ptr(new history::HistoryService( | 52 return make_scoped_ptr(new history::HistoryService( |
54 make_scoped_ptr(new HistoryClientImpl( | 53 make_scoped_ptr(new HistoryClientImpl( |
55 ios::BookmarkModelFactory::GetForBrowserState(browser_state))), | 54 ios::BookmarkModelFactory::GetForBrowserState(browser_state))), |
56 nullptr)); | 55 nullptr)); |
57 } | 56 } |
58 | 57 |
59 scoped_ptr<KeyedService> BuildBookmarkModel(web::BrowserState* context) { | 58 scoped_ptr<KeyedService> BuildBookmarkModel(web::BrowserState* context) { |
60 ios::ChromeBrowserState* browser_state = | 59 ios::ChromeBrowserState* browser_state = |
61 ios::ChromeBrowserState::FromBrowserState(context); | 60 ios::ChromeBrowserState::FromBrowserState(context); |
62 scoped_ptr<bookmarks::BookmarkModel> bookmark_model( | 61 scoped_ptr<bookmarks::BookmarkModel> bookmark_model( |
63 new bookmarks::BookmarkModel( | 62 new bookmarks::BookmarkModel( |
64 make_scoped_ptr(new BookmarkClientImpl(browser_state)))); | 63 make_scoped_ptr(new BookmarkClientImpl(browser_state)))); |
65 bookmark_model->Load( | 64 bookmark_model->Load( |
66 browser_state->GetPrefs(), | 65 browser_state->GetPrefs(), |
67 browser_state->GetPrefs()->GetString(prefs::kAcceptLanguages), | |
68 browser_state->GetStatePath(), browser_state->GetIOTaskRunner(), | 66 browser_state->GetStatePath(), browser_state->GetIOTaskRunner(), |
69 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI)); | 67 web::WebThread::GetTaskRunnerForThread(web::WebThread::UI)); |
70 return std::move(bookmark_model); | 68 return std::move(bookmark_model); |
71 } | 69 } |
72 | 70 |
73 void NotReachedErrorCallback(WebDataServiceWrapper::ErrorType error_type, | 71 void NotReachedErrorCallback(WebDataServiceWrapper::ErrorType error_type, |
74 sql::InitStatus status) { | 72 sql::InitStatus status) { |
75 NOTREACHED(); | 73 NOTREACHED(); |
76 } | 74 } |
77 | 75 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 if (!base::DeleteFile(path, false) && base::PathExists(path)) | 325 if (!base::DeleteFile(path, false) && base::PathExists(path)) |
328 return false; | 326 return false; |
329 } | 327 } |
330 | 328 |
331 // Create and initialize the HistoryService, but destroy it if the init fails. | 329 // Create and initialize the HistoryService, but destroy it if the init fails. |
332 history::HistoryService* history_service = | 330 history::HistoryService* history_service = |
333 static_cast<history::HistoryService*>( | 331 static_cast<history::HistoryService*>( |
334 ios::HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 332 ios::HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
335 this, &BuildHistoryService)); | 333 this, &BuildHistoryService)); |
336 if (!history_service->Init( | 334 if (!history_service->Init( |
337 GetPrefs()->GetString(prefs::kAcceptLanguages), | |
338 history::HistoryDatabaseParamsForPath( | 335 history::HistoryDatabaseParamsForPath( |
339 GetOriginalChromeBrowserState()->GetStatePath()))) { | 336 GetOriginalChromeBrowserState()->GetStatePath()))) { |
340 ios::HistoryServiceFactory::GetInstance()->SetTestingFactory(this, nullptr); | 337 ios::HistoryServiceFactory::GetInstance()->SetTestingFactory(this, nullptr); |
341 return false; | 338 return false; |
342 } | 339 } |
343 | 340 |
344 // Some tests expect that CreateHistoryService() will also make the | 341 // Some tests expect that CreateHistoryService() will also make the |
345 // InMemoryURLIndex available. | 342 // InMemoryURLIndex available. |
346 ios::InMemoryURLIndexFactory::GetInstance()->SetTestingFactory( | 343 ios::InMemoryURLIndexFactory::GetInstance()->SetTestingFactory( |
347 this, ios::InMemoryURLIndexFactory::GetDefaultFactory()); | 344 this, ios::InMemoryURLIndexFactory::GetDefaultFactory()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 DCHECK(!build_called_); | 414 DCHECK(!build_called_); |
418 pref_service_ = std::move(prefs); | 415 pref_service_ = std::move(prefs); |
419 } | 416 } |
420 | 417 |
421 scoped_ptr<TestChromeBrowserState> TestChromeBrowserState::Builder::Build() { | 418 scoped_ptr<TestChromeBrowserState> TestChromeBrowserState::Builder::Build() { |
422 DCHECK(!build_called_); | 419 DCHECK(!build_called_); |
423 return make_scoped_ptr(new TestChromeBrowserState( | 420 return make_scoped_ptr(new TestChromeBrowserState( |
424 state_path_, std::move(pref_service_), testing_factories_, | 421 state_path_, std::move(pref_service_), testing_factories_, |
425 refcounted_testing_factories_)); | 422 refcounted_testing_factories_)); |
426 } | 423 } |
OLD | NEW |