| 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 #ifndef COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_ | 6 #define COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 std::unique_ptr<syncer_v2::ModelTypeStore> store); | 112 std::unique_ptr<syncer_v2::ModelTypeStore> store); |
| 113 void OnReadAllData( | 113 void OnReadAllData( |
| 114 syncer_v2::ModelTypeStore::Result result, | 114 syncer_v2::ModelTypeStore::Result result, |
| 115 std::unique_ptr<syncer_v2::ModelTypeStore::RecordList> record_list); | 115 std::unique_ptr<syncer_v2::ModelTypeStore::RecordList> record_list); |
| 116 void OnReadAllMetadata( | 116 void OnReadAllMetadata( |
| 117 syncer_v2::ModelTypeStore::Result result, | 117 syncer_v2::ModelTypeStore::Result result, |
| 118 std::unique_ptr<syncer_v2::ModelTypeStore::RecordList> metadata_records, | 118 std::unique_ptr<syncer_v2::ModelTypeStore::RecordList> metadata_records, |
| 119 const std::string& global_metadata); | 119 const std::string& global_metadata); |
| 120 void OnCommit(syncer_v2::ModelTypeStore::Result result); | 120 void OnCommit(syncer_v2::ModelTypeStore::Result result); |
| 121 | 121 |
| 122 // Checks if conditions have been met to perform reconciliation between the | 122 // Load metadata if the data is loaded and the provider is initialized. |
| 123 // locally provide device info and the stored device info data. If conditions | 123 void LoadMetadataIfReady(); |
| 124 // are met and the sets of data differ, than we condier this a local change | 124 |
| 125 // and we send it to the processor. | 125 // Performs reconciliation between the locally provided device info and the |
| 126 void TryReconcileLocalAndStored(); | 126 // stored device info data. If the sets of data differ, then we consider this |
| 127 // a local change and we send it to the processor. |
| 128 void ReconcileLocalAndStored(); |
| 127 | 129 |
| 128 // Stores the updated version of the local copy of device info in durable | 130 // Stores the updated version of the local copy of device info in durable |
| 129 // storage, in memory, and informs sync of the change. Should not be called | 131 // storage, in memory, and informs sync of the change. Should not be called |
| 130 // before the provider and processor have initialized. | 132 // before the provider and processor have initialized. |
| 131 void SendLocalData(); | 133 void SendLocalData(); |
| 132 | 134 |
| 133 // Persists the changes in the given aggregators and notifies observers if | 135 // Persists the changes in the given aggregators and notifies observers if |
| 134 // indicated to do as such. | 136 // indicated to do as such. |
| 135 void CommitAndNotify( | 137 void CommitAndNotify( |
| 136 std::unique_ptr<syncer_v2::ModelTypeStore::WriteBatch> batch, | 138 std::unique_ptr<syncer_v2::ModelTypeStore::WriteBatch> batch, |
| 137 std::unique_ptr<syncer_v2::MetadataChangeList> metadata_change_list, | 139 std::unique_ptr<syncer_v2::MetadataChangeList> metadata_change_list, |
| 138 bool should_notify); | 140 bool should_notify); |
| 139 | 141 |
| 140 // Counts the number of active devices relative to |now|. The activeness of a | 142 // Counts the number of active devices relative to |now|. The activeness of a |
| 141 // device depends on the amount of time since it was updated, which means | 143 // device depends on the amount of time since it was updated, which means |
| 142 // comparing it against the current time. |now| is passed into this method to | 144 // comparing it against the current time. |now| is passed into this method to |
| 143 // allow unit tests to control expected results. | 145 // allow unit tests to control expected results. |
| 144 int CountActiveDevices(const base::Time now) const; | 146 int CountActiveDevices(const base::Time now) const; |
| 145 | 147 |
| 148 // Report an error starting up to sync if it tries to connect to this |
| 149 // datatype, since these errors prevent us from knowing if sync is enabled. |
| 150 void ReportStartupErrorToSync(const std::string& msg); |
| 151 |
| 146 // Find the timestamp for the last time this |device_info| was edited. | 152 // Find the timestamp for the last time this |device_info| was edited. |
| 147 static base::Time GetLastUpdateTime( | 153 static base::Time GetLastUpdateTime( |
| 148 const sync_pb::DeviceInfoSpecifics& specifics); | 154 const sync_pb::DeviceInfoSpecifics& specifics); |
| 149 | 155 |
| 150 // |local_device_info_provider_| isn't owned. | 156 // |local_device_info_provider_| isn't owned. |
| 151 const sync_driver::LocalDeviceInfoProvider* const local_device_info_provider_; | 157 const sync_driver::LocalDeviceInfoProvider* const local_device_info_provider_; |
| 152 | 158 |
| 153 ClientIdToSpecifics all_data_; | 159 ClientIdToSpecifics all_data_; |
| 154 | 160 |
| 155 // Registered observers, not owned. | 161 // Registered observers, not owned. |
| 156 base::ObserverList<Observer, true> observers_; | 162 base::ObserverList<Observer, true> observers_; |
| 157 | 163 |
| 158 // Used to listen for provider initialization. If the provider is already | 164 // Used to listen for provider initialization. If the provider is already |
| 159 // initialized during our constructor then the subscription is never used. | 165 // initialized during our constructor then the subscription is never used. |
| 160 std::unique_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> | 166 std::unique_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> |
| 161 subscription_; | 167 subscription_; |
| 162 | 168 |
| 163 // In charge of actually persiting changes to disk, or loading previous data. | 169 // In charge of actually persiting changes to disk, or loading previous data. |
| 164 std::unique_ptr<syncer_v2::ModelTypeStore> store_; | 170 std::unique_ptr<syncer_v2::ModelTypeStore> store_; |
| 165 | 171 |
| 166 // If |local_device_info_provider_| has initialized. | 172 // If |local_device_info_provider_| has initialized. |
| 167 bool has_provider_initialized_ = false; | 173 bool has_provider_initialized_ = false; |
| 174 // If data has been loaded from the store. |
| 175 bool has_data_loaded_ = false; |
| 168 // if |change_processor()| has been given metadata. | 176 // if |change_processor()| has been given metadata. |
| 169 bool has_metadata_loaded_ = false; | 177 bool has_metadata_loaded_ = false; |
| 170 | 178 |
| 171 // Used to update our local device info once every pulse interval. | 179 // Used to update our local device info once every pulse interval. |
| 172 base::OneShotTimer pulse_timer_; | 180 base::OneShotTimer pulse_timer_; |
| 173 | 181 |
| 174 // Should always be last member. | 182 // Should always be last member. |
| 175 base::WeakPtrFactory<DeviceInfoService> weak_factory_; | 183 base::WeakPtrFactory<DeviceInfoService> weak_factory_; |
| 176 | 184 |
| 177 DISALLOW_COPY_AND_ASSIGN(DeviceInfoService); | 185 DISALLOW_COPY_AND_ASSIGN(DeviceInfoService); |
| 178 }; | 186 }; |
| 179 | 187 |
| 180 } // namespace sync_driver_v2 | 188 } // namespace sync_driver_v2 |
| 181 | 189 |
| 182 #endif // COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_ | 190 #endif // COMPONENTS_SYNC_DRIVER_DEVICE_INFO_SERVICE_H_ |
| OLD | NEW |