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

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

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

Powered by Google App Engine
This is Rietveld 408576698