diff options
Diffstat (limited to 'components/sync_driver')
-rw-r--r-- | components/sync_driver/device_info_service.cc | 36 | ||||
-rw-r--r-- | components/sync_driver/device_info_service.h | 2 | ||||
-rw-r--r-- | components/sync_driver/device_info_service_unittest.cc | 50 |
3 files changed, 61 insertions, 27 deletions
diff --git a/components/sync_driver/device_info_service.cc b/components/sync_driver/device_info_service.cc index 0a5949e..933ff1e 100644 --- a/components/sync_driver/device_info_service.cc +++ b/components/sync_driver/device_info_service.cc @@ -14,6 +14,12 @@ namespace sync_driver_v2 { +using syncer::SyncError; +using syncer_v2::EntityChangeList; +using syncer_v2::EntityData; +using syncer_v2::EntityDataList; +using syncer_v2::MetadataChangeList; +using syncer_v2::SimpleMetadataChangeList; using sync_driver::DeviceInfo; using sync_pb::DeviceInfoSpecifics; @@ -23,6 +29,8 @@ DeviceInfoService::DeviceInfoService( local_device_info_provider_(local_device_info_provider) { DCHECK(local_device_info_provider); + // This is not threadsafe, but presuably the provider initializes on the same + // thread as us so we're okay. if (local_device_info_provider->GetLocalDeviceInfo()) { OnProviderInitialized(); } else { @@ -34,23 +42,22 @@ DeviceInfoService::DeviceInfoService( DeviceInfoService::~DeviceInfoService() {} -scoped_ptr<syncer_v2::MetadataChangeList> -DeviceInfoService::CreateMetadataChangeList() { - return make_scoped_ptr(new syncer_v2::SimpleMetadataChangeList()); +scoped_ptr<MetadataChangeList> DeviceInfoService::CreateMetadataChangeList() { + return make_scoped_ptr(new SimpleMetadataChangeList()); } -syncer::SyncError DeviceInfoService::MergeSyncData( - scoped_ptr<syncer_v2::MetadataChangeList> metadata_change_list, - syncer_v2::EntityDataList entity_data_list) { +SyncError DeviceInfoService::MergeSyncData( + scoped_ptr<MetadataChangeList> metadata_change_list, + EntityDataList entity_data_list) { // TODO(skym): Implementation. - return syncer::SyncError(); + return SyncError(); } -syncer::SyncError DeviceInfoService::ApplySyncChanges( - scoped_ptr<syncer_v2::MetadataChangeList> metadata_change_list, - syncer_v2::EntityChangeList entity_changes) { +SyncError DeviceInfoService::ApplySyncChanges( + scoped_ptr<MetadataChangeList> metadata_change_list, + EntityChangeList entity_changes) { // TODO(skym): Implementation. - return syncer::SyncError(); + return SyncError(); } void DeviceInfoService::LoadMetadata(MetadataCallback callback) { @@ -66,10 +73,9 @@ void DeviceInfoService::GetAllData(DataCallback callback) { // TODO(skym): Implementation. } -std::string DeviceInfoService::GetClientTag( - const syncer_v2::EntityData* entity_data) { - // TODO(skym): Implementation. - return ""; +std::string DeviceInfoService::GetClientTag(const EntityData& entity_data) { + DCHECK(entity_data.specifics.has_device_info()); + return entity_data.specifics.device_info().cache_guid(); } bool DeviceInfoService::IsSyncing() const { diff --git a/components/sync_driver/device_info_service.h b/components/sync_driver/device_info_service.h index fdd1127..4c8ac29 100644 --- a/components/sync_driver/device_info_service.h +++ b/components/sync_driver/device_info_service.h @@ -52,7 +52,7 @@ class DeviceInfoService : public syncer_v2::ModelTypeService, void LoadMetadata(MetadataCallback callback) override; void GetData(ClientKeyList client_keys, DataCallback callback) override; void GetAllData(DataCallback callback) override; - std::string GetClientTag(const syncer_v2::EntityData* entity_data) override; + std::string GetClientTag(const syncer_v2::EntityData& entity_data) override; // DeviceInfoTracker implementation. bool IsSyncing() const override; diff --git a/components/sync_driver/device_info_service_unittest.cc b/components/sync_driver/device_info_service_unittest.cc index 5144bd5..1aa553a 100644 --- a/components/sync_driver/device_info_service_unittest.cc +++ b/components/sync_driver/device_info_service_unittest.cc @@ -11,53 +11,81 @@ namespace sync_driver_v2 { +using syncer_v2::EntityData; using sync_driver::DeviceInfo; using sync_driver::DeviceInfoTracker; using sync_driver::LocalDeviceInfoProviderMock; +using sync_pb::EntitySpecifics; namespace { class DeviceInfoServiceTest : public testing::Test, public DeviceInfoTracker::Observer { protected: + ~DeviceInfoServiceTest() override { service_->RemoveObserver(this); } + + void OnDeviceInfoChange() override { num_device_info_changed_callbacks_++; } + + protected: DeviceInfoServiceTest() : num_device_info_changed_callbacks_(0) {} - void InitFully() { + DeviceInfoService* InitFully() { local_device_.reset(new LocalDeviceInfoProviderMock( "guid_1", "client_1", "Chromium 10k", "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id")); service_.reset(new DeviceInfoService(local_device_.get())); service_->AddObserver(this); + return service_.get(); } - void InitPartially() { + DeviceInfoService* InitPartially() { local_device_.reset(new LocalDeviceInfoProviderMock()); service_.reset(new DeviceInfoService(local_device_.get())); service_->AddObserver(this); + return service_.get(); } - ~DeviceInfoServiceTest() override { service_->RemoveObserver(this); } - - void OnDeviceInfoChange() override { num_device_info_changed_callbacks_++; } + int num_device_info_changed_callbacks() { + return num_device_info_changed_callbacks_; + } + LocalDeviceInfoProviderMock* local_device() { return local_device_.get(); } - protected: + private: int num_device_info_changed_callbacks_; scoped_ptr<LocalDeviceInfoProviderMock> local_device_; scoped_ptr<DeviceInfoService> service_; }; TEST_F(DeviceInfoServiceTest, StartSyncEmptyInitialData) { - InitFully(); - EXPECT_FALSE(service_->IsSyncing()); + DeviceInfoService* service = InitFully(); + EXPECT_FALSE(service->IsSyncing()); } TEST_F(DeviceInfoServiceTest, DelayedProviderInitialization) { - InitPartially(); - local_device_->Initialize(make_scoped_ptr( + DeviceInfoService* service = InitPartially(); + local_device()->Initialize(make_scoped_ptr( new DeviceInfo("guid_1", "client_1", "Chromium 10k", "Chrome 10k", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id"))); + EXPECT_FALSE(service->IsSyncing()); +} + +TEST_F(DeviceInfoServiceTest, GetClientTagNormal) { + DeviceInfoService* service = InitFully(); + const std::string guid = "abc"; + EntitySpecifics entity_specifics; + entity_specifics.mutable_device_info()->set_cache_guid(guid); + EntityData entity_data; + entity_data.specifics = entity_specifics; + EXPECT_EQ(guid, service->GetClientTag(entity_data)); +} - EXPECT_FALSE(service_->IsSyncing()); +TEST_F(DeviceInfoServiceTest, GetClientTagEmpty) { + DeviceInfoService* service = InitFully(); + EntitySpecifics entity_specifics; + entity_specifics.mutable_device_info(); + EntityData entity_data; + entity_data.specifics = entity_specifics; + EXPECT_EQ("", service->GetClientTag(entity_data)); } } // namespace |