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

Unified Diff: components/sync/device_info/device_info_service.cc

Issue 2452523003: Sending local data avoid derefing null if the local provider no longer has data. (Closed)
Patch Set: Fixing DeviceInfoServiceTest.MergeWithData 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/sync/device_info/device_info_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/device_info/device_info_service.cc
diff --git a/components/sync/device_info/device_info_service.cc b/components/sync/device_info/device_info_service.cc
index f00c6c8ea4114464ca896f7c6488b179e61989b7..a5fb849eb0e5e0b6dc3fbe586a0ffa75b38136ce 100644
--- a/components/sync/device_info/device_info_service.cc
+++ b/components/sync/device_info/device_info_service.cc
@@ -412,22 +412,27 @@ void DeviceInfoService::ReconcileLocalAndStored() {
void DeviceInfoService::SendLocalData() {
DCHECK(has_provider_initialized_);
- std::unique_ptr<DeviceInfoSpecifics> specifics =
- CopyToSpecifics(*local_device_info_provider_->GetLocalDeviceInfo());
- specifics->set_last_updated_timestamp(TimeToProtoTime(Time::Now()));
-
- std::unique_ptr<MetadataChangeList> metadata_change_list =
- CreateMetadataChangeList();
- if (change_processor()->IsTrackingMetadata()) {
- change_processor()->Put(specifics->cache_guid(),
- CopyToEntityData(*specifics),
- metadata_change_list.get());
- }
+ // It is possible that the provider no longer has data for us, such as when
+ // the user signs out. No-op this pulse, but keep the timer going in case sync
+ // is enabled later.
+ if (local_device_info_provider_->GetLocalDeviceInfo() != nullptr) {
+ std::unique_ptr<DeviceInfoSpecifics> specifics =
+ CopyToSpecifics(*local_device_info_provider_->GetLocalDeviceInfo());
+ specifics->set_last_updated_timestamp(TimeToProtoTime(Time::Now()));
+
+ std::unique_ptr<MetadataChangeList> metadata_change_list =
+ CreateMetadataChangeList();
+ if (change_processor()->IsTrackingMetadata()) {
+ change_processor()->Put(specifics->cache_guid(),
+ CopyToEntityData(*specifics),
+ metadata_change_list.get());
+ }
- std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch();
- StoreSpecifics(std::move(specifics), batch.get());
+ std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch();
+ StoreSpecifics(std::move(specifics), batch.get());
+ CommitAndNotify(std::move(batch), std::move(metadata_change_list), true);
+ }
- CommitAndNotify(std::move(batch), std::move(metadata_change_list), true);
pulse_timer_.Start(
FROM_HERE, DeviceInfoUtil::kPulseInterval,
base::Bind(&DeviceInfoService::SendLocalData, base::Unretained(this)));
« no previous file with comments | « no previous file | components/sync/device_info/device_info_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698