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

Side by Side Diff: components/sync/device_info/device_info_sync_bridge.cc

Issue 2468423010: [Sync] ModelTypeStore::ReadMetadataCallback now returns a MetadataBatch (Closed)
Patch Set: Use SyncError instead of Result. Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/device_info/device_info_sync_bridge.h" 5 #include "components/sync/device_info/device_info_sync_bridge.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 361 }
362 362
363 void DeviceInfoSyncBridge::LoadMetadataIfReady() { 363 void DeviceInfoSyncBridge::LoadMetadataIfReady() {
364 if (has_data_loaded_ && has_provider_initialized_) { 364 if (has_data_loaded_ && has_provider_initialized_) {
365 store_->ReadAllMetadata(base::Bind(&DeviceInfoSyncBridge::OnReadAllMetadata, 365 store_->ReadAllMetadata(base::Bind(&DeviceInfoSyncBridge::OnReadAllMetadata,
366 base::AsWeakPtr(this))); 366 base::AsWeakPtr(this)));
367 } 367 }
368 } 368 }
369 369
370 void DeviceInfoSyncBridge::OnReadAllMetadata( 370 void DeviceInfoSyncBridge::OnReadAllMetadata(
371 Result result, 371 SyncError error,
372 std::unique_ptr<RecordList> metadata_records, 372 std::unique_ptr<MetadataBatch> metadata_batch) {
373 const std::string& global_metadata) { 373 change_processor()->OnMetadataLoaded(error, std::move(metadata_batch));
skym 2016/11/05 00:45:42 So much less code! However, this is perpetuating
maxbogue 2016/11/07 17:03:39 Eh, doesn't make it any harder to get rid of in th
374 if (result != Result::SUCCESS) {
375 ReportStartupErrorToSync("Load of metadata completely failed.");
376 return;
377 }
378
379 auto batch = base::MakeUnique<MetadataBatch>();
380 ModelTypeState state;
381 if (state.ParseFromString(global_metadata)) {
382 batch->SetModelTypeState(state);
383 } else {
384 ReportStartupErrorToSync("Failed to deserialize global metadata.");
385 return;
386 }
387
388 for (const Record& r : *metadata_records.get()) {
389 sync_pb::EntityMetadata entity_metadata;
390 if (entity_metadata.ParseFromString(r.value)) {
391 batch->AddMetadata(r.id, entity_metadata);
392 } else {
393 ReportStartupErrorToSync("Failed to deserialize entity metadata.");
394 }
395 }
396
397 change_processor()->OnMetadataLoaded(SyncError(), std::move(batch));
398 ReconcileLocalAndStored(); 374 ReconcileLocalAndStored();
399 } 375 }
400 376
401 void DeviceInfoSyncBridge::OnCommit(Result result) { 377 void DeviceInfoSyncBridge::OnCommit(Result result) {
402 if (result != Result::SUCCESS) { 378 if (result != Result::SUCCESS) {
403 change_processor()->CreateAndUploadError(FROM_HERE, 379 change_processor()->CreateAndUploadError(FROM_HERE,
404 "Failed a write to store."); 380 "Failed a write to store.");
405 } 381 }
406 } 382 }
407 383
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 455 }
480 456
481 void DeviceInfoSyncBridge::ReportStartupErrorToSync(const std::string& msg) { 457 void DeviceInfoSyncBridge::ReportStartupErrorToSync(const std::string& msg) {
482 // TODO(skym): Shouldn't need to log this here, reporting should always log. 458 // TODO(skym): Shouldn't need to log this here, reporting should always log.
483 LOG(WARNING) << msg; 459 LOG(WARNING) << msg;
484 change_processor()->OnMetadataLoaded( 460 change_processor()->OnMetadataLoaded(
485 change_processor()->CreateAndUploadError(FROM_HERE, msg), nullptr); 461 change_processor()->CreateAndUploadError(FROM_HERE, msg), nullptr);
486 } 462 }
487 463
488 } // namespace syncer 464 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698