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_driver/device_info_service.h" | 5 #include "components/sync_driver/device_info_service.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 using sync_pb::DeviceInfoSpecifics; | 35 using sync_pb::DeviceInfoSpecifics; |
36 using sync_pb::EntitySpecifics; | 36 using sync_pb::EntitySpecifics; |
37 | 37 |
38 using Record = ModelTypeStore::Record; | 38 using Record = ModelTypeStore::Record; |
39 using RecordList = ModelTypeStore::RecordList; | 39 using RecordList = ModelTypeStore::RecordList; |
40 using Result = ModelTypeStore::Result; | 40 using Result = ModelTypeStore::Result; |
41 using WriteBatch = ModelTypeStore::WriteBatch; | 41 using WriteBatch = ModelTypeStore::WriteBatch; |
42 | 42 |
43 DeviceInfoService::DeviceInfoService( | 43 DeviceInfoService::DeviceInfoService( |
44 sync_driver::LocalDeviceInfoProvider* local_device_info_provider, | 44 sync_driver::LocalDeviceInfoProvider* local_device_info_provider, |
45 const StoreFactoryFunction& callback) | 45 const StoreFactoryFunction& callback, |
46 : local_device_info_provider_(local_device_info_provider), | 46 const ChangeProcessorFactory& change_processor_factory) |
47 : ModelTypeService(change_processor_factory), | |
48 local_device_info_provider_(local_device_info_provider), | |
47 weak_factory_(this) { | 49 weak_factory_(this) { |
48 DCHECK(local_device_info_provider); | 50 DCHECK(local_device_info_provider); |
49 | 51 |
50 // This is not threadsafe, but presuably the provider initializes on the same | 52 // This is not threadsafe, but presuably the provider initializes on the same |
51 // thread as us so we're okay. | 53 // thread as us so we're okay. |
52 if (local_device_info_provider->GetLocalDeviceInfo()) { | 54 if (local_device_info_provider->GetLocalDeviceInfo()) { |
53 OnProviderInitialized(); | 55 OnProviderInitialized(); |
54 } else { | 56 } else { |
55 subscription_ = | 57 subscription_ = |
56 local_device_info_provider->RegisterOnInitializedCallback(base::Bind( | 58 local_device_info_provider->RegisterOnInitializedCallback(base::Bind( |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 LOG(WARNING) << "Initial load of data failed."; | 365 LOG(WARNING) << "Initial load of data failed."; |
364 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization | 366 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization |
365 // failure. | 367 // failure. |
366 } | 368 } |
367 } | 369 } |
368 | 370 |
369 void DeviceInfoService::OnReadAllMetadata( | 371 void DeviceInfoService::OnReadAllMetadata( |
370 Result result, | 372 Result result, |
371 scoped_ptr<RecordList> metadata_records, | 373 scoped_ptr<RecordList> metadata_records, |
372 const std::string& global_metadata) { | 374 const std::string& global_metadata) { |
375 if (metadata_records->size() > 0 || global_metadata.size() > 0) { | |
376 GetOrCreateChangeProcessor(); | |
377 } | |
373 if (!change_processor()) { | 378 if (!change_processor()) { |
374 // This datatype was disabled while this read was oustanding. | 379 // This datatype was disabled while this read was oustanding. |
375 return; | 380 return; |
376 } | 381 } |
377 if (result != Result::SUCCESS) { | 382 if (result != Result::SUCCESS) { |
378 // Store has encountered some serious error. We should still be able to | 383 // Store has encountered some serious error. We should still be able to |
379 // continue as a read only service, since if we got this far we must have | 384 // continue as a read only service, since if we got this far we must have |
380 // loaded all data out succesfully. TODO(skym): Should we communicate this | 385 // loaded all data out succesfully. TODO(skym): Should we communicate this |
381 // to sync somehow? | 386 // to sync somehow? |
382 LOG(WARNING) << "Load of metadata completely failed."; | 387 LOG(WARNING) << "Load of metadata completely failed."; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 LOG(WARNING) << "Failed a write to store."; | 419 LOG(WARNING) << "Failed a write to store."; |
415 } | 420 } |
416 } | 421 } |
417 | 422 |
418 void DeviceInfoService::TryReconcileLocalAndStored() { | 423 void DeviceInfoService::TryReconcileLocalAndStored() { |
419 // TODO(skym, crbug.com/582460): Implement logic to reconcile provider and | 424 // TODO(skym, crbug.com/582460): Implement logic to reconcile provider and |
420 // stored device infos. | 425 // stored device infos. |
421 } | 426 } |
422 | 427 |
423 void DeviceInfoService::TryLoadAllMetadata() { | 428 void DeviceInfoService::TryLoadAllMetadata() { |
424 if (has_data_loaded_ && change_processor()) { | 429 // TODO(skym): fix the double load metadata issue |
skym
2016/03/24 22:51:37
nit: Comments should look like sentences with capi
Gang Wu
2016/03/25 02:07:00
Done.
| |
430 if (has_data_loaded_) { | |
425 store_->ReadAllMetadata(base::Bind(&DeviceInfoService::OnReadAllMetadata, | 431 store_->ReadAllMetadata(base::Bind(&DeviceInfoService::OnReadAllMetadata, |
426 weak_factory_.GetWeakPtr())); | 432 weak_factory_.GetWeakPtr())); |
427 } | 433 } |
428 } | 434 } |
429 | 435 |
436 syncer::ModelType DeviceInfoService::type() const { | |
437 return syncer::DEVICE_INFO; | |
438 } | |
439 | |
430 } // namespace sync_driver_v2 | 440 } // namespace sync_driver_v2 |
OLD | NEW |