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

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

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. 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 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_service.h" 5 #include "components/sync/device_info/device_info_service.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "components/sync/api/entity_change.h" 14 #include "components/sync/api/entity_change.h"
15 #include "components/sync/api/metadata_batch.h" 15 #include "components/sync/api/metadata_batch.h"
16 #include "components/sync/api/sync_error.h" 16 #include "components/sync/api/sync_error.h"
17 #include "components/sync/base/time.h" 17 #include "components/sync/base/time.h"
18 #include "components/sync/core/data_batch_impl.h" 18 #include "components/sync/core/data_batch_impl.h"
19 #include "components/sync/device_info/device_info_util.h" 19 #include "components/sync/device_info/device_info_util.h"
20 #include "components/sync/protocol/data_type_state.pb.h" 20 #include "components/sync/protocol/data_type_state.pb.h"
21 #include "components/sync/protocol/sync.pb.h" 21 #include "components/sync/protocol/sync.pb.h"
22 22
23 namespace sync_driver_v2 { 23 namespace syncer {
24 24
25 using base::Time; 25 using base::Time;
26 using base::TimeDelta; 26 using base::TimeDelta;
27 using syncer::SyncError;
28 using syncer_v2::DataBatchImpl;
29 using syncer_v2::EntityChange;
30 using syncer_v2::EntityChangeList;
31 using syncer_v2::EntityData;
32 using syncer_v2::EntityDataMap;
33 using syncer_v2::MetadataBatch;
34 using syncer_v2::MetadataChangeList;
35 using syncer_v2::ModelTypeStore;
36 using syncer_v2::SimpleMetadataChangeList;
37 using sync_driver::DeviceInfo;
38 using sync_driver::DeviceInfoUtil;
39 using sync_pb::DataTypeState; 27 using sync_pb::DataTypeState;
40 using sync_pb::DeviceInfoSpecifics; 28 using sync_pb::DeviceInfoSpecifics;
41 using sync_pb::EntitySpecifics; 29 using sync_pb::EntitySpecifics;
42 30
43 using Record = ModelTypeStore::Record; 31 using Record = ModelTypeStore::Record;
44 using RecordList = ModelTypeStore::RecordList; 32 using RecordList = ModelTypeStore::RecordList;
45 using Result = ModelTypeStore::Result; 33 using Result = ModelTypeStore::Result;
46 using WriteBatch = ModelTypeStore::WriteBatch; 34 using WriteBatch = ModelTypeStore::WriteBatch;
47 35
48 DeviceInfoService::DeviceInfoService( 36 DeviceInfoService::DeviceInfoService(
49 sync_driver::LocalDeviceInfoProvider* local_device_info_provider, 37 LocalDeviceInfoProvider* local_device_info_provider,
50 const StoreFactoryFunction& callback, 38 const StoreFactoryFunction& callback,
51 const ChangeProcessorFactory& change_processor_factory) 39 const ChangeProcessorFactory& change_processor_factory)
52 : ModelTypeService(change_processor_factory, syncer::DEVICE_INFO), 40 : ModelTypeService(change_processor_factory, DEVICE_INFO),
53 local_device_info_provider_(local_device_info_provider) { 41 local_device_info_provider_(local_device_info_provider) {
54 DCHECK(local_device_info_provider); 42 DCHECK(local_device_info_provider);
55 43
56 // This is not threadsafe, but presuably the provider initializes on the same 44 // This is not threadsafe, but presuably the provider initializes on the same
57 // thread as us so we're okay. 45 // thread as us so we're okay.
58 if (local_device_info_provider->GetLocalDeviceInfo()) { 46 if (local_device_info_provider->GetLocalDeviceInfo()) {
59 OnProviderInitialized(); 47 OnProviderInitialized();
60 } else { 48 } else {
61 subscription_ = 49 subscription_ =
62 local_device_info_provider->RegisterOnInitializedCallback(base::Bind( 50 local_device_info_provider->RegisterOnInitializedCallback(base::Bind(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 kv.second.value().specifics.device_info(); 89 kv.second.value().specifics.device_info();
102 DCHECK_EQ(kv.first, specifics.cache_guid()); 90 DCHECK_EQ(kv.first, specifics.cache_guid());
103 if (specifics.cache_guid() == local_guid) { 91 if (specifics.cache_guid() == local_guid) {
104 // Don't Put local data if it's the same as the remote copy. 92 // Don't Put local data if it's the same as the remote copy.
105 if (local_info->Equals(*CopyToModel(specifics))) { 93 if (local_info->Equals(*CopyToModel(specifics))) {
106 local_guids_to_put.erase(local_guid); 94 local_guids_to_put.erase(local_guid);
107 } else { 95 } else {
108 // This device is valid right now and this entry is about to be 96 // This device is valid right now and this entry is about to be
109 // committed, use this as an opportunity to refresh the timestamp. 97 // committed, use this as an opportunity to refresh the timestamp.
110 all_data_[local_guid]->set_last_updated_timestamp( 98 all_data_[local_guid]->set_last_updated_timestamp(
111 syncer::TimeToProtoTime(Time::Now())); 99 TimeToProtoTime(Time::Now()));
112 } 100 }
113 } else { 101 } else {
114 // Remote data wins conflicts. 102 // Remote data wins conflicts.
115 local_guids_to_put.erase(specifics.cache_guid()); 103 local_guids_to_put.erase(specifics.cache_guid());
116 has_changes = true; 104 has_changes = true;
117 StoreSpecifics(base::MakeUnique<DeviceInfoSpecifics>(specifics), 105 StoreSpecifics(base::MakeUnique<DeviceInfoSpecifics>(specifics),
118 batch.get()); 106 batch.get());
119 } 107 }
120 } 108 }
121 109
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 175 }
188 176
189 callback.Run(SyncError(), std::move(batch)); 177 callback.Run(SyncError(), std::move(batch));
190 } 178 }
191 179
192 std::string DeviceInfoService::GetClientTag(const EntityData& entity_data) { 180 std::string DeviceInfoService::GetClientTag(const EntityData& entity_data) {
193 DCHECK(entity_data.specifics.has_device_info()); 181 DCHECK(entity_data.specifics.has_device_info());
194 return DeviceInfoUtil::SpecificsToTag(entity_data.specifics.device_info()); 182 return DeviceInfoUtil::SpecificsToTag(entity_data.specifics.device_info());
195 } 183 }
196 184
197 std::string DeviceInfoService::GetStorageKey( 185 std::string DeviceInfoService::GetStorageKey(const EntityData& entity_data) {
198 const syncer_v2::EntityData& entity_data) {
199 DCHECK(entity_data.specifics.has_device_info()); 186 DCHECK(entity_data.specifics.has_device_info());
200 return entity_data.specifics.device_info().cache_guid(); 187 return entity_data.specifics.device_info().cache_guid();
201 } 188 }
202 189
203 void DeviceInfoService::OnChangeProcessorSet() { 190 void DeviceInfoService::OnChangeProcessorSet() {
204 // We've recieved a new processor that needs metadata. If we're still in the 191 // We've recieved a new processor that needs metadata. If we're still in the
205 // process of loading data and/or metadata, then |has_metadata_loaded_| is 192 // process of loading data and/or metadata, then |has_metadata_loaded_| is
206 // false and we'll wait for those async reads to happen. If we've already 193 // false and we'll wait for those async reads to happen. If we've already
207 // loaded metadata and then subsequently we get a new processor, we must not 194 // loaded metadata and then subsequently we get a new processor, we must not
208 // have created the processor ourselves because we had no metadata. So there 195 // have created the processor ourselves because we had no metadata. So there
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 void DeviceInfoService::SendLocalData() { 453 void DeviceInfoService::SendLocalData() {
467 DCHECK(has_provider_initialized_); 454 DCHECK(has_provider_initialized_);
468 // TODO(skym): Handle disconnecting and reconnecting, this will currently halt 455 // TODO(skym): Handle disconnecting and reconnecting, this will currently halt
469 // the pulse timer and never restart it. 456 // the pulse timer and never restart it.
470 if (!change_processor()) { 457 if (!change_processor()) {
471 return; 458 return;
472 } 459 }
473 460
474 std::unique_ptr<DeviceInfoSpecifics> specifics = 461 std::unique_ptr<DeviceInfoSpecifics> specifics =
475 CopyToSpecifics(*local_device_info_provider_->GetLocalDeviceInfo()); 462 CopyToSpecifics(*local_device_info_provider_->GetLocalDeviceInfo());
476 specifics->set_last_updated_timestamp(syncer::TimeToProtoTime(Time::Now())); 463 specifics->set_last_updated_timestamp(TimeToProtoTime(Time::Now()));
477 464
478 std::unique_ptr<MetadataChangeList> metadata_change_list = 465 std::unique_ptr<MetadataChangeList> metadata_change_list =
479 CreateMetadataChangeList(); 466 CreateMetadataChangeList();
480 change_processor()->Put(specifics->cache_guid(), CopyToEntityData(*specifics), 467 change_processor()->Put(specifics->cache_guid(), CopyToEntityData(*specifics),
481 metadata_change_list.get()); 468 metadata_change_list.get());
482 469
483 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch(); 470 std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch();
484 StoreSpecifics(std::move(specifics), batch.get()); 471 StoreSpecifics(std::move(specifics), batch.get());
485 472
486 CommitAndNotify(std::move(batch), std::move(metadata_change_list), true); 473 CommitAndNotify(std::move(batch), std::move(metadata_change_list), true);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 CreateChangeProcessor(); 507 CreateChangeProcessor();
521 } 508 }
522 change_processor()->OnMetadataLoaded( 509 change_processor()->OnMetadataLoaded(
523 change_processor()->CreateAndUploadError(FROM_HERE, msg), nullptr); 510 change_processor()->CreateAndUploadError(FROM_HERE, msg), nullptr);
524 } 511 }
525 512
526 // static 513 // static
527 Time DeviceInfoService::GetLastUpdateTime( 514 Time DeviceInfoService::GetLastUpdateTime(
528 const DeviceInfoSpecifics& specifics) { 515 const DeviceInfoSpecifics& specifics) {
529 if (specifics.has_last_updated_timestamp()) { 516 if (specifics.has_last_updated_timestamp()) {
530 return syncer::ProtoTimeToTime(specifics.last_updated_timestamp()); 517 return ProtoTimeToTime(specifics.last_updated_timestamp());
531 } else { 518 } else {
532 return Time(); 519 return Time();
533 } 520 }
534 } 521 }
535 522
536 } // namespace sync_driver_v2 523 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/device_info/device_info_service.h ('k') | components/sync/device_info/device_info_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698