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

Side by Side Diff: components/sync/driver/glue/sync_backend_host_core.cc

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 years, 2 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 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 "components/sync/driver/glue/sync_backend_host_core.h" 5 #include "components/sync/driver/glue/sync_backend_host_core.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 namespace { 47 namespace {
48 48
49 void BindFetcherToDataTracker(net::URLFetcher* fetcher) { 49 void BindFetcherToDataTracker(net::URLFetcher* fetcher) {
50 data_use_measurement::DataUseUserData::AttachToFetcher( 50 data_use_measurement::DataUseUserData::AttachToFetcher(
51 fetcher, data_use_measurement::DataUseUserData::SYNC); 51 fetcher, data_use_measurement::DataUseUserData::SYNC);
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 namespace syncer { 56 namespace browser_sync {
57 57
58 DoInitializeOptions::DoInitializeOptions( 58 DoInitializeOptions::DoInitializeOptions(
59 base::MessageLoop* sync_loop, 59 base::MessageLoop* sync_loop,
60 SyncBackendRegistrar* registrar, 60 SyncBackendRegistrar* registrar,
61 const std::vector<scoped_refptr<ModelSafeWorker>>& workers, 61 const std::vector<scoped_refptr<syncer::ModelSafeWorker>>& workers,
62 const scoped_refptr<ExtensionsActivity>& extensions_activity, 62 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity,
63 const WeakHandle<JsEventHandler>& event_handler, 63 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
64 const GURL& service_url, 64 const GURL& service_url,
65 const std::string& sync_user_agent, 65 const std::string& sync_user_agent,
66 std::unique_ptr<HttpPostProviderFactory> http_bridge_factory, 66 std::unique_ptr<syncer::HttpPostProviderFactory> http_bridge_factory,
67 const SyncCredentials& credentials, 67 const syncer::SyncCredentials& credentials,
68 const std::string& invalidator_client_id, 68 const std::string& invalidator_client_id,
69 std::unique_ptr<SyncManagerFactory> sync_manager_factory, 69 std::unique_ptr<syncer::SyncManagerFactory> sync_manager_factory,
70 bool delete_sync_data_folder, 70 bool delete_sync_data_folder,
71 const std::string& restored_key_for_bootstrapping, 71 const std::string& restored_key_for_bootstrapping,
72 const std::string& restored_keystore_key_for_bootstrapping, 72 const std::string& restored_keystore_key_for_bootstrapping,
73 std::unique_ptr<InternalComponentsFactory> internal_components_factory, 73 std::unique_ptr<syncer::InternalComponentsFactory>
74 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, 74 internal_components_factory,
75 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>&
76 unrecoverable_error_handler,
75 const base::Closure& report_unrecoverable_error_function, 77 const base::Closure& report_unrecoverable_error_function,
76 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state, 78 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>
77 const std::map<ModelType, int64_t>& invalidation_versions) 79 saved_nigori_state,
80 const std::map<syncer::ModelType, int64_t>& invalidation_versions)
78 : sync_loop(sync_loop), 81 : sync_loop(sync_loop),
79 registrar(registrar), 82 registrar(registrar),
80 workers(workers), 83 workers(workers),
81 extensions_activity(extensions_activity), 84 extensions_activity(extensions_activity),
82 event_handler(event_handler), 85 event_handler(event_handler),
83 service_url(service_url), 86 service_url(service_url),
84 sync_user_agent(sync_user_agent), 87 sync_user_agent(sync_user_agent),
85 http_bridge_factory(std::move(http_bridge_factory)), 88 http_bridge_factory(std::move(http_bridge_factory)),
86 credentials(credentials), 89 credentials(credentials),
87 invalidator_client_id(invalidator_client_id), 90 invalidator_client_id(invalidator_client_id),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 forward_type_info_(false), 123 forward_type_info_(false),
121 weak_ptr_factory_(this) { 124 weak_ptr_factory_(this) {
122 DCHECK(backend.get()); 125 DCHECK(backend.get());
123 } 126 }
124 127
125 SyncBackendHostCore::~SyncBackendHostCore() { 128 SyncBackendHostCore::~SyncBackendHostCore() {
126 DCHECK(!sync_manager_.get()); 129 DCHECK(!sync_manager_.get());
127 } 130 }
128 131
129 void SyncBackendHostCore::OnSyncCycleCompleted( 132 void SyncBackendHostCore::OnSyncCycleCompleted(
130 const SyncCycleSnapshot& snapshot) { 133 const syncer::SyncCycleSnapshot& snapshot) {
131 if (!sync_loop_) 134 if (!sync_loop_)
132 return; 135 return;
133 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 136 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
134 137
135 host_.Call(FROM_HERE, 138 host_.Call(FROM_HERE,
136 &SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop, 139 &SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop,
137 snapshot); 140 snapshot);
138 } 141 }
139 142
140 void SyncBackendHostCore::DoRefreshTypes(ModelTypeSet types) { 143 void SyncBackendHostCore::DoRefreshTypes(syncer::ModelTypeSet types) {
141 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 144 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
142 sync_manager_->RefreshTypes(types); 145 sync_manager_->RefreshTypes(types);
143 } 146 }
144 147
145 void SyncBackendHostCore::OnInitializationComplete( 148 void SyncBackendHostCore::OnInitializationComplete(
146 const WeakHandle<JsBackend>& js_backend, 149 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
147 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, 150 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
151 debug_info_listener,
148 bool success, 152 bool success,
149 const ModelTypeSet restored_types) { 153 const syncer::ModelTypeSet restored_types) {
150 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 154 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
151 155
152 if (!success) { 156 if (!success) {
153 DoDestroySyncManager(STOP_SYNC); 157 DoDestroySyncManager(syncer::STOP_SYNC);
154 host_.Call(FROM_HERE, 158 host_.Call(FROM_HERE,
155 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); 159 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop);
156 return; 160 return;
157 } 161 }
158 162
159 // Register for encryption related changes now. We have to do this before 163 // Register for encryption related changes now. We have to do this before
160 // the initializing downloading control types or initializing the encryption 164 // the initializing downloading control types or initializing the encryption
161 // handler in order to receive notifications triggered during encryption 165 // handler in order to receive notifications triggered during encryption
162 // startup. 166 // startup.
163 sync_manager_->GetEncryptionHandler()->AddObserver(this); 167 sync_manager_->GetEncryptionHandler()->AddObserver(this);
(...skipping 10 matching lines...) Expand all
174 debug_info_listener_ = debug_info_listener; 178 debug_info_listener_ = debug_info_listener;
175 179
176 // Before proceeding any further, we need to download the control types and 180 // Before proceeding any further, we need to download the control types and
177 // purge any partial data (ie. data downloaded for a type that was on its way 181 // purge any partial data (ie. data downloaded for a type that was on its way
178 // to being initially synced, but didn't quite make it.). The following 182 // to being initially synced, but didn't quite make it.). The following
179 // configure cycle will take care of this. It depends on the registrar state 183 // configure cycle will take care of this. It depends on the registrar state
180 // which we initialize below to ensure that we don't perform any downloads if 184 // which we initialize below to ensure that we don't perform any downloads if
181 // all control types have already completed their initial sync. 185 // all control types have already completed their initial sync.
182 registrar_->SetInitialTypes(restored_types); 186 registrar_->SetInitialTypes(restored_types);
183 187
184 ConfigureReason reason = restored_types.Empty() 188 syncer::ConfigureReason reason =
185 ? CONFIGURE_REASON_NEW_CLIENT 189 restored_types.Empty() ? syncer::CONFIGURE_REASON_NEW_CLIENT
186 : CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; 190 : syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE;
187 191
188 ModelTypeSet new_control_types = 192 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes(
189 registrar_->ConfigureDataTypes(ControlTypes(), ModelTypeSet()); 193 syncer::ControlTypes(), syncer::ModelTypeSet());
190 ModelSafeRoutingInfo routing_info; 194 syncer::ModelSafeRoutingInfo routing_info;
191 registrar_->GetModelSafeRoutingInfo(&routing_info); 195 registrar_->GetModelSafeRoutingInfo(&routing_info);
192 SDVLOG(1) << "Control Types " << ModelTypeSetToString(new_control_types) 196 SDVLOG(1) << "Control Types "
197 << syncer::ModelTypeSetToString(new_control_types)
193 << " added; calling ConfigureSyncer"; 198 << " added; calling ConfigureSyncer";
194 199
195 ModelTypeSet types_to_purge = 200 syncer::ModelTypeSet types_to_purge = syncer::Difference(
196 Difference(ModelTypeSet::All(), GetRoutingInfoTypes(routing_info)); 201 syncer::ModelTypeSet::All(), GetRoutingInfoTypes(routing_info));
197 202
198 sync_manager_->ConfigureSyncer( 203 sync_manager_->ConfigureSyncer(
199 reason, new_control_types, types_to_purge, ModelTypeSet(), ModelTypeSet(), 204 reason, new_control_types, types_to_purge, syncer::ModelTypeSet(),
200 routing_info, 205 syncer::ModelTypeSet(), routing_info,
201 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, 206 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes,
202 weak_ptr_factory_.GetWeakPtr()), 207 weak_ptr_factory_.GetWeakPtr()),
203 base::Closure()); 208 base::Closure());
204 } 209 }
205 210
206 void SyncBackendHostCore::OnConnectionStatusChange(ConnectionStatus status) { 211 void SyncBackendHostCore::OnConnectionStatusChange(
212 syncer::ConnectionStatus status) {
207 if (!sync_loop_) 213 if (!sync_loop_)
208 return; 214 return;
209 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 215 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
210 host_.Call(FROM_HERE, 216 host_.Call(FROM_HERE,
211 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, 217 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop,
212 status); 218 status);
213 } 219 }
214 220
215 void SyncBackendHostCore::OnPassphraseRequired( 221 void SyncBackendHostCore::OnPassphraseRequired(
216 PassphraseRequiredReason reason, 222 syncer::PassphraseRequiredReason reason,
217 const sync_pb::EncryptedData& pending_keys) { 223 const sync_pb::EncryptedData& pending_keys) {
218 if (!sync_loop_) 224 if (!sync_loop_)
219 return; 225 return;
220 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 226 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
221 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseRequired, reason, 227 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseRequired, reason,
222 pending_keys); 228 pending_keys);
223 } 229 }
224 230
225 void SyncBackendHostCore::OnPassphraseAccepted() { 231 void SyncBackendHostCore::OnPassphraseAccepted() {
226 if (!sync_loop_) 232 if (!sync_loop_)
227 return; 233 return;
228 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 234 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
229 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseAccepted); 235 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyPassphraseAccepted);
230 } 236 }
231 237
232 void SyncBackendHostCore::OnBootstrapTokenUpdated( 238 void SyncBackendHostCore::OnBootstrapTokenUpdated(
233 const std::string& bootstrap_token, 239 const std::string& bootstrap_token,
234 BootstrapTokenType type) { 240 syncer::BootstrapTokenType type) {
235 if (!sync_loop_) 241 if (!sync_loop_)
236 return; 242 return;
237 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 243 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
238 host_.Call(FROM_HERE, &SyncBackendHostImpl::PersistEncryptionBootstrapToken, 244 host_.Call(FROM_HERE, &SyncBackendHostImpl::PersistEncryptionBootstrapToken,
239 bootstrap_token, type); 245 bootstrap_token, type);
240 } 246 }
241 247
242 void SyncBackendHostCore::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, 248 void SyncBackendHostCore::OnEncryptedTypesChanged(
243 bool encrypt_everything) { 249 syncer::ModelTypeSet encrypted_types,
250 bool encrypt_everything) {
244 if (!sync_loop_) 251 if (!sync_loop_)
245 return; 252 return;
246 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 253 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
247 // NOTE: We're in a transaction. 254 // NOTE: We're in a transaction.
248 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptedTypesChanged, 255 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptedTypesChanged,
249 encrypted_types, encrypt_everything); 256 encrypted_types, encrypt_everything);
250 } 257 }
251 258
252 void SyncBackendHostCore::OnEncryptionComplete() { 259 void SyncBackendHostCore::OnEncryptionComplete() {
253 if (!sync_loop_) 260 if (!sync_loop_)
254 return; 261 return;
255 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 262 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
256 // NOTE: We're in a transaction. 263 // NOTE: We're in a transaction.
257 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptionComplete); 264 host_.Call(FROM_HERE, &SyncBackendHostImpl::NotifyEncryptionComplete);
258 } 265 }
259 266
260 void SyncBackendHostCore::OnCryptographerStateChanged( 267 void SyncBackendHostCore::OnCryptographerStateChanged(
261 Cryptographer* cryptographer) { 268 syncer::Cryptographer* cryptographer) {
262 // Do nothing. 269 // Do nothing.
263 } 270 }
264 271
265 void SyncBackendHostCore::OnPassphraseTypeChanged(PassphraseType type, 272 void SyncBackendHostCore::OnPassphraseTypeChanged(syncer::PassphraseType type,
266 base::Time passphrase_time) { 273 base::Time passphrase_time) {
267 host_.Call(FROM_HERE, 274 host_.Call(FROM_HERE,
268 &SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop, 275 &SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop,
269 type, passphrase_time); 276 type, passphrase_time);
270 } 277 }
271 278
272 void SyncBackendHostCore::OnLocalSetPassphraseEncryption( 279 void SyncBackendHostCore::OnLocalSetPassphraseEncryption(
273 const SyncEncryptionHandler::NigoriState& nigori_state) { 280 const syncer::SyncEncryptionHandler::NigoriState& nigori_state) {
274 host_.Call( 281 host_.Call(
275 FROM_HERE, 282 FROM_HERE,
276 &SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop, 283 &SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop,
277 nigori_state); 284 nigori_state);
278 } 285 }
279 286
280 void SyncBackendHostCore::OnCommitCountersUpdated( 287 void SyncBackendHostCore::OnCommitCountersUpdated(
281 ModelType type, 288 syncer::ModelType type,
282 const CommitCounters& counters) { 289 const syncer::CommitCounters& counters) {
283 host_.Call( 290 host_.Call(
284 FROM_HERE, 291 FROM_HERE,
285 &SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop, 292 &SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop,
286 type, counters); 293 type, counters);
287 } 294 }
288 295
289 void SyncBackendHostCore::OnUpdateCountersUpdated( 296 void SyncBackendHostCore::OnUpdateCountersUpdated(
290 ModelType type, 297 syncer::ModelType type,
291 const UpdateCounters& counters) { 298 const syncer::UpdateCounters& counters) {
292 host_.Call( 299 host_.Call(
293 FROM_HERE, 300 FROM_HERE,
294 &SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop, 301 &SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop,
295 type, counters); 302 type, counters);
296 } 303 }
297 304
298 void SyncBackendHostCore::OnStatusCountersUpdated( 305 void SyncBackendHostCore::OnStatusCountersUpdated(
299 ModelType type, 306 syncer::ModelType type,
300 const StatusCounters& counters) { 307 const syncer::StatusCounters& counters) {
301 host_.Call( 308 host_.Call(
302 FROM_HERE, 309 FROM_HERE,
303 &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop, 310 &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop,
304 type, counters); 311 type, counters);
305 } 312 }
306 313
307 void SyncBackendHostCore::OnActionableError( 314 void SyncBackendHostCore::OnActionableError(
308 const SyncProtocolError& sync_error) { 315 const syncer::SyncProtocolError& sync_error) {
309 if (!sync_loop_) 316 if (!sync_loop_)
310 return; 317 return;
311 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 318 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
312 host_.Call(FROM_HERE, 319 host_.Call(FROM_HERE,
313 &SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop, 320 &SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop,
314 sync_error); 321 sync_error);
315 } 322 }
316 323
317 void SyncBackendHostCore::OnMigrationRequested(ModelTypeSet types) { 324 void SyncBackendHostCore::OnMigrationRequested(syncer::ModelTypeSet types) {
318 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 325 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
319 host_.Call(FROM_HERE, 326 host_.Call(FROM_HERE,
320 &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop, 327 &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop,
321 types); 328 types);
322 } 329 }
323 330
324 void SyncBackendHostCore::OnProtocolEvent(const ProtocolEvent& event) { 331 void SyncBackendHostCore::OnProtocolEvent(const syncer::ProtocolEvent& event) {
325 if (forward_protocol_events_) { 332 if (forward_protocol_events_) {
326 std::unique_ptr<ProtocolEvent> event_clone(event.Clone()); 333 std::unique_ptr<syncer::ProtocolEvent> event_clone(event.Clone());
327 host_.Call(FROM_HERE, 334 host_.Call(FROM_HERE,
328 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, 335 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop,
329 base::Passed(std::move(event_clone))); 336 base::Passed(std::move(event_clone)));
330 } 337 }
331 } 338 }
332 339
333 void SyncBackendHostCore::DoOnInvalidatorStateChange(InvalidatorState state) { 340 void SyncBackendHostCore::DoOnInvalidatorStateChange(
341 syncer::InvalidatorState state) {
334 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 342 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
335 sync_manager_->SetInvalidatorEnabled(state == INVALIDATIONS_ENABLED); 343 sync_manager_->SetInvalidatorEnabled(state == syncer::INVALIDATIONS_ENABLED);
336 } 344 }
337 345
338 void SyncBackendHostCore::DoOnIncomingInvalidation( 346 void SyncBackendHostCore::DoOnIncomingInvalidation(
339 const ObjectIdInvalidationMap& invalidation_map) { 347 const syncer::ObjectIdInvalidationMap& invalidation_map) {
340 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 348 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
341 349
342 ObjectIdSet ids = invalidation_map.GetObjectIds(); 350 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds();
343 for (const invalidation::ObjectId& object_id : ids) { 351 for (const invalidation::ObjectId& object_id : ids) {
344 ModelType type; 352 syncer::ModelType type;
345 if (!NotificationTypeToRealModelType(object_id.name(), &type)) { 353 if (!NotificationTypeToRealModelType(object_id.name(), &type)) {
346 DLOG(WARNING) << "Notification has invalid id: " 354 DLOG(WARNING) << "Notification has invalid id: "
347 << ObjectIdToString(object_id); 355 << syncer::ObjectIdToString(object_id);
348 } else { 356 } else {
349 SingleObjectInvalidationSet invalidation_set = 357 syncer::SingleObjectInvalidationSet invalidation_set =
350 invalidation_map.ForObject(object_id); 358 invalidation_map.ForObject(object_id);
351 for (Invalidation invalidation : invalidation_set) { 359 for (syncer::Invalidation invalidation : invalidation_set) {
352 auto last_invalidation = last_invalidation_versions_.find(type); 360 auto last_invalidation = last_invalidation_versions_.find(type);
353 if (!invalidation.is_unknown_version() && 361 if (!invalidation.is_unknown_version() &&
354 last_invalidation != last_invalidation_versions_.end() && 362 last_invalidation != last_invalidation_versions_.end() &&
355 invalidation.version() <= last_invalidation->second) { 363 invalidation.version() <= last_invalidation->second) {
356 DVLOG(1) << "Ignoring redundant invalidation for " 364 DVLOG(1) << "Ignoring redundant invalidation for "
357 << ModelTypeToString(type) << " with version " 365 << syncer::ModelTypeToString(type) << " with version "
358 << invalidation.version() << ", last seen version was " 366 << invalidation.version() << ", last seen version was "
359 << last_invalidation->second; 367 << last_invalidation->second;
360 continue; 368 continue;
361 } 369 }
362 std::unique_ptr<InvalidationInterface> inv_adapter( 370 std::unique_ptr<syncer::InvalidationInterface> inv_adapter(
363 new InvalidationAdapter(invalidation)); 371 new InvalidationAdapter(invalidation));
364 sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter)); 372 sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter));
365 if (!invalidation.is_unknown_version()) 373 if (!invalidation.is_unknown_version())
366 last_invalidation_versions_[type] = invalidation.version(); 374 last_invalidation_versions_[type] = invalidation.version();
367 } 375 }
368 } 376 }
369 } 377 }
370 378
371 host_.Call(FROM_HERE, &SyncBackendHostImpl::UpdateInvalidationVersions, 379 host_.Call(FROM_HERE, &SyncBackendHostImpl::UpdateInvalidationVersions,
372 last_invalidation_versions_); 380 last_invalidation_versions_);
(...skipping 25 matching lines...) Expand all
398 // Load the previously persisted set of invalidation versions into memory. 406 // Load the previously persisted set of invalidation versions into memory.
399 last_invalidation_versions_ = options->invalidation_versions; 407 last_invalidation_versions_ = options->invalidation_versions;
400 408
401 DCHECK(!registrar_); 409 DCHECK(!registrar_);
402 registrar_ = options->registrar; 410 registrar_ = options->registrar;
403 DCHECK(registrar_); 411 DCHECK(registrar_);
404 412
405 sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_); 413 sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_);
406 sync_manager_->AddObserver(this); 414 sync_manager_->AddObserver(this);
407 415
408 SyncManager::InitArgs args; 416 syncer::SyncManager::InitArgs args;
409 args.database_location = sync_data_folder_path_; 417 args.database_location = sync_data_folder_path_;
410 args.event_handler = options->event_handler; 418 args.event_handler = options->event_handler;
411 args.service_url = options->service_url; 419 args.service_url = options->service_url;
412 args.post_factory = std::move(options->http_bridge_factory); 420 args.post_factory = std::move(options->http_bridge_factory);
413 args.workers = options->workers; 421 args.workers = options->workers;
414 args.extensions_activity = options->extensions_activity.get(); 422 args.extensions_activity = options->extensions_activity.get();
415 args.change_delegate = options->registrar; // as SyncManager::ChangeDelegate 423 args.change_delegate = options->registrar; // as SyncManager::ChangeDelegate
416 args.credentials = options->credentials; 424 args.credentials = options->credentials;
417 args.invalidator_client_id = options->invalidator_client_id; 425 args.invalidator_client_id = options->invalidator_client_id;
418 args.restored_key_for_bootstrapping = options->restored_key_for_bootstrapping; 426 args.restored_key_for_bootstrapping = options->restored_key_for_bootstrapping;
419 args.restored_keystore_key_for_bootstrapping = 427 args.restored_keystore_key_for_bootstrapping =
420 options->restored_keystore_key_for_bootstrapping; 428 options->restored_keystore_key_for_bootstrapping;
421 args.internal_components_factory = 429 args.internal_components_factory =
422 std::move(options->internal_components_factory); 430 std::move(options->internal_components_factory);
423 args.encryptor = &encryptor_; 431 args.encryptor = &encryptor_;
424 args.unrecoverable_error_handler = options->unrecoverable_error_handler; 432 args.unrecoverable_error_handler = options->unrecoverable_error_handler;
425 args.report_unrecoverable_error_function = 433 args.report_unrecoverable_error_function =
426 options->report_unrecoverable_error_function; 434 options->report_unrecoverable_error_function;
427 args.cancelation_signal = &stop_syncing_signal_; 435 args.cancelation_signal = &stop_syncing_signal_;
428 args.saved_nigori_state = std::move(options->saved_nigori_state); 436 args.saved_nigori_state = std::move(options->saved_nigori_state);
429 sync_manager_->Init(&args); 437 sync_manager_->Init(&args);
430 } 438 }
431 439
432 void SyncBackendHostCore::DoUpdateCredentials( 440 void SyncBackendHostCore::DoUpdateCredentials(
433 const SyncCredentials& credentials) { 441 const syncer::SyncCredentials& credentials) {
434 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 442 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
435 // UpdateCredentials can be called during backend initialization, possibly 443 // UpdateCredentials can be called during backend initialization, possibly
436 // when backend initialization has failed but hasn't notified the UI thread 444 // when backend initialization has failed but hasn't notified the UI thread
437 // yet. In that case, the sync manager may have been destroyed on the sync 445 // yet. In that case, the sync manager may have been destroyed on the sync
438 // thread before this task was executed, so we do nothing. 446 // thread before this task was executed, so we do nothing.
439 if (sync_manager_) { 447 if (sync_manager_) {
440 sync_manager_->UpdateCredentials(credentials); 448 sync_manager_->UpdateCredentials(credentials);
441 } 449 }
442 } 450 }
443 451
444 void SyncBackendHostCore::DoStartSyncing( 452 void SyncBackendHostCore::DoStartSyncing(
445 const ModelSafeRoutingInfo& routing_info, 453 const syncer::ModelSafeRoutingInfo& routing_info,
446 base::Time last_poll_time) { 454 base::Time last_poll_time) {
447 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 455 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
448 sync_manager_->StartSyncingNormally(routing_info, last_poll_time); 456 sync_manager_->StartSyncingNormally(routing_info, last_poll_time);
449 } 457 }
450 458
451 void SyncBackendHostCore::DoSetEncryptionPassphrase( 459 void SyncBackendHostCore::DoSetEncryptionPassphrase(
452 const std::string& passphrase, 460 const std::string& passphrase,
453 bool is_explicit) { 461 bool is_explicit) {
454 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 462 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
455 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, 463 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(passphrase,
(...skipping 12 matching lines...) Expand all
468 // which is called at the end of every sync cycle. 476 // which is called at the end of every sync cycle.
469 // TODO(zea): eventually add an experiment handler and initialize it here. 477 // TODO(zea): eventually add an experiment handler and initialize it here.
470 478
471 if (!sync_manager_->GetUserShare()) { // NULL in some tests. 479 if (!sync_manager_->GetUserShare()) { // NULL in some tests.
472 DVLOG(1) << "Skipping initialization of DeviceInfo"; 480 DVLOG(1) << "Skipping initialization of DeviceInfo";
473 host_.Call(FROM_HERE, 481 host_.Call(FROM_HERE,
474 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); 482 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop);
475 return; 483 return;
476 } 484 }
477 485
478 if (!sync_manager_->InitialSyncEndedTypes().HasAll(ControlTypes())) { 486 if (!sync_manager_->InitialSyncEndedTypes().HasAll(syncer::ControlTypes())) {
479 LOG(ERROR) << "Failed to download control types"; 487 LOG(ERROR) << "Failed to download control types";
480 host_.Call(FROM_HERE, 488 host_.Call(FROM_HERE,
481 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); 489 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop);
482 return; 490 return;
483 } 491 }
484 492
485 host_.Call(FROM_HERE, 493 host_.Call(FROM_HERE,
486 &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop, 494 &SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop,
487 js_backend_, debug_info_listener_, 495 js_backend_, debug_info_listener_,
488 base::Passed(sync_manager_->GetModelTypeConnectorProxy()), 496 base::Passed(sync_manager_->GetModelTypeConnectorProxy()),
(...skipping 28 matching lines...) Expand all
517 525
518 // This will drop the HttpBridgeFactory's reference to the 526 // This will drop the HttpBridgeFactory's reference to the
519 // RequestContextGetter. Once this has been called, the HttpBridgeFactory can 527 // RequestContextGetter. Once this has been called, the HttpBridgeFactory can
520 // no longer be used to create new HttpBridge instances. We can get away with 528 // no longer be used to create new HttpBridge instances. We can get away with
521 // this because the stop_syncing_signal_ has already been signalled, which 529 // this because the stop_syncing_signal_ has already been signalled, which
522 // guarantees that the ServerConnectionManager will no longer attempt to 530 // guarantees that the ServerConnectionManager will no longer attempt to
523 // create new connections. 531 // create new connections.
524 release_request_context_signal_.Signal(); 532 release_request_context_signal_.Signal();
525 } 533 }
526 534
527 void SyncBackendHostCore::DoShutdown(ShutdownReason reason) { 535 void SyncBackendHostCore::DoShutdown(syncer::ShutdownReason reason) {
528 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 536 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
529 537
530 DoDestroySyncManager(reason); 538 DoDestroySyncManager(reason);
531 539
532 registrar_ = NULL; 540 registrar_ = NULL;
533 541
534 if (reason == DISABLE_SYNC) 542 if (reason == syncer::DISABLE_SYNC)
535 DeleteSyncDataFolder(); 543 DeleteSyncDataFolder();
536 544
537 host_.Reset(); 545 host_.Reset();
538 weak_ptr_factory_.InvalidateWeakPtrs(); 546 weak_ptr_factory_.InvalidateWeakPtrs();
539 } 547 }
540 548
541 void SyncBackendHostCore::DoDestroySyncManager(ShutdownReason reason) { 549 void SyncBackendHostCore::DoDestroySyncManager(syncer::ShutdownReason reason) {
542 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 550 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
543 if (sync_manager_) { 551 if (sync_manager_) {
544 DisableDirectoryTypeDebugInfoForwarding(); 552 DisableDirectoryTypeDebugInfoForwarding();
545 save_changes_timer_.reset(); 553 save_changes_timer_.reset();
546 sync_manager_->RemoveObserver(this); 554 sync_manager_->RemoveObserver(this);
547 sync_manager_->ShutdownOnSyncThread(reason); 555 sync_manager_->ShutdownOnSyncThread(reason);
548 sync_manager_.reset(); 556 sync_manager_.reset();
549 } 557 }
550 } 558 }
551 559
552 void SyncBackendHostCore::DoConfigureSyncer( 560 void SyncBackendHostCore::DoConfigureSyncer(
553 ConfigureReason reason, 561 syncer::ConfigureReason reason,
554 const DoConfigureSyncerTypes& config_types, 562 const DoConfigureSyncerTypes& config_types,
555 const ModelSafeRoutingInfo routing_info, 563 const syncer::ModelSafeRoutingInfo routing_info,
556 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task, 564 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
565 ready_task,
557 const base::Closure& retry_callback) { 566 const base::Closure& retry_callback) {
558 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 567 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
559 DCHECK(!ready_task.is_null()); 568 DCHECK(!ready_task.is_null());
560 DCHECK(!retry_callback.is_null()); 569 DCHECK(!retry_callback.is_null());
561 base::Closure chained_ready_task(base::Bind( 570 base::Closure chained_ready_task(base::Bind(
562 &SyncBackendHostCore::DoFinishConfigureDataTypes, 571 &SyncBackendHostCore::DoFinishConfigureDataTypes,
563 weak_ptr_factory_.GetWeakPtr(), config_types.to_download, ready_task)); 572 weak_ptr_factory_.GetWeakPtr(), config_types.to_download, ready_task));
564 base::Closure chained_retry_task( 573 base::Closure chained_retry_task(
565 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, 574 base::Bind(&SyncBackendHostCore::DoRetryConfiguration,
566 weak_ptr_factory_.GetWeakPtr(), retry_callback)); 575 weak_ptr_factory_.GetWeakPtr(), retry_callback));
567 sync_manager_->ConfigureSyncer(reason, config_types.to_download, 576 sync_manager_->ConfigureSyncer(reason, config_types.to_download,
568 config_types.to_purge, config_types.to_journal, 577 config_types.to_purge, config_types.to_journal,
569 config_types.to_unapply, routing_info, 578 config_types.to_unapply, routing_info,
570 chained_ready_task, chained_retry_task); 579 chained_ready_task, chained_retry_task);
571 } 580 }
572 581
573 void SyncBackendHostCore::DoFinishConfigureDataTypes( 582 void SyncBackendHostCore::DoFinishConfigureDataTypes(
574 ModelTypeSet types_to_config, 583 syncer::ModelTypeSet types_to_config,
575 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) { 584 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>&
585 ready_task) {
576 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 586 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
577 587
578 // Update the enabled types for the bridge and sync manager. 588 // Update the enabled types for the bridge and sync manager.
579 ModelSafeRoutingInfo routing_info; 589 syncer::ModelSafeRoutingInfo routing_info;
580 registrar_->GetModelSafeRoutingInfo(&routing_info); 590 registrar_->GetModelSafeRoutingInfo(&routing_info);
581 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); 591 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
582 enabled_types.RemoveAll(ProxyTypes()); 592 enabled_types.RemoveAll(syncer::ProxyTypes());
583 593
584 const ModelTypeSet failed_configuration_types = 594 const syncer::ModelTypeSet failed_configuration_types =
585 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); 595 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes());
586 const ModelTypeSet succeeded_configuration_types = 596 const syncer::ModelTypeSet succeeded_configuration_types =
587 Difference(types_to_config, failed_configuration_types); 597 Difference(types_to_config, failed_configuration_types);
588 host_.Call(FROM_HERE, 598 host_.Call(FROM_HERE,
589 &SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop, 599 &SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop,
590 enabled_types, succeeded_configuration_types, 600 enabled_types, succeeded_configuration_types,
591 failed_configuration_types, ready_task); 601 failed_configuration_types, ready_task);
592 } 602 }
593 603
594 void SyncBackendHostCore::DoRetryConfiguration( 604 void SyncBackendHostCore::DoRetryConfiguration(
595 const base::Closure& retry_callback) { 605 const base::Closure& retry_callback) {
596 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 606 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
597 host_.Call(FROM_HERE, &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, 607 host_.Call(FROM_HERE, &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop,
598 retry_callback); 608 retry_callback);
599 } 609 }
600 610
601 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { 611 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() {
602 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 612 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
603 forward_protocol_events_ = true; 613 forward_protocol_events_ = true;
604 614
605 if (sync_manager_) { 615 if (sync_manager_) {
606 // Grab our own copy of the buffered events. 616 // Grab our own copy of the buffered events.
607 // The buffer is not modified by this operation. 617 // The buffer is not modified by this operation.
608 std::vector<std::unique_ptr<ProtocolEvent>> buffered_events = 618 std::vector<std::unique_ptr<syncer::ProtocolEvent>> buffered_events =
609 sync_manager_->GetBufferedProtocolEvents(); 619 sync_manager_->GetBufferedProtocolEvents();
610 620
611 // Send them all over the fence to the host. 621 // Send them all over the fence to the host.
612 for (auto& event : buffered_events) { 622 for (auto& event : buffered_events) {
613 host_.Call(FROM_HERE, 623 host_.Call(FROM_HERE,
614 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, 624 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop,
615 base::Passed(std::move(event))); 625 base::Passed(std::move(event)));
616 } 626 }
617 } 627 }
618 } 628 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 FROM_HERE, base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 672 FROM_HERE, base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
663 this, &SyncBackendHostCore::SaveChanges); 673 this, &SyncBackendHostCore::SaveChanges);
664 } 674 }
665 675
666 void SyncBackendHostCore::SaveChanges() { 676 void SyncBackendHostCore::SaveChanges() {
667 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 677 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
668 sync_manager_->SaveChanges(); 678 sync_manager_->SaveChanges();
669 } 679 }
670 680
671 void SyncBackendHostCore::DoClearServerData( 681 void SyncBackendHostCore::DoClearServerData(
672 const SyncManager::ClearServerDataCallback& frontend_callback) { 682 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) {
673 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 683 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
674 const SyncManager::ClearServerDataCallback callback = 684 const syncer::SyncManager::ClearServerDataCallback callback =
675 base::Bind(&SyncBackendHostCore::ClearServerDataDone, 685 base::Bind(&SyncBackendHostCore::ClearServerDataDone,
676 weak_ptr_factory_.GetWeakPtr(), frontend_callback); 686 weak_ptr_factory_.GetWeakPtr(), frontend_callback);
677 sync_manager_->ClearServerData(callback); 687 sync_manager_->ClearServerData(callback);
678 } 688 }
679 689
680 void SyncBackendHostCore::DoOnCookieJarChanged(bool account_mismatch, 690 void SyncBackendHostCore::DoOnCookieJarChanged(bool account_mismatch,
681 bool empty_jar) { 691 bool empty_jar) {
682 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 692 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
683 sync_manager_->OnCookieJarChanged(account_mismatch, empty_jar); 693 sync_manager_->OnCookieJarChanged(account_mismatch, empty_jar);
684 } 694 }
685 695
686 void SyncBackendHostCore::ClearServerDataDone( 696 void SyncBackendHostCore::ClearServerDataDone(
687 const base::Closure& frontend_callback) { 697 const base::Closure& frontend_callback) {
688 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); 698 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread());
689 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, 699 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop,
690 frontend_callback); 700 frontend_callback);
691 } 701 }
692 702
693 } // namespace syncer 703 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync/driver/glue/sync_backend_host_core.h ('k') | components/sync/driver/glue/sync_backend_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698