| OLD | NEW |
| 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_service.h" | 5 #include "components/sync/device_info/device_info_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 base::Unretained(this))); | 405 base::Unretained(this))); |
| 406 return; | 406 return; |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 SendLocalData(); | 409 SendLocalData(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 void DeviceInfoService::SendLocalData() { | 412 void DeviceInfoService::SendLocalData() { |
| 413 DCHECK(has_provider_initialized_); | 413 DCHECK(has_provider_initialized_); |
| 414 | 414 |
| 415 std::unique_ptr<DeviceInfoSpecifics> specifics = | 415 // It is possible that the provider no longer has data for us, such as when |
| 416 CopyToSpecifics(*local_device_info_provider_->GetLocalDeviceInfo()); | 416 // the user signs out. No-op this pulse, but keep the timer going in case sync |
| 417 specifics->set_last_updated_timestamp(TimeToProtoTime(Time::Now())); | 417 // is enabled later. |
| 418 if (local_device_info_provider_->GetLocalDeviceInfo() != nullptr) { |
| 419 std::unique_ptr<DeviceInfoSpecifics> specifics = |
| 420 CopyToSpecifics(*local_device_info_provider_->GetLocalDeviceInfo()); |
| 421 specifics->set_last_updated_timestamp(TimeToProtoTime(Time::Now())); |
| 418 | 422 |
| 419 std::unique_ptr<MetadataChangeList> metadata_change_list = | 423 std::unique_ptr<MetadataChangeList> metadata_change_list = |
| 420 CreateMetadataChangeList(); | 424 CreateMetadataChangeList(); |
| 421 if (change_processor()->IsTrackingMetadata()) { | 425 if (change_processor()->IsTrackingMetadata()) { |
| 422 change_processor()->Put(specifics->cache_guid(), | 426 change_processor()->Put(specifics->cache_guid(), |
| 423 CopyToEntityData(*specifics), | 427 CopyToEntityData(*specifics), |
| 424 metadata_change_list.get()); | 428 metadata_change_list.get()); |
| 429 } |
| 430 |
| 431 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); |
| 432 StoreSpecifics(std::move(specifics), batch.get()); |
| 433 CommitAndNotify(std::move(batch), std::move(metadata_change_list), true); |
| 425 } | 434 } |
| 426 | 435 |
| 427 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); | |
| 428 StoreSpecifics(std::move(specifics), batch.get()); | |
| 429 | |
| 430 CommitAndNotify(std::move(batch), std::move(metadata_change_list), true); | |
| 431 pulse_timer_.Start( | 436 pulse_timer_.Start( |
| 432 FROM_HERE, DeviceInfoUtil::kPulseInterval, | 437 FROM_HERE, DeviceInfoUtil::kPulseInterval, |
| 433 base::Bind(&DeviceInfoService::SendLocalData, base::Unretained(this))); | 438 base::Bind(&DeviceInfoService::SendLocalData, base::Unretained(this))); |
| 434 } | 439 } |
| 435 | 440 |
| 436 void DeviceInfoService::CommitAndNotify( | 441 void DeviceInfoService::CommitAndNotify( |
| 437 std::unique_ptr<WriteBatch> batch, | 442 std::unique_ptr<WriteBatch> batch, |
| 438 std::unique_ptr<MetadataChangeList> metadata_change_list, | 443 std::unique_ptr<MetadataChangeList> metadata_change_list, |
| 439 bool should_notify) { | 444 bool should_notify) { |
| 440 static_cast<SimpleMetadataChangeList*>(metadata_change_list.get()) | 445 static_cast<SimpleMetadataChangeList*>(metadata_change_list.get()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 466 Time DeviceInfoService::GetLastUpdateTime( | 471 Time DeviceInfoService::GetLastUpdateTime( |
| 467 const DeviceInfoSpecifics& specifics) { | 472 const DeviceInfoSpecifics& specifics) { |
| 468 if (specifics.has_last_updated_timestamp()) { | 473 if (specifics.has_last_updated_timestamp()) { |
| 469 return ProtoTimeToTime(specifics.last_updated_timestamp()); | 474 return ProtoTimeToTime(specifics.last_updated_timestamp()); |
| 470 } else { | 475 } else { |
| 471 return Time(); | 476 return Time(); |
| 472 } | 477 } |
| 473 } | 478 } |
| 474 | 479 |
| 475 } // namespace syncer | 480 } // namespace syncer |
| OLD | NEW |