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

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