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

Side by Side Diff: components/sync/core_impl/test/fake_sync_manager.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 "sync/internal_api/public/test/fake_sync_manager.h" 5 #include "components/sync/core/test/fake_sync_manager.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "sync/internal_api/public/http_post_provider_factory.h" 18 #include "components/sync/base/weak_handle.h"
19 #include "sync/internal_api/public/internal_components_factory.h" 19 #include "components/sync/core/http_post_provider_factory.h"
20 #include "sync/internal_api/public/test/fake_model_type_connector.h" 20 #include "components/sync/core/internal_components_factory.h"
21 #include "sync/internal_api/public/util/weak_handle.h" 21 #include "components/sync/core/test/fake_model_type_connector.h"
22 #include "sync/syncable/directory.h" 22 #include "components/sync/syncable/directory.h"
23 #include "sync/test/fake_sync_encryption_handler.h" 23 #include "components/sync/test/fake_sync_encryption_handler.h"
24 24
25 class GURL; 25 class GURL;
26 26
27 namespace syncer { 27 namespace syncer {
28 28
29 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types, 29 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types,
30 ModelTypeSet progress_marker_types, 30 ModelTypeSet progress_marker_types,
31 ModelTypeSet configure_fail_types) : 31 ModelTypeSet configure_fail_types)
32 initial_sync_ended_types_(initial_sync_ended_types), 32 : initial_sync_ended_types_(initial_sync_ended_types),
33 progress_marker_types_(progress_marker_types), 33 progress_marker_types_(progress_marker_types),
34 configure_fail_types_(configure_fail_types), 34 configure_fail_types_(configure_fail_types),
35 last_configure_reason_(CONFIGURE_REASON_UNKNOWN), 35 last_configure_reason_(CONFIGURE_REASON_UNKNOWN),
36 num_invalidations_received_(0) { 36 num_invalidations_received_(0) {
37 fake_encryption_handler_.reset(new FakeSyncEncryptionHandler()); 37 fake_encryption_handler_.reset(new FakeSyncEncryptionHandler());
38 } 38 }
39 39
40 FakeSyncManager::~FakeSyncManager() {} 40 FakeSyncManager::~FakeSyncManager() {}
41 41
42 ModelTypeSet FakeSyncManager::GetAndResetCleanedTypes() { 42 ModelTypeSet FakeSyncManager::GetAndResetCleanedTypes() {
43 ModelTypeSet cleaned_types = cleaned_types_; 43 ModelTypeSet cleaned_types = cleaned_types_;
44 cleaned_types_.Clear(); 44 cleaned_types_.Clear();
45 return cleaned_types; 45 return cleaned_types;
46 } 46 }
(...skipping 17 matching lines...) Expand all
64 } 64 }
65 65
66 int FakeSyncManager::GetInvalidationCount() const { 66 int FakeSyncManager::GetInvalidationCount() const {
67 return num_invalidations_received_; 67 return num_invalidations_received_;
68 } 68 }
69 69
70 void FakeSyncManager::WaitForSyncThread() { 70 void FakeSyncManager::WaitForSyncThread() {
71 // Post a task to |sync_task_runner_| and block until it runs. 71 // Post a task to |sync_task_runner_| and block until it runs.
72 base::RunLoop run_loop; 72 base::RunLoop run_loop;
73 if (!sync_task_runner_->PostTaskAndReply( 73 if (!sync_task_runner_->PostTaskAndReply(
74 FROM_HERE, 74 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure())) {
75 base::Bind(&base::DoNothing),
76 run_loop.QuitClosure())) {
77 NOTREACHED(); 75 NOTREACHED();
78 } 76 }
79 run_loop.Run(); 77 run_loop.Run();
80 } 78 }
81 79
82 void FakeSyncManager::Init(InitArgs* args) { 80 void FakeSyncManager::Init(InitArgs* args) {
83 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 81 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get();
84 PurgePartiallySyncedTypes(); 82 PurgePartiallySyncedTypes();
85 83
86 test_user_share_.SetUp(); 84 test_user_share_.SetUp();
87 UserShare* share = test_user_share_.user_share(); 85 UserShare* share = test_user_share_.user_share();
88 for (ModelTypeSet::Iterator it = initial_sync_ended_types_.First(); 86 for (ModelTypeSet::Iterator it = initial_sync_ended_types_.First(); it.Good();
89 it.Good(); it.Inc()) { 87 it.Inc()) {
90 TestUserShare::CreateRoot(it.Get(), share); 88 TestUserShare::CreateRoot(it.Get(), share);
91 } 89 }
92 90
93 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 91 FOR_EACH_OBSERVER(
94 OnInitializationComplete( 92 SyncManager::Observer, observers_,
95 WeakHandle<JsBackend>(), 93 OnInitializationComplete(WeakHandle<JsBackend>(),
96 WeakHandle<DataTypeDebugInfoListener>(), 94 WeakHandle<DataTypeDebugInfoListener>(), true,
97 true, initial_sync_ended_types_)); 95 initial_sync_ended_types_));
98 } 96 }
99 97
100 ModelTypeSet FakeSyncManager::InitialSyncEndedTypes() { 98 ModelTypeSet FakeSyncManager::InitialSyncEndedTypes() {
101 return initial_sync_ended_types_; 99 return initial_sync_ended_types_;
102 } 100 }
103 101
104 ModelTypeSet FakeSyncManager::GetTypesWithEmptyProgressMarkerToken( 102 ModelTypeSet FakeSyncManager::GetTypesWithEmptyProgressMarkerToken(
105 ModelTypeSet types) { 103 ModelTypeSet types) {
106 ModelTypeSet empty_types = types; 104 ModelTypeSet empty_types = types;
107 empty_types.RemoveAll(progress_marker_types_); 105 empty_types.RemoveAll(progress_marker_types_);
108 return empty_types; 106 return empty_types;
109 } 107 }
110 108
111 bool FakeSyncManager::PurgePartiallySyncedTypes() { 109 bool FakeSyncManager::PurgePartiallySyncedTypes() {
112 ModelTypeSet partial_types; 110 ModelTypeSet partial_types;
113 for (ModelTypeSet::Iterator i = progress_marker_types_.First(); 111 for (ModelTypeSet::Iterator i = progress_marker_types_.First(); i.Good();
114 i.Good(); i.Inc()) { 112 i.Inc()) {
115 if (!initial_sync_ended_types_.Has(i.Get())) 113 if (!initial_sync_ended_types_.Has(i.Get()))
116 partial_types.Put(i.Get()); 114 partial_types.Put(i.Get());
117 } 115 }
118 progress_marker_types_.RemoveAll(partial_types); 116 progress_marker_types_.RemoveAll(partial_types);
119 cleaned_types_.PutAll(partial_types); 117 cleaned_types_.PutAll(partial_types);
120 return true; 118 return true;
121 } 119 }
122 120
123 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { 121 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) {
124 NOTIMPLEMENTED(); 122 NOTIMPLEMENTED();
125 } 123 }
126 124
127 void FakeSyncManager::StartSyncingNormally( 125 void FakeSyncManager::StartSyncingNormally(
128 const ModelSafeRoutingInfo& routing_info, base::Time last_poll_time) { 126 const ModelSafeRoutingInfo& routing_info,
127 base::Time last_poll_time) {
129 // Do nothing. 128 // Do nothing.
130 } 129 }
131 130
132 void FakeSyncManager::ConfigureSyncer( 131 void FakeSyncManager::ConfigureSyncer(
133 ConfigureReason reason, 132 ConfigureReason reason,
134 ModelTypeSet to_download, 133 ModelTypeSet to_download,
135 ModelTypeSet to_purge, 134 ModelTypeSet to_purge,
136 ModelTypeSet to_journal, 135 ModelTypeSet to_journal,
137 ModelTypeSet to_unapply, 136 ModelTypeSet to_unapply,
138 const ModelSafeRoutingInfo& new_routing_info, 137 const ModelSafeRoutingInfo& new_routing_info,
139 const base::Closure& ready_task, 138 const base::Closure& ready_task,
140 const base::Closure& retry_task) { 139 const base::Closure& retry_task) {
141 last_configure_reason_ = reason; 140 last_configure_reason_ = reason;
142 enabled_types_ = GetRoutingInfoTypes(new_routing_info); 141 enabled_types_ = GetRoutingInfoTypes(new_routing_info);
143 ModelTypeSet success_types = to_download; 142 ModelTypeSet success_types = to_download;
144 success_types.RemoveAll(configure_fail_types_); 143 success_types.RemoveAll(configure_fail_types_);
145 144
146 DVLOG(1) << "Faking configuration. Downloading: " 145 DVLOG(1) << "Faking configuration. Downloading: "
147 << ModelTypeSetToString(success_types) << ". Cleaning: " 146 << ModelTypeSetToString(success_types)
148 << ModelTypeSetToString(to_purge); 147 << ". Cleaning: " << ModelTypeSetToString(to_purge);
149 148
150 // Update our fake directory by clearing and fake-downloading as necessary. 149 // Update our fake directory by clearing and fake-downloading as necessary.
151 UserShare* share = GetUserShare(); 150 UserShare* share = GetUserShare();
152 share->directory->PurgeEntriesWithTypeIn(to_purge, 151 share->directory->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply);
153 to_journal,
154 to_unapply);
155 for (ModelTypeSet::Iterator it = success_types.First(); it.Good(); it.Inc()) { 152 for (ModelTypeSet::Iterator it = success_types.First(); it.Good(); it.Inc()) {
156 // We must be careful to not create the same root node twice. 153 // We must be careful to not create the same root node twice.
157 if (!initial_sync_ended_types_.Has(it.Get())) { 154 if (!initial_sync_ended_types_.Has(it.Get())) {
158 TestUserShare::CreateRoot(it.Get(), share); 155 TestUserShare::CreateRoot(it.Get(), share);
159 } 156 }
160 } 157 }
161 158
162 // Simulate cleaning up disabled types. 159 // Simulate cleaning up disabled types.
163 // TODO(sync): consider only cleaning those types that were recently disabled, 160 // TODO(sync): consider only cleaning those types that were recently disabled,
164 // if this isn't the first cleanup, which more accurately reflects the 161 // if this isn't the first cleanup, which more accurately reflects the
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 263 }
267 264
268 void FakeSyncManager::ClearServerData(const ClearServerDataCallback& callback) { 265 void FakeSyncManager::ClearServerData(const ClearServerDataCallback& callback) {
269 callback.Run(); 266 callback.Run();
270 } 267 }
271 268
272 void FakeSyncManager::OnCookieJarChanged(bool account_mismatch, 269 void FakeSyncManager::OnCookieJarChanged(bool account_mismatch,
273 bool empty_jar) {} 270 bool empty_jar) {}
274 271
275 } // namespace syncer 272 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698