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

Side by Side Diff: components/sync/device_info/device_info_sync_bridge.h

Issue 2618483003: [Sync] Introduce ModelError for USS error handling. (Closed)
Patch Set: Address comments. Created 3 years, 11 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
« no previous file with comments | « components/sync/BUILD.gn ('k') | components/sync/device_info/device_info_sync_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_BRIDGE_H_ 5 #ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_BRIDGE_H_
6 #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_BRIDGE_H_ 6 #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_BRIDGE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
18 #include "components/sync/device_info/device_info_tracker.h" 18 #include "components/sync/device_info/device_info_tracker.h"
19 #include "components/sync/device_info/local_device_info_provider.h" 19 #include "components/sync/device_info/local_device_info_provider.h"
20 #include "components/sync/model/model_error.h"
20 #include "components/sync/model/model_type_store.h" 21 #include "components/sync/model/model_type_store.h"
21 #include "components/sync/model/model_type_sync_bridge.h" 22 #include "components/sync/model/model_type_sync_bridge.h"
22 23
23 namespace sync_pb { 24 namespace sync_pb {
24 class DeviceInfoSpecifics; 25 class DeviceInfoSpecifics;
25 } // namespace sync_pb 26 } // namespace sync_pb
26 27
27 namespace syncer { 28 namespace syncer {
28 29
29 class SyncError;
30
31 // Sync bridge implementation for DEVICE_INFO model type. Handles storage of 30 // Sync bridge implementation for DEVICE_INFO model type. Handles storage of
32 // device info and associated sync metadata, applying/merging foreign changes, 31 // device info and associated sync metadata, applying/merging foreign changes,
33 // and allows public read access. 32 // and allows public read access.
34 class DeviceInfoSyncBridge : public ModelTypeSyncBridge, 33 class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
35 public DeviceInfoTracker { 34 public DeviceInfoTracker {
36 public: 35 public:
37 typedef base::Callback<void(const ModelTypeStore::InitCallback& callback)> 36 typedef base::Callback<void(const ModelTypeStore::InitCallback& callback)>
38 StoreFactoryFunction; 37 StoreFactoryFunction;
39 38
40 DeviceInfoSyncBridge(LocalDeviceInfoProvider* local_device_info_provider, 39 DeviceInfoSyncBridge(LocalDeviceInfoProvider* local_device_info_provider,
41 const StoreFactoryFunction& callback, 40 const StoreFactoryFunction& callback,
42 const ChangeProcessorFactory& change_processor_factory); 41 const ChangeProcessorFactory& change_processor_factory);
43 ~DeviceInfoSyncBridge() override; 42 ~DeviceInfoSyncBridge() override;
44 43
45 // ModelTypeSyncBridge implementation. 44 // ModelTypeSyncBridge implementation.
46 std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() override; 45 std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() override;
47 SyncError MergeSyncData( 46 ModelError MergeSyncData(
48 std::unique_ptr<MetadataChangeList> metadata_change_list, 47 std::unique_ptr<MetadataChangeList> metadata_change_list,
49 EntityDataMap entity_data_map) override; 48 EntityDataMap entity_data_map) override;
50 SyncError ApplySyncChanges( 49 ModelError ApplySyncChanges(
51 std::unique_ptr<MetadataChangeList> metadata_change_list, 50 std::unique_ptr<MetadataChangeList> metadata_change_list,
52 EntityChangeList entity_changes) override; 51 EntityChangeList entity_changes) override;
53 void GetData(StorageKeyList storage_keys, DataCallback callback) override; 52 void GetData(StorageKeyList storage_keys, DataCallback callback) override;
54 void GetAllData(DataCallback callback) override; 53 void GetAllData(DataCallback callback) override;
55 std::string GetClientTag(const EntityData& entity_data) override; 54 std::string GetClientTag(const EntityData& entity_data) override;
56 std::string GetStorageKey(const EntityData& entity_data) override; 55 std::string GetStorageKey(const EntityData& entity_data) override;
57 void DisableSync() override; 56 void DisableSync() override;
58 57
59 // DeviceInfoTracker implementation. 58 // DeviceInfoTracker implementation.
60 bool IsSyncing() const override; 59 bool IsSyncing() const override;
(...skipping 23 matching lines...) Expand all
84 void NotifyObservers(); 83 void NotifyObservers();
85 84
86 // Used as callback given to LocalDeviceInfoProvider. 85 // Used as callback given to LocalDeviceInfoProvider.
87 void OnProviderInitialized(); 86 void OnProviderInitialized();
88 87
89 // Methods used as callbacks given to DataTypeStore. 88 // Methods used as callbacks given to DataTypeStore.
90 void OnStoreCreated(ModelTypeStore::Result result, 89 void OnStoreCreated(ModelTypeStore::Result result,
91 std::unique_ptr<ModelTypeStore> store); 90 std::unique_ptr<ModelTypeStore> store);
92 void OnReadAllData(ModelTypeStore::Result result, 91 void OnReadAllData(ModelTypeStore::Result result,
93 std::unique_ptr<ModelTypeStore::RecordList> record_list); 92 std::unique_ptr<ModelTypeStore::RecordList> record_list);
94 void OnReadAllMetadata(SyncError error, 93 void OnReadAllMetadata(ModelError error,
95 std::unique_ptr<MetadataBatch> metadata_batch); 94 std::unique_ptr<MetadataBatch> metadata_batch);
96 void OnCommit(ModelTypeStore::Result result); 95 void OnCommit(ModelTypeStore::Result result);
97 96
98 // Load metadata if the data is loaded and the provider is initialized. 97 // Load metadata if the data is loaded and the provider is initialized.
99 void LoadMetadataIfReady(); 98 void LoadMetadataIfReady();
100 99
101 // Performs reconciliation between the locally provided device info and the 100 // Performs reconciliation between the locally provided device info and the
102 // stored device info data. If the sets of data differ, then we consider this 101 // stored device info data. If the sets of data differ, then we consider this
103 // a local change and we send it to the processor. 102 // a local change and we send it to the processor.
104 void ReconcileLocalAndStored(); 103 void ReconcileLocalAndStored();
105 104
106 // Stores the updated version of the local copy of device info in durable 105 // Stores the updated version of the local copy of device info in durable
107 // storage, in memory, and informs sync of the change. Should not be called 106 // storage, in memory, and informs sync of the change. Should not be called
108 // before the provider and processor have initialized. 107 // before the provider and processor have initialized.
109 void SendLocalData(); 108 void SendLocalData();
110 109
111 // Persists the changes in the given aggregators and notifies observers if 110 // Persists the changes in the given aggregators and notifies observers if
112 // indicated to do as such. 111 // indicated to do as such.
113 void CommitAndNotify(std::unique_ptr<ModelTypeStore::WriteBatch> batch, 112 void CommitAndNotify(std::unique_ptr<ModelTypeStore::WriteBatch> batch,
114 bool should_notify); 113 bool should_notify);
115 114
116 // Counts the number of active devices relative to |now|. The activeness of a 115 // Counts the number of active devices relative to |now|. The activeness of a
117 // device depends on the amount of time since it was updated, which means 116 // device depends on the amount of time since it was updated, which means
118 // comparing it against the current time. |now| is passed into this method to 117 // comparing it against the current time. |now| is passed into this method to
119 // allow unit tests to control expected results. 118 // allow unit tests to control expected results.
120 int CountActiveDevices(const base::Time now) const; 119 int CountActiveDevices(const base::Time now) const;
121 120
122 // Report an error starting up to sync if it tries to connect to this
123 // datatype, since these errors prevent us from knowing if sync is enabled.
124 void ReportStartupErrorToSync(const std::string& msg);
125
126 // |local_device_info_provider_| isn't owned. 121 // |local_device_info_provider_| isn't owned.
127 const LocalDeviceInfoProvider* const local_device_info_provider_; 122 const LocalDeviceInfoProvider* const local_device_info_provider_;
128 123
129 ClientIdToSpecifics all_data_; 124 ClientIdToSpecifics all_data_;
130 125
131 // Registered observers, not owned. 126 // Registered observers, not owned.
132 base::ObserverList<Observer, true> observers_; 127 base::ObserverList<Observer, true> observers_;
133 128
134 // Used to listen for provider initialization. If the provider is already 129 // Used to listen for provider initialization. If the provider is already
135 // initialized during our constructor then the subscription is never used. 130 // initialized during our constructor then the subscription is never used.
136 std::unique_ptr<LocalDeviceInfoProvider::Subscription> subscription_; 131 std::unique_ptr<LocalDeviceInfoProvider::Subscription> subscription_;
137 132
138 // In charge of actually persiting changes to disk, or loading previous data. 133 // In charge of actually persiting changes to disk, or loading previous data.
139 std::unique_ptr<ModelTypeStore> store_; 134 std::unique_ptr<ModelTypeStore> store_;
140 135
141 // If |local_device_info_provider_| has initialized. 136 // If |local_device_info_provider_| has initialized.
142 bool has_provider_initialized_ = false; 137 bool has_provider_initialized_ = false;
143 // If data has been loaded from the store. 138 // If data has been loaded from the store.
144 bool has_data_loaded_ = false; 139 bool has_data_loaded_ = false;
145 140
146 // Used to update our local device info once every pulse interval. 141 // Used to update our local device info once every pulse interval.
147 base::OneShotTimer pulse_timer_; 142 base::OneShotTimer pulse_timer_;
148 143
149 DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncBridge); 144 DISALLOW_COPY_AND_ASSIGN(DeviceInfoSyncBridge);
150 }; 145 };
151 146
152 } // namespace syncer 147 } // namespace syncer
153 148
154 #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_BRIDGE_H_ 149 #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_SYNC_BRIDGE_H_
OLDNEW
« no previous file with comments | « components/sync/BUILD.gn ('k') | components/sync/device_info/device_info_sync_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698