| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/engine/model_type_sync_worker_impl.h" | 5 #include "sync/engine/commit_queue_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "sync/engine/commit_contribution.h" | 12 #include "sync/engine/commit_contribution.h" |
| 13 #include "sync/engine/entity_tracker.h" | 13 #include "sync/engine/entity_tracker.h" |
| 14 #include "sync/engine/model_type_sync_proxy.h" | 14 #include "sync/engine/model_type_processor.h" |
| 15 #include "sync/engine/non_blocking_type_commit_contribution.h" | 15 #include "sync/engine/non_blocking_type_commit_contribution.h" |
| 16 #include "sync/syncable/syncable_util.h" | 16 #include "sync/syncable/syncable_util.h" |
| 17 #include "sync/util/cryptographer.h" | 17 #include "sync/util/cryptographer.h" |
| 18 #include "sync/util/time.h" | 18 #include "sync/util/time.h" |
| 19 | 19 |
| 20 namespace syncer_v2 { | 20 namespace syncer_v2 { |
| 21 | 21 |
| 22 using syncer::CommitContribution; | 22 using syncer::CommitContribution; |
| 23 using syncer::Cryptographer; | 23 using syncer::Cryptographer; |
| 24 using syncer::ModelType; | 24 using syncer::ModelType; |
| 25 using syncer::NudgeHandler; | 25 using syncer::NudgeHandler; |
| 26 using syncer::SyncerError; | 26 using syncer::SyncerError; |
| 27 | 27 |
| 28 ModelTypeSyncWorkerImpl::ModelTypeSyncWorkerImpl( | 28 CommitQueueImpl::CommitQueueImpl( |
| 29 ModelType type, | 29 ModelType type, |
| 30 const DataTypeState& initial_state, | 30 const DataTypeState& initial_state, |
| 31 const UpdateResponseDataList& saved_pending_updates, | 31 const UpdateResponseDataList& saved_pending_updates, |
| 32 scoped_ptr<Cryptographer> cryptographer, | 32 scoped_ptr<Cryptographer> cryptographer, |
| 33 NudgeHandler* nudge_handler, | 33 NudgeHandler* nudge_handler, |
| 34 scoped_ptr<ModelTypeSyncProxy> type_sync_proxy) | 34 scoped_ptr<ModelTypeProcessor> type_sync_proxy) |
| 35 : type_(type), | 35 : type_(type), |
| 36 data_type_state_(initial_state), | 36 data_type_state_(initial_state), |
| 37 type_sync_proxy_(type_sync_proxy.Pass()), | 37 type_sync_proxy_(type_sync_proxy.Pass()), |
| 38 cryptographer_(cryptographer.Pass()), | 38 cryptographer_(cryptographer.Pass()), |
| 39 nudge_handler_(nudge_handler), | 39 nudge_handler_(nudge_handler), |
| 40 weak_ptr_factory_(this) { | 40 weak_ptr_factory_(this) { |
| 41 // Request an initial sync if it hasn't been completed yet. | 41 // Request an initial sync if it hasn't been completed yet. |
| 42 if (!data_type_state_.initial_sync_done) { | 42 if (!data_type_state_.initial_sync_done) { |
| 43 nudge_handler_->NudgeForInitialDownload(type_); | 43 nudge_handler_->NudgeForInitialDownload(type_); |
| 44 } | 44 } |
| 45 | 45 |
| 46 for (UpdateResponseDataList::const_iterator it = | 46 for (UpdateResponseDataList::const_iterator it = |
| 47 saved_pending_updates.begin(); | 47 saved_pending_updates.begin(); |
| 48 it != saved_pending_updates.end(); ++it) { | 48 it != saved_pending_updates.end(); ++it) { |
| 49 scoped_ptr<EntityTracker> entity_tracker = EntityTracker::FromServerUpdate( | 49 scoped_ptr<EntityTracker> entity_tracker = EntityTracker::FromServerUpdate( |
| 50 it->id, it->client_tag_hash, it->response_version); | 50 it->id, it->client_tag_hash, it->response_version); |
| 51 entity_tracker->ReceivePendingUpdate(*it); | 51 entity_tracker->ReceivePendingUpdate(*it); |
| 52 entities_.insert(it->client_tag_hash, entity_tracker.Pass()); | 52 entities_.insert(it->client_tag_hash, entity_tracker.Pass()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 if (cryptographer_) { | 55 if (cryptographer_) { |
| 56 DVLOG(1) << ModelTypeToString(type_) << ": Starting with encryption key " | 56 DVLOG(1) << ModelTypeToString(type_) << ": Starting with encryption key " |
| 57 << cryptographer_->GetDefaultNigoriKeyName(); | 57 << cryptographer_->GetDefaultNigoriKeyName(); |
| 58 OnCryptographerUpdated(); | 58 OnCryptographerUpdated(); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 ModelTypeSyncWorkerImpl::~ModelTypeSyncWorkerImpl() { | 62 CommitQueueImpl::~CommitQueueImpl() { |
| 63 } | 63 } |
| 64 | 64 |
| 65 ModelType ModelTypeSyncWorkerImpl::GetModelType() const { | 65 ModelType CommitQueueImpl::GetModelType() const { |
| 66 DCHECK(CalledOnValidThread()); | 66 DCHECK(CalledOnValidThread()); |
| 67 return type_; | 67 return type_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool ModelTypeSyncWorkerImpl::IsEncryptionRequired() const { | 70 bool CommitQueueImpl::IsEncryptionRequired() const { |
| 71 return !!cryptographer_; | 71 return !!cryptographer_; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void ModelTypeSyncWorkerImpl::UpdateCryptographer( | 74 void CommitQueueImpl::UpdateCryptographer( |
| 75 scoped_ptr<Cryptographer> cryptographer) { | 75 scoped_ptr<Cryptographer> cryptographer) { |
| 76 DCHECK(cryptographer); | 76 DCHECK(cryptographer); |
| 77 cryptographer_ = cryptographer.Pass(); | 77 cryptographer_ = cryptographer.Pass(); |
| 78 | 78 |
| 79 // Update our state and that of the proxy. | 79 // Update our state and that of the proxy. |
| 80 OnCryptographerUpdated(); | 80 OnCryptographerUpdated(); |
| 81 | 81 |
| 82 // Nudge the scheduler if we're now allowed to commit. | 82 // Nudge the scheduler if we're now allowed to commit. |
| 83 if (CanCommitItems()) | 83 if (CanCommitItems()) |
| 84 nudge_handler_->NudgeForCommit(type_); | 84 nudge_handler_->NudgeForCommit(type_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // UpdateHandler implementation. | 87 // UpdateHandler implementation. |
| 88 void ModelTypeSyncWorkerImpl::GetDownloadProgress( | 88 void CommitQueueImpl::GetDownloadProgress( |
| 89 sync_pb::DataTypeProgressMarker* progress_marker) const { | 89 sync_pb::DataTypeProgressMarker* progress_marker) const { |
| 90 DCHECK(CalledOnValidThread()); | 90 DCHECK(CalledOnValidThread()); |
| 91 progress_marker->CopyFrom(data_type_state_.progress_marker); | 91 progress_marker->CopyFrom(data_type_state_.progress_marker); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void ModelTypeSyncWorkerImpl::GetDataTypeContext( | 94 void CommitQueueImpl::GetDataTypeContext( |
| 95 sync_pb::DataTypeContext* context) const { | 95 sync_pb::DataTypeContext* context) const { |
| 96 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
| 97 context->CopyFrom(data_type_state_.type_context); | 97 context->CopyFrom(data_type_state_.type_context); |
| 98 } | 98 } |
| 99 | 99 |
| 100 SyncerError ModelTypeSyncWorkerImpl::ProcessGetUpdatesResponse( | 100 SyncerError CommitQueueImpl::ProcessGetUpdatesResponse( |
| 101 const sync_pb::DataTypeProgressMarker& progress_marker, | 101 const sync_pb::DataTypeProgressMarker& progress_marker, |
| 102 const sync_pb::DataTypeContext& mutated_context, | 102 const sync_pb::DataTypeContext& mutated_context, |
| 103 const SyncEntityList& applicable_updates, | 103 const SyncEntityList& applicable_updates, |
| 104 syncer::sessions::StatusController* status) { | 104 syncer::sessions::StatusController* status) { |
| 105 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
| 106 | 106 |
| 107 // TODO(rlarocque): Handle data type context conflicts. | 107 // TODO(rlarocque): Handle data type context conflicts. |
| 108 data_type_state_.type_context = mutated_context; | 108 data_type_state_.type_context = mutated_context; |
| 109 data_type_state_.progress_marker = progress_marker; | 109 data_type_state_.progress_marker = progress_marker; |
| 110 | 110 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 response_datas.size(), | 187 response_datas.size(), |
| 188 pending_updates.size()); | 188 pending_updates.size()); |
| 189 | 189 |
| 190 // Forward these updates to the model thread so it can do the rest. | 190 // Forward these updates to the model thread so it can do the rest. |
| 191 type_sync_proxy_->OnUpdateReceived( | 191 type_sync_proxy_->OnUpdateReceived( |
| 192 data_type_state_, response_datas, pending_updates); | 192 data_type_state_, response_datas, pending_updates); |
| 193 | 193 |
| 194 return syncer::SYNCER_OK; | 194 return syncer::SYNCER_OK; |
| 195 } | 195 } |
| 196 | 196 |
| 197 void ModelTypeSyncWorkerImpl::ApplyUpdates( | 197 void CommitQueueImpl::ApplyUpdates( |
| 198 syncer::sessions::StatusController* status) { | 198 syncer::sessions::StatusController* status) { |
| 199 DCHECK(CalledOnValidThread()); | 199 DCHECK(CalledOnValidThread()); |
| 200 // This function is called only when we've finished a download cycle, ie. we | 200 // This function is called only when we've finished a download cycle, ie. we |
| 201 // got a response with changes_remaining == 0. If this is our first download | 201 // got a response with changes_remaining == 0. If this is our first download |
| 202 // cycle, we should update our state so the ModelTypeSyncProxy knows that | 202 // cycle, we should update our state so the ModelTypeProcessor knows that |
| 203 // it's safe to commit items now. | 203 // it's safe to commit items now. |
| 204 if (!data_type_state_.initial_sync_done) { | 204 if (!data_type_state_.initial_sync_done) { |
| 205 DVLOG(1) << "Delivering 'initial sync done' ping."; | 205 DVLOG(1) << "Delivering 'initial sync done' ping."; |
| 206 | 206 |
| 207 data_type_state_.initial_sync_done = true; | 207 data_type_state_.initial_sync_done = true; |
| 208 | 208 |
| 209 type_sync_proxy_->OnUpdateReceived( | 209 type_sync_proxy_->OnUpdateReceived( |
| 210 data_type_state_, UpdateResponseDataList(), UpdateResponseDataList()); | 210 data_type_state_, UpdateResponseDataList(), UpdateResponseDataList()); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 void ModelTypeSyncWorkerImpl::PassiveApplyUpdates( | 214 void CommitQueueImpl::PassiveApplyUpdates( |
| 215 syncer::sessions::StatusController* status) { | 215 syncer::sessions::StatusController* status) { |
| 216 NOTREACHED() | 216 NOTREACHED() |
| 217 << "Non-blocking types should never apply updates on sync thread. " | 217 << "Non-blocking types should never apply updates on sync thread. " |
| 218 << "ModelType is: " << ModelTypeToString(type_); | 218 << "ModelType is: " << ModelTypeToString(type_); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void ModelTypeSyncWorkerImpl::EnqueueForCommit( | 221 void CommitQueueImpl::EnqueueForCommit( |
| 222 const CommitRequestDataList& list) { | 222 const CommitRequestDataList& list) { |
| 223 DCHECK(CalledOnValidThread()); | 223 DCHECK(CalledOnValidThread()); |
| 224 | 224 |
| 225 DCHECK(IsTypeInitialized()) | 225 DCHECK(IsTypeInitialized()) |
| 226 << "Asked to commit items before type was initialized. " | 226 << "Asked to commit items before type was initialized. " |
| 227 << "ModelType is: " << ModelTypeToString(type_); | 227 << "ModelType is: " << ModelTypeToString(type_); |
| 228 | 228 |
| 229 for (CommitRequestDataList::const_iterator it = list.begin(); | 229 for (CommitRequestDataList::const_iterator it = list.begin(); |
| 230 it != list.end(); ++it) { | 230 it != list.end(); ++it) { |
| 231 StorePendingCommit(*it); | 231 StorePendingCommit(*it); |
| 232 } | 232 } |
| 233 | 233 |
| 234 if (CanCommitItems()) | 234 if (CanCommitItems()) |
| 235 nudge_handler_->NudgeForCommit(type_); | 235 nudge_handler_->NudgeForCommit(type_); |
| 236 } | 236 } |
| 237 | 237 |
| 238 // CommitContributor implementation. | 238 // CommitContributor implementation. |
| 239 scoped_ptr<CommitContribution> ModelTypeSyncWorkerImpl::GetContribution( | 239 scoped_ptr<CommitContribution> CommitQueueImpl::GetContribution( |
| 240 size_t max_entries) { | 240 size_t max_entries) { |
| 241 DCHECK(CalledOnValidThread()); | 241 DCHECK(CalledOnValidThread()); |
| 242 | 242 |
| 243 size_t space_remaining = max_entries; | 243 size_t space_remaining = max_entries; |
| 244 std::vector<int64> sequence_numbers; | 244 std::vector<int64> sequence_numbers; |
| 245 google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> commit_entities; | 245 google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> commit_entities; |
| 246 | 246 |
| 247 if (!CanCommitItems()) | 247 if (!CanCommitItems()) |
| 248 return scoped_ptr<CommitContribution>(); | 248 return scoped_ptr<CommitContribution>(); |
| 249 | 249 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 if (commit_entities.size() == 0) | 267 if (commit_entities.size() == 0) |
| 268 return scoped_ptr<CommitContribution>(); | 268 return scoped_ptr<CommitContribution>(); |
| 269 | 269 |
| 270 return scoped_ptr<CommitContribution>(new NonBlockingTypeCommitContribution( | 270 return scoped_ptr<CommitContribution>(new NonBlockingTypeCommitContribution( |
| 271 data_type_state_.type_context, commit_entities, sequence_numbers, this)); | 271 data_type_state_.type_context, commit_entities, sequence_numbers, this)); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void ModelTypeSyncWorkerImpl::StorePendingCommit( | 274 void CommitQueueImpl::StorePendingCommit( |
| 275 const CommitRequestData& request) { | 275 const CommitRequestData& request) { |
| 276 if (!request.deleted) { | 276 if (!request.deleted) { |
| 277 DCHECK_EQ(type_, syncer::GetModelTypeFromSpecifics(request.specifics)); | 277 DCHECK_EQ(type_, syncer::GetModelTypeFromSpecifics(request.specifics)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 EntityMap::const_iterator map_it = entities_.find(request.client_tag_hash); | 280 EntityMap::const_iterator map_it = entities_.find(request.client_tag_hash); |
| 281 if (map_it == entities_.end()) { | 281 if (map_it == entities_.end()) { |
| 282 scoped_ptr<EntityTracker> entity = EntityTracker::FromCommitRequest( | 282 scoped_ptr<EntityTracker> entity = EntityTracker::FromCommitRequest( |
| 283 request.id, request.client_tag_hash, request.sequence_number, | 283 request.id, request.client_tag_hash, request.sequence_number, |
| 284 request.base_version, request.ctime, request.mtime, | 284 request.base_version, request.ctime, request.mtime, |
| 285 request.non_unique_name, request.deleted, request.specifics); | 285 request.non_unique_name, request.deleted, request.specifics); |
| 286 entities_.insert(request.client_tag_hash, entity.Pass()); | 286 entities_.insert(request.client_tag_hash, entity.Pass()); |
| 287 } else { | 287 } else { |
| 288 EntityTracker* entity = map_it->second; | 288 EntityTracker* entity = map_it->second; |
| 289 entity->RequestCommit(request.id, | 289 entity->RequestCommit(request.id, |
| 290 request.client_tag_hash, | 290 request.client_tag_hash, |
| 291 request.sequence_number, | 291 request.sequence_number, |
| 292 request.base_version, | 292 request.base_version, |
| 293 request.ctime, | 293 request.ctime, |
| 294 request.mtime, | 294 request.mtime, |
| 295 request.non_unique_name, | 295 request.non_unique_name, |
| 296 request.deleted, | 296 request.deleted, |
| 297 request.specifics); | 297 request.specifics); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 void ModelTypeSyncWorkerImpl::OnCommitResponse( | 301 void CommitQueueImpl::OnCommitResponse( |
| 302 const CommitResponseDataList& response_list) { | 302 const CommitResponseDataList& response_list) { |
| 303 for (CommitResponseDataList::const_iterator response_it = | 303 for (CommitResponseDataList::const_iterator response_it = |
| 304 response_list.begin(); | 304 response_list.begin(); |
| 305 response_it != response_list.end(); ++response_it) { | 305 response_it != response_list.end(); ++response_it) { |
| 306 const std::string client_tag_hash = response_it->client_tag_hash; | 306 const std::string client_tag_hash = response_it->client_tag_hash; |
| 307 EntityMap::const_iterator map_it = entities_.find(client_tag_hash); | 307 EntityMap::const_iterator map_it = entities_.find(client_tag_hash); |
| 308 | 308 |
| 309 // There's no way we could have committed an entry we know nothing about. | 309 // There's no way we could have committed an entry we know nothing about. |
| 310 if (map_it == entities_.end()) { | 310 if (map_it == entities_.end()) { |
| 311 NOTREACHED() << "Received commit response for item unknown to us." | 311 NOTREACHED() << "Received commit response for item unknown to us." |
| 312 << " Model type: " << ModelTypeToString(type_) | 312 << " Model type: " << ModelTypeToString(type_) |
| 313 << " ID: " << response_it->id; | 313 << " ID: " << response_it->id; |
| 314 continue; | 314 continue; |
| 315 } | 315 } |
| 316 | 316 |
| 317 EntityTracker* entity = map_it->second; | 317 EntityTracker* entity = map_it->second; |
| 318 entity->ReceiveCommitResponse(response_it->id, | 318 entity->ReceiveCommitResponse(response_it->id, |
| 319 response_it->response_version, | 319 response_it->response_version, |
| 320 response_it->sequence_number); | 320 response_it->sequence_number); |
| 321 } | 321 } |
| 322 | 322 |
| 323 // Send the responses back to the model thread. It needs to know which | 323 // Send the responses back to the model thread. It needs to know which |
| 324 // items have been successfully committed so it can save that information in | 324 // items have been successfully committed so it can save that information in |
| 325 // permanent storage. | 325 // permanent storage. |
| 326 type_sync_proxy_->OnCommitCompleted(data_type_state_, response_list); | 326 type_sync_proxy_->OnCommitCompleted(data_type_state_, response_list); |
| 327 } | 327 } |
| 328 | 328 |
| 329 base::WeakPtr<ModelTypeSyncWorkerImpl> ModelTypeSyncWorkerImpl::AsWeakPtr() { | 329 base::WeakPtr<CommitQueueImpl> CommitQueueImpl::AsWeakPtr() { |
| 330 return weak_ptr_factory_.GetWeakPtr(); | 330 return weak_ptr_factory_.GetWeakPtr(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool ModelTypeSyncWorkerImpl::IsTypeInitialized() const { | 333 bool CommitQueueImpl::IsTypeInitialized() const { |
| 334 return data_type_state_.initial_sync_done && | 334 return data_type_state_.initial_sync_done && |
| 335 !data_type_state_.progress_marker.token().empty(); | 335 !data_type_state_.progress_marker.token().empty(); |
| 336 } | 336 } |
| 337 | 337 |
| 338 bool ModelTypeSyncWorkerImpl::CanCommitItems() const { | 338 bool CommitQueueImpl::CanCommitItems() const { |
| 339 // We can't commit anything until we know the type's parent node. | 339 // We can't commit anything until we know the type's parent node. |
| 340 // We'll get it in the first update response. | 340 // We'll get it in the first update response. |
| 341 if (!IsTypeInitialized()) | 341 if (!IsTypeInitialized()) |
| 342 return false; | 342 return false; |
| 343 | 343 |
| 344 // Don't commit if we should be encrypting but don't have the required keys. | 344 // Don't commit if we should be encrypting but don't have the required keys. |
| 345 if (IsEncryptionRequired() && | 345 if (IsEncryptionRequired() && |
| 346 (!cryptographer_ || !cryptographer_->is_ready())) { | 346 (!cryptographer_ || !cryptographer_->is_ready())) { |
| 347 return false; | 347 return false; |
| 348 } | 348 } |
| 349 | 349 |
| 350 return true; | 350 return true; |
| 351 } | 351 } |
| 352 | 352 |
| 353 void ModelTypeSyncWorkerImpl::HelpInitializeCommitEntity( | 353 void CommitQueueImpl::HelpInitializeCommitEntity( |
| 354 sync_pb::SyncEntity* sync_entity) { | 354 sync_pb::SyncEntity* sync_entity) { |
| 355 DCHECK(CanCommitItems()); | 355 DCHECK(CanCommitItems()); |
| 356 | 356 |
| 357 // Initial commits need our help to generate a client ID. | 357 // Initial commits need our help to generate a client ID. |
| 358 if (!sync_entity->has_id_string()) { | 358 if (!sync_entity->has_id_string()) { |
| 359 DCHECK_EQ(kUncommittedVersion, sync_entity->version()); | 359 DCHECK_EQ(kUncommittedVersion, sync_entity->version()); |
| 360 // TODO(stanisc): This is incorrect for bookmarks for two reasons: | 360 // TODO(stanisc): This is incorrect for bookmarks for two reasons: |
| 361 // 1) Won't be able to match previously committed bookmarks to the ones | 361 // 1) Won't be able to match previously committed bookmarks to the ones |
| 362 // with server ID. | 362 // with server ID. |
| 363 // 2) Recommitting an item in a case of failing to receive commit response | 363 // 2) Recommitting an item in a case of failing to receive commit response |
| (...skipping 16 matching lines...) Expand all Loading... |
| 380 } | 380 } |
| 381 | 381 |
| 382 // Always include enough specifics to identify the type. Do this even in | 382 // Always include enough specifics to identify the type. Do this even in |
| 383 // deletion requests, where the specifics are otherwise invalid. | 383 // deletion requests, where the specifics are otherwise invalid. |
| 384 AddDefaultFieldValue(type_, sync_entity->mutable_specifics()); | 384 AddDefaultFieldValue(type_, sync_entity->mutable_specifics()); |
| 385 | 385 |
| 386 // TODO(stanisc): crbug.com/516866: | 386 // TODO(stanisc): crbug.com/516866: |
| 387 // Call sync_entity->set_parent_id_string(...) for hierarchical entities here. | 387 // Call sync_entity->set_parent_id_string(...) for hierarchical entities here. |
| 388 } | 388 } |
| 389 | 389 |
| 390 void ModelTypeSyncWorkerImpl::OnCryptographerUpdated() { | 390 void CommitQueueImpl::OnCryptographerUpdated() { |
| 391 DCHECK(cryptographer_); | 391 DCHECK(cryptographer_); |
| 392 | 392 |
| 393 bool new_encryption_key = false; | 393 bool new_encryption_key = false; |
| 394 UpdateResponseDataList response_datas; | 394 UpdateResponseDataList response_datas; |
| 395 | 395 |
| 396 const std::string& new_key_name = cryptographer_->GetDefaultNigoriKeyName(); | 396 const std::string& new_key_name = cryptographer_->GetDefaultNigoriKeyName(); |
| 397 | 397 |
| 398 // Handle a change in encryption key. | 398 // Handle a change in encryption key. |
| 399 if (data_type_state_.encryption_key_name != new_key_name) { | 399 if (data_type_state_.encryption_key_name != new_key_name) { |
| 400 DVLOG(1) << ModelTypeToString(type_) << ": Updating encryption key " | 400 DVLOG(1) << ModelTypeToString(type_) << ": Updating encryption key " |
| (...skipping 29 matching lines...) Expand all Loading... |
| 430 if (new_encryption_key || response_datas.size() > 0) { | 430 if (new_encryption_key || response_datas.size() > 0) { |
| 431 DVLOG(1) << ModelTypeToString(type_) << ": " | 431 DVLOG(1) << ModelTypeToString(type_) << ": " |
| 432 << base::StringPrintf( | 432 << base::StringPrintf( |
| 433 "Delivering encryption key and %zd decrypted updates.", | 433 "Delivering encryption key and %zd decrypted updates.", |
| 434 response_datas.size()); | 434 response_datas.size()); |
| 435 type_sync_proxy_->OnUpdateReceived(data_type_state_, response_datas, | 435 type_sync_proxy_->OnUpdateReceived(data_type_state_, response_datas, |
| 436 UpdateResponseDataList()); | 436 UpdateResponseDataList()); |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 | 439 |
| 440 bool ModelTypeSyncWorkerImpl::DecryptSpecifics( | 440 bool CommitQueueImpl::DecryptSpecifics( |
| 441 Cryptographer* cryptographer, | 441 Cryptographer* cryptographer, |
| 442 const sync_pb::EntitySpecifics& in, | 442 const sync_pb::EntitySpecifics& in, |
| 443 sync_pb::EntitySpecifics* out) { | 443 sync_pb::EntitySpecifics* out) { |
| 444 DCHECK(in.has_encrypted()); | 444 DCHECK(in.has_encrypted()); |
| 445 DCHECK(cryptographer->CanDecrypt(in.encrypted())); | 445 DCHECK(cryptographer->CanDecrypt(in.encrypted())); |
| 446 | 446 |
| 447 std::string plaintext; | 447 std::string plaintext; |
| 448 plaintext = cryptographer->DecryptToString(in.encrypted()); | 448 plaintext = cryptographer->DecryptToString(in.encrypted()); |
| 449 if (plaintext.empty()) { | 449 if (plaintext.empty()) { |
| 450 LOG(ERROR) << "Failed to decrypt a decryptable entity"; | 450 LOG(ERROR) << "Failed to decrypt a decryptable entity"; |
| 451 return false; | 451 return false; |
| 452 } | 452 } |
| 453 if (!out->ParseFromString(plaintext)) { | 453 if (!out->ParseFromString(plaintext)) { |
| 454 LOG(ERROR) << "Failed to parse decrypted entity"; | 454 LOG(ERROR) << "Failed to parse decrypted entity"; |
| 455 return false; | 455 return false; |
| 456 } | 456 } |
| 457 return true; | 457 return true; |
| 458 } | 458 } |
| 459 | 459 |
| 460 } // namespace syncer | 460 } // namespace syncer |
| OLD | NEW |