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

Side by Side Diff: ios/chrome/browser/browser_state/test_chrome_browser_state.mm

Issue 2459823002: [Sync] Rename syncable_prefs to sync_preferences. (Closed)
Patch Set: Created 4 years, 1 month 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 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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "components/bookmarks/browser/bookmark_model.h" 20 #include "components/bookmarks/browser/bookmark_model.h"
21 #include "components/bookmarks/common/bookmark_constants.h" 21 #include "components/bookmarks/common/bookmark_constants.h"
22 #include "components/history/core/browser/history_constants.h" 22 #include "components/history/core/browser/history_constants.h"
23 #include "components/history/core/browser/history_database_params.h" 23 #include "components/history/core/browser/history_database_params.h"
24 #include "components/history/core/browser/history_service.h" 24 #include "components/history/core/browser/history_service.h"
25 #include "components/history/core/browser/top_sites.h" 25 #include "components/history/core/browser/top_sites.h"
26 #include "components/history/core/browser/visit_delegate.h" 26 #include "components/history/core/browser/visit_delegate.h"
27 #include "components/history/ios/browser/history_database_helper.h" 27 #include "components/history/ios/browser/history_database_helper.h"
28 #include "components/keyed_service/core/service_access_type.h" 28 #include "components/keyed_service/core/service_access_type.h"
29 #include "components/keyed_service/ios/browser_state_dependency_manager.h" 29 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
30 #include "components/syncable_prefs/pref_service_syncable.h" 30 #include "components/sync_preferences/pref_service_syncable.h"
31 #include "components/syncable_prefs/testing_pref_service_syncable.h" 31 #include "components/sync_preferences/testing_pref_service_syncable.h"
32 #include "components/user_prefs/user_prefs.h" 32 #include "components/user_prefs/user_prefs.h"
33 #include "components/webdata_services/web_data_service_wrapper.h" 33 #include "components/webdata_services/web_data_service_wrapper.h"
34 #include "ios/chrome/browser/application_context.h" 34 #include "ios/chrome/browser/application_context.h"
35 #include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h" 35 #include "ios/chrome/browser/autocomplete/in_memory_url_index_factory.h"
36 #include "ios/chrome/browser/bookmarks/bookmark_client_impl.h" 36 #include "ios/chrome/browser/bookmarks/bookmark_client_impl.h"
37 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 37 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
38 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories .h" 38 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories .h"
39 #include "ios/chrome/browser/history/history_client_impl.h" 39 #include "ios/chrome/browser/history/history_client_impl.h"
40 #include "ios/chrome/browser/history/history_service_factory.h" 40 #include "ios/chrome/browser/history/history_service_factory.h"
41 #include "ios/chrome/browser/history/top_sites_factory.h" 41 #include "ios/chrome/browser/history/top_sites_factory.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 otr_browser_state_(nullptr), 122 otr_browser_state_(nullptr),
123 original_browser_state_(original_browser_state) { 123 original_browser_state_(original_browser_state) {
124 // Not calling Init() here as the bi-directional link between original and 124 // Not calling Init() here as the bi-directional link between original and
125 // off-the-record TestChromeBrowserState must be established before this 125 // off-the-record TestChromeBrowserState must be established before this
126 // method can be called. 126 // method can be called.
127 DCHECK(original_browser_state_); 127 DCHECK(original_browser_state_);
128 } 128 }
129 129
130 TestChromeBrowserState::TestChromeBrowserState( 130 TestChromeBrowserState::TestChromeBrowserState(
131 const base::FilePath& path, 131 const base::FilePath& path,
132 std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs, 132 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs,
133 const TestingFactories& testing_factories, 133 const TestingFactories& testing_factories,
134 const RefcountedTestingFactories& refcounted_testing_factories) 134 const RefcountedTestingFactories& refcounted_testing_factories)
135 : state_path_(path), 135 : state_path_(path),
136 prefs_(std::move(prefs)), 136 prefs_(std::move(prefs)),
137 testing_prefs_(nullptr), 137 testing_prefs_(nullptr),
138 otr_browser_state_(nullptr), 138 otr_browser_state_(nullptr),
139 original_browser_state_(nullptr) { 139 original_browser_state_(nullptr) {
140 Init(); 140 Init();
141 141
142 for (const auto& pair : testing_factories) { 142 for (const auto& pair : testing_factories) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (prefs_) { 180 if (prefs_) {
181 // If user passed a custom PrefServiceSyncable, then leave |testing_prefs_| 181 // If user passed a custom PrefServiceSyncable, then leave |testing_prefs_|
182 // unset as it is not possible to determine its type. 182 // unset as it is not possible to determine its type.
183 } else if (IsOffTheRecord()) { 183 } else if (IsOffTheRecord()) {
184 // This leaves |testing_prefs_| unset as CreateIncognitoBrowserStatePrefs() 184 // This leaves |testing_prefs_| unset as CreateIncognitoBrowserStatePrefs()
185 // does not return a TestingPrefServiceSyncable. 185 // does not return a TestingPrefServiceSyncable.
186 DCHECK(original_browser_state_); 186 DCHECK(original_browser_state_);
187 prefs_ = 187 prefs_ =
188 CreateIncognitoBrowserStatePrefs(original_browser_state_->prefs_.get()); 188 CreateIncognitoBrowserStatePrefs(original_browser_state_->prefs_.get());
189 } else { 189 } else {
190 testing_prefs_ = new syncable_prefs::TestingPrefServiceSyncable(); 190 testing_prefs_ = new sync_preferences::TestingPrefServiceSyncable();
191 RegisterBrowserStatePrefs(testing_prefs_->registry()); 191 RegisterBrowserStatePrefs(testing_prefs_->registry());
192 prefs_.reset(testing_prefs_); 192 prefs_.reset(testing_prefs_);
193 } 193 }
194 user_prefs::UserPrefs::Set(this, prefs_.get()); 194 user_prefs::UserPrefs::Set(this, prefs_.get());
195 195
196 // Prefs for incognito TestChromeBrowserState are set in 196 // Prefs for incognito TestChromeBrowserState are set in
197 // CreateIncognitoBrowserStatePrefs(). 197 // CreateIncognitoBrowserStatePrefs().
198 if (!IsOffTheRecord()) { 198 if (!IsOffTheRecord()) {
199 user_prefs::PrefRegistrySyncable* pref_registry = 199 user_prefs::PrefRegistrySyncable* pref_registry =
200 static_cast<user_prefs::PrefRegistrySyncable*>( 200 static_cast<user_prefs::PrefRegistrySyncable*>(
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // HistoryService instance associated with the TestChromeBrowserState. 371 // HistoryService instance associated with the TestChromeBrowserState.
372 ios::HistoryServiceFactory::GetInstance()->SetTestingFactory(this, nullptr); 372 ios::HistoryServiceFactory::GetInstance()->SetTestingFactory(this, nullptr);
373 373
374 // Wait for the backend class to terminate before deleting the files and 374 // Wait for the backend class to terminate before deleting the files and
375 // moving to the next test. Note: if this never terminates, somebody is 375 // moving to the next test. Note: if this never terminates, somebody is
376 // probably leaking a reference to the history backend, so it never calls 376 // probably leaking a reference to the history backend, so it never calls
377 // our destroy task. 377 // our destroy task.
378 run_loop.Run(); 378 run_loop.Run();
379 } 379 }
380 380
381 syncable_prefs::TestingPrefServiceSyncable* 381 sync_preferences::TestingPrefServiceSyncable*
382 TestChromeBrowserState::GetTestingPrefService() { 382 TestChromeBrowserState::GetTestingPrefService() {
383 DCHECK(prefs_); 383 DCHECK(prefs_);
384 DCHECK(testing_prefs_); 384 DCHECK(testing_prefs_);
385 return testing_prefs_; 385 return testing_prefs_;
386 } 386 }
387 387
388 TestChromeBrowserState::Builder::Builder() : build_called_(false) {} 388 TestChromeBrowserState::Builder::Builder() : build_called_(false) {}
389 389
390 TestChromeBrowserState::Builder::~Builder() {} 390 TestChromeBrowserState::Builder::~Builder() {}
391 391
(...skipping 10 matching lines...) Expand all
402 DCHECK(!build_called_); 402 DCHECK(!build_called_);
403 refcounted_testing_factories_.push_back(std::make_pair(service_factory, cb)); 403 refcounted_testing_factories_.push_back(std::make_pair(service_factory, cb));
404 } 404 }
405 405
406 void TestChromeBrowserState::Builder::SetPath(const base::FilePath& path) { 406 void TestChromeBrowserState::Builder::SetPath(const base::FilePath& path) {
407 DCHECK(!build_called_); 407 DCHECK(!build_called_);
408 state_path_ = path; 408 state_path_ = path;
409 } 409 }
410 410
411 void TestChromeBrowserState::Builder::SetPrefService( 411 void TestChromeBrowserState::Builder::SetPrefService(
412 std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs) { 412 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs) {
413 DCHECK(!build_called_); 413 DCHECK(!build_called_);
414 pref_service_ = std::move(prefs); 414 pref_service_ = std::move(prefs);
415 } 415 }
416 416
417 std::unique_ptr<TestChromeBrowserState> 417 std::unique_ptr<TestChromeBrowserState>
418 TestChromeBrowserState::Builder::Build() { 418 TestChromeBrowserState::Builder::Build() {
419 DCHECK(!build_called_); 419 DCHECK(!build_called_);
420 return base::WrapUnique(new TestChromeBrowserState( 420 return base::WrapUnique(new TestChromeBrowserState(
421 state_path_, std::move(pref_service_), testing_factories_, 421 state_path_, std::move(pref_service_), testing_factories_,
422 refcounted_testing_factories_)); 422 refcounted_testing_factories_));
423 } 423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698