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

Side by Side Diff: components/sync/driver/generic_change_processor.h

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_GENERIC_CHANGE_PROCESSOR_H_ 5 #ifndef COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_
6 #define COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_ 6 #define COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/threading/non_thread_safe.h" 17 #include "base/threading/non_thread_safe.h"
18 #include "components/sync/api/attachments/attachment_store.h" 18 #include "components/sync/api/attachments/attachment_store.h"
19 #include "components/sync/api/data_type_error_handler.h" 19 #include "components/sync/api/data_type_error_handler.h"
20 #include "components/sync/api/sync_change_processor.h" 20 #include "components/sync/api/sync_change_processor.h"
21 #include "components/sync/api/sync_merge_result.h" 21 #include "components/sync/api/sync_merge_result.h"
22 #include "components/sync/core/attachments/attachment_service.h" 22 #include "components/sync/core/attachments/attachment_service.h"
23 #include "components/sync/core/attachments/attachment_service_proxy.h" 23 #include "components/sync/core/attachments/attachment_service_proxy.h"
24 #include "components/sync/driver/change_processor.h" 24 #include "components/sync/driver/change_processor.h"
25 25
26 namespace syncer { 26 namespace syncer {
27
28 class SyncApiComponentFactory;
29 class SyncClient;
30 class SyncData; 27 class SyncData;
31 class SyncableService; 28 class SyncableService;
32 class WriteNode; 29 class WriteNode;
33 class WriteTransaction; 30 class WriteTransaction;
34 31
32 typedef std::vector<syncer::SyncData> SyncDataList;
33
35 namespace syncable { 34 namespace syncable {
36 class Entry; 35 class Entry;
37 } // namespace syncable 36 } // namespace syncable
37 } // namespace syncer
38 38
39 typedef std::vector<SyncData> SyncDataList; 39 namespace sync_driver {
40
41 class SyncApiComponentFactory;
42 class SyncClient;
40 43
41 // Datatype agnostic change processor. One instance of GenericChangeProcessor 44 // Datatype agnostic change processor. One instance of GenericChangeProcessor
42 // is created for each datatype and lives on the datatype's thread. It then 45 // is created for each datatype and lives on the datatype's thread. It then
43 // handles all interaction with the sync api, both translating pushes from the 46 // handles all interaction with the sync api, both translating pushes from the
44 // local service into transactions and receiving changes from the sync model, 47 // local service into transactions and receiving changes from the sync model,
45 // which then get converted into SyncChange's and sent to the local service. 48 // which then get converted into SyncChange's and sent to the local service.
46 // 49 //
47 // As a rule, the GenericChangeProcessor is not thread safe, and should only 50 // As a rule, the GenericChangeProcessor is not thread safe, and should only
48 // be used on the same thread in which it was created. 51 // be used on the same thread in which it was created.
49 class GenericChangeProcessor : public ChangeProcessor, 52 class GenericChangeProcessor : public ChangeProcessor,
50 public SyncChangeProcessor, 53 public syncer::SyncChangeProcessor,
51 public AttachmentService::Delegate, 54 public syncer::AttachmentService::Delegate,
52 public base::NonThreadSafe { 55 public base::NonThreadSafe {
53 public: 56 public:
54 // Create a change processor for |type| and connect it to the syncer. 57 // Create a change processor for |type| and connect it to the syncer.
55 // |attachment_store| can be NULL which means that datatype will not use sync 58 // |attachment_store| can be NULL which means that datatype will not use sync
56 // attachments. 59 // attachments.
57 GenericChangeProcessor( 60 GenericChangeProcessor(
58 ModelType type, 61 syncer::ModelType type,
59 std::unique_ptr<DataTypeErrorHandler> error_handler, 62 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler,
60 const base::WeakPtr<SyncableService>& local_service, 63 const base::WeakPtr<syncer::SyncableService>& local_service,
61 const base::WeakPtr<SyncMergeResult>& merge_result, 64 const base::WeakPtr<syncer::SyncMergeResult>& merge_result,
62 UserShare* user_share, 65 syncer::UserShare* user_share,
63 SyncClient* sync_client, 66 SyncClient* sync_client,
64 std::unique_ptr<AttachmentStoreForSync> attachment_store); 67 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store);
65 ~GenericChangeProcessor() override; 68 ~GenericChangeProcessor() override;
66 69
67 // ChangeProcessor interface. 70 // ChangeProcessor interface.
68 // Build and store a list of all changes into |syncer_changes_|. 71 // Build and store a list of all changes into |syncer_changes_|.
69 void ApplyChangesFromSyncModel( 72 void ApplyChangesFromSyncModel(
70 const BaseTransaction* trans, 73 const syncer::BaseTransaction* trans,
71 int64_t version, 74 int64_t version,
72 const ImmutableChangeRecordList& changes) override; 75 const syncer::ImmutableChangeRecordList& changes) override;
73 // Passes |syncer_changes_|, built in ApplyChangesFromSyncModel, onto 76 // Passes |syncer_changes_|, built in ApplyChangesFromSyncModel, onto
74 // |local_service_| by way of its ProcessSyncChanges method. 77 // |local_service_| by way of its ProcessSyncChanges method.
75 void CommitChangesFromSyncModel() override; 78 void CommitChangesFromSyncModel() override;
76 79
77 // SyncChangeProcessor implementation. 80 // syncer::SyncChangeProcessor implementation.
78 SyncError ProcessSyncChanges(const tracked_objects::Location& from_here, 81 syncer::SyncError ProcessSyncChanges(
79 const SyncChangeList& change_list) override; 82 const tracked_objects::Location& from_here,
80 SyncDataList GetAllSyncData(ModelType type) const override; 83 const syncer::SyncChangeList& change_list) override;
81 SyncError UpdateDataTypeContext( 84 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
82 ModelType type, 85 syncer::SyncError UpdateDataTypeContext(
83 SyncChangeProcessor::ContextRefreshStatus refresh_status, 86 syncer::ModelType type,
87 syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status,
84 const std::string& context) override; 88 const std::string& context) override;
85 void AddLocalChangeObserver(LocalChangeObserver* observer) override; 89 void AddLocalChangeObserver(syncer::LocalChangeObserver* observer) override;
86 void RemoveLocalChangeObserver(LocalChangeObserver* observer) override; 90 void RemoveLocalChangeObserver(
91 syncer::LocalChangeObserver* observer) override;
87 92
88 // AttachmentService::Delegate implementation. 93 // syncer::AttachmentService::Delegate implementation.
89 void OnAttachmentUploaded(const AttachmentId& attachment_id) override; 94 void OnAttachmentUploaded(const syncer::AttachmentId& attachment_id) override;
90 95
91 // Similar to above, but returns a SyncError for use by direct clients 96 // Similar to above, but returns a SyncError for use by direct clients
92 // of GenericChangeProcessor that may need more error visibility. 97 // of GenericChangeProcessor that may need more error visibility.
93 virtual SyncError GetAllSyncDataReturnError(SyncDataList* data) const; 98 virtual syncer::SyncError GetAllSyncDataReturnError(
99 syncer::SyncDataList* data) const;
94 100
95 // If a datatype context associated with this GenericChangeProcessor's type 101 // If a datatype context associated with this GenericChangeProcessor's type
96 // exists, fills |context| and returns true. Otheriwse, if there has not been 102 // exists, fills |context| and returns true. Otheriwse, if there has not been
97 // a context set, returns false. 103 // a context set, returns false.
98 virtual bool GetDataTypeContext(std::string* context) const; 104 virtual bool GetDataTypeContext(std::string* context) const;
99 105
100 // Returns the number of items for this type. 106 // Returns the number of items for this type.
101 virtual int GetSyncCount(); 107 virtual int GetSyncCount();
102 108
103 // Generic versions of AssociatorInterface methods. Called by 109 // Generic versions of AssociatorInterface methods. Called by
104 // SyncableServiceAdapter or the DataTypeController. 110 // syncer::SyncableServiceAdapter or the DataTypeController.
105 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); 111 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes);
106 virtual bool CryptoReadyIfNecessary(); 112 virtual bool CryptoReadyIfNecessary();
107 113
108 // Gets AttachmentService proxy for datatype. 114 // Gets AttachmentService proxy for datatype.
109 std::unique_ptr<AttachmentService> GetAttachmentService() const; 115 std::unique_ptr<syncer::AttachmentService> GetAttachmentService() const;
110 116
111 protected: 117 protected:
112 // ChangeProcessor interface. 118 // ChangeProcessor interface.
113 void StartImpl() override; // Does nothing. 119 void StartImpl() override; // Does nothing.
114 UserShare* share_handle() const override; 120 syncer::UserShare* share_handle() const override;
115 121
116 private: 122 private:
117 SyncError AttemptDelete(const SyncChange& change, 123 syncer::SyncError AttemptDelete(const syncer::SyncChange& change,
118 ModelType type, 124 syncer::ModelType type,
119 const std::string& type_str, 125 const std::string& type_str,
120 WriteNode* node, 126 syncer::WriteNode* node,
121 DataTypeErrorHandler* error_handler); 127 syncer::DataTypeErrorHandler* error_handler);
122 // Logically part of ProcessSyncChanges. 128 // Logically part of ProcessSyncChanges.
123 // 129 //
124 // |new_attachments| is an output parameter containing newly added attachments 130 // |new_attachments| is an output parameter containing newly added attachments
125 // that need to be stored. This method will append to it. 131 // that need to be stored. This method will append to it.
126 SyncError HandleActionAdd(const SyncChange& change, 132 syncer::SyncError HandleActionAdd(const syncer::SyncChange& change,
127 const std::string& type_str, 133 const std::string& type_str,
128 const WriteTransaction& trans, 134 const syncer::WriteTransaction& trans,
129 WriteNode* sync_node, 135 syncer::WriteNode* sync_node,
130 AttachmentIdSet* new_attachments); 136 syncer::AttachmentIdSet* new_attachments);
131 137
132 // Logically part of ProcessSyncChanges. 138 // Logically part of ProcessSyncChanges.
133 // 139 //
134 // |new_attachments| is an output parameter containing newly added attachments 140 // |new_attachments| is an output parameter containing newly added attachments
135 // that need to be stored. This method will append to it. 141 // that need to be stored. This method will append to it.
136 SyncError HandleActionUpdate(const SyncChange& change, 142 syncer::SyncError HandleActionUpdate(
137 const std::string& type_str, 143 const syncer::SyncChange& change,
138 const WriteTransaction& trans, 144 const std::string& type_str,
139 WriteNode* sync_node, 145 const syncer::WriteTransaction& trans,
140 AttachmentIdSet* new_attachments); 146 syncer::WriteNode* sync_node,
147 syncer::AttachmentIdSet* new_attachments);
141 148
142 // Begin uploading attachments that have not yet been uploaded to the sync 149 // Begin uploading attachments that have not yet been uploaded to the sync
143 // server. 150 // server.
144 void UploadAllAttachmentsNotOnServer(); 151 void UploadAllAttachmentsNotOnServer();
145 152
146 // Notify every registered local change observer that |change| is about to be 153 // Notify every registered local change observer that |change| is about to be
147 // applied to |current_entry|. 154 // applied to |current_entry|.
148 void NotifyLocalChangeObservers(const syncable::Entry* current_entry, 155 void NotifyLocalChangeObservers(const syncer::syncable::Entry* current_entry,
149 const SyncChange& change); 156 const syncer::SyncChange& change);
150 157
151 const ModelType type_; 158 const syncer::ModelType type_;
152 159
153 // The SyncableService this change processor will forward changes on to. 160 // The SyncableService this change processor will forward changes on to.
154 const base::WeakPtr<SyncableService> local_service_; 161 const base::WeakPtr<syncer::SyncableService> local_service_;
155 162
156 // A SyncMergeResult used to track the changes made during association. The 163 // A SyncMergeResult used to track the changes made during association. The
157 // owner will invalidate the weak pointer when association is complete. While 164 // owner will invalidate the weak pointer when association is complete. While
158 // the pointer is valid though, we increment it with any changes received 165 // the pointer is valid though, we increment it with any changes received
159 // via ProcessSyncChanges. 166 // via ProcessSyncChanges.
160 const base::WeakPtr<SyncMergeResult> merge_result_; 167 const base::WeakPtr<syncer::SyncMergeResult> merge_result_;
161 168
162 // The current list of changes received from the syncer. We buffer because 169 // The current list of changes received from the syncer. We buffer because
163 // we must ensure no syncapi transaction is held when we pass it on to 170 // we must ensure no syncapi transaction is held when we pass it on to
164 // |local_service_|. 171 // |local_service_|.
165 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. 172 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel.
166 SyncChangeList syncer_changes_; 173 syncer::SyncChangeList syncer_changes_;
167 174
168 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to 175 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to
169 // be able to access the sync model before the change processor begins 176 // be able to access the sync model before the change processor begins
170 // listening to changes (the local_service_ will be interacting with us 177 // listening to changes (the local_service_ will be interacting with us
171 // when it starts up). As such we can't wait until Start(_) has been called, 178 // when it starts up). As such we can't wait until Start(_) has been called,
172 // and have to keep a local pointer to the user_share. 179 // and have to keep a local pointer to the user_share.
173 UserShare* const share_handle_; 180 syncer::UserShare* const share_handle_;
174 181
175 // AttachmentService for datatype. Can be NULL if datatype doesn't use 182 // AttachmentService for datatype. Can be NULL if datatype doesn't use
176 // attachments. 183 // attachments.
177 std::unique_ptr<AttachmentService> attachment_service_; 184 std::unique_ptr<syncer::AttachmentService> attachment_service_;
178 185
179 // List of observers that want to be notified of local changes being written. 186 // List of observers that want to be notified of local changes being written.
180 base::ObserverList<LocalChangeObserver> local_change_observers_; 187 base::ObserverList<syncer::LocalChangeObserver> local_change_observers_;
181 188
182 // Must be destroyed before attachment_service_ to ensure WeakPtrs are 189 // Must be destroyed before attachment_service_ to ensure WeakPtrs are
183 // invalidated before attachment_service_ is destroyed. 190 // invalidated before attachment_service_ is destroyed.
184 // Can be NULL if attachment_service_ is NULL; 191 // Can be NULL if attachment_service_ is NULL;
185 std::unique_ptr<base::WeakPtrFactory<AttachmentService>> 192 std::unique_ptr<base::WeakPtrFactory<syncer::AttachmentService>>
186 attachment_service_weak_ptr_factory_; 193 attachment_service_weak_ptr_factory_;
187 AttachmentServiceProxy attachment_service_proxy_; 194 syncer::AttachmentServiceProxy attachment_service_proxy_;
188 base::WeakPtrFactory<GenericChangeProcessor> weak_ptr_factory_; 195 base::WeakPtrFactory<GenericChangeProcessor> weak_ptr_factory_;
189 196
190 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor); 197 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor);
191 }; 198 };
192 199
193 } // namespace syncer 200 } // namespace sync_driver
194 201
195 #endif // COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_ 202 #endif // COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_
OLDNEW
« no previous file with comments | « components/sync/driver/frontend_data_type_controller_unittest.cc ('k') | components/sync/driver/generic_change_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698