OLD | NEW |
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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
13 #include "components/sync_driver/change_processor.h" | 13 #include "components/sync_driver/change_processor.h" |
14 #include "components/sync_driver/data_type_controller.h" | 14 #include "components/sync_driver/data_type_controller.h" |
15 #include "components/sync_driver/data_type_error_handler.h" | 15 #include "components/sync_driver/data_type_error_handler.h" |
16 #include "sync/api/attachments/attachment_store.h" | |
17 #include "sync/api/sync_change_processor.h" | 16 #include "sync/api/sync_change_processor.h" |
18 #include "sync/api/sync_merge_result.h" | 17 #include "sync/api/sync_merge_result.h" |
19 #include "sync/internal_api/public/attachments/attachment_service.h" | 18 #include "sync/internal_api/public/attachments/attachment_service.h" |
20 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" | 19 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" |
21 | 20 |
22 namespace syncer { | 21 namespace syncer { |
23 class SyncData; | 22 class SyncData; |
24 class SyncableService; | 23 class SyncableService; |
25 class WriteNode; | 24 class WriteNode; |
26 class WriteTransaction; | 25 class WriteTransaction; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // | 119 // |
121 // |new_attachments| is an output parameter containing newly added attachments | 120 // |new_attachments| is an output parameter containing newly added attachments |
122 // that need to be stored. This method will append to it. | 121 // that need to be stored. This method will append to it. |
123 syncer::SyncError HandleActionUpdate(const syncer::SyncChange& change, | 122 syncer::SyncError HandleActionUpdate(const syncer::SyncChange& change, |
124 const std::string& type_str, | 123 const std::string& type_str, |
125 const syncer::ModelType& type, | 124 const syncer::ModelType& type, |
126 const syncer::WriteTransaction& trans, | 125 const syncer::WriteTransaction& trans, |
127 syncer::WriteNode* sync_node, | 126 syncer::WriteNode* sync_node, |
128 syncer::AttachmentList* new_attachments); | 127 syncer::AttachmentList* new_attachments); |
129 | 128 |
130 // Store |attachments| locally then upload them to the sync server. | |
131 // | |
132 // Store and uploading are asynchronous operations. |WriteAttachmentsDone| | |
133 // will be invoked once the attachments have been stored on the local device. | |
134 void StoreAndUploadAttachments(const syncer::AttachmentList& attachments); | |
135 | |
136 // Invoked once attachments have been stored locally. | |
137 // | |
138 // See also AttachmentStore::WriteCallback. | |
139 void WriteAttachmentsDone(const syncer::AttachmentList& attachments, | |
140 const syncer::AttachmentStore::Result& result); | |
141 | |
142 // The SyncableService this change processor will forward changes on to. | 129 // The SyncableService this change processor will forward changes on to. |
143 const base::WeakPtr<syncer::SyncableService> local_service_; | 130 const base::WeakPtr<syncer::SyncableService> local_service_; |
144 | 131 |
145 // A SyncMergeResult used to track the changes made during association. The | 132 // A SyncMergeResult used to track the changes made during association. The |
146 // owner will invalidate the weak pointer when association is complete. While | 133 // owner will invalidate the weak pointer when association is complete. While |
147 // the pointer is valid though, we increment it with any changes received | 134 // the pointer is valid though, we increment it with any changes received |
148 // via ProcessSyncChanges. | 135 // via ProcessSyncChanges. |
149 const base::WeakPtr<syncer::SyncMergeResult> merge_result_; | 136 const base::WeakPtr<syncer::SyncMergeResult> merge_result_; |
150 | 137 |
151 // The current list of changes received from the syncer. We buffer because | 138 // The current list of changes received from the syncer. We buffer because |
152 // we must ensure no syncapi transaction is held when we pass it on to | 139 // we must ensure no syncapi transaction is held when we pass it on to |
153 // |local_service_|. | 140 // |local_service_|. |
154 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. | 141 // Set in ApplyChangesFromSyncModel, consumed in CommitChangesFromSyncModel. |
155 syncer::SyncChangeList syncer_changes_; | 142 syncer::SyncChangeList syncer_changes_; |
156 | 143 |
157 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to | 144 // Our handle to the sync model. Unlike normal ChangeProcessors, we need to |
158 // be able to access the sync model before the change processor begins | 145 // be able to access the sync model before the change processor begins |
159 // listening to changes (the local_service_ will be interacting with us | 146 // listening to changes (the local_service_ will be interacting with us |
160 // when it starts up). As such we can't wait until Start(_) has been called, | 147 // when it starts up). As such we can't wait until Start(_) has been called, |
161 // and have to keep a local pointer to the user_share. | 148 // and have to keep a local pointer to the user_share. |
162 syncer::UserShare* const share_handle_; | 149 syncer::UserShare* const share_handle_; |
163 | 150 |
164 scoped_ptr<syncer::AttachmentService> attachment_service_; | 151 scoped_ptr<syncer::AttachmentService> attachment_service_; |
165 // Must be destroyed before attachment_service_ to ensure WeakPtrs are | 152 // Must be destroyed before attachment_service_ to ensure WeakPtrs are |
166 // invalidated before attachment_service_ is destroyed. | 153 // invalidated before attachment_service_ is destroyed. |
167 base::WeakPtrFactory<syncer::AttachmentService> | 154 base::WeakPtrFactory<syncer::AttachmentService> |
168 attachment_service_weak_ptr_factory_; | 155 attachment_service_weak_ptr_factory_; |
169 syncer::AttachmentServiceProxy attachment_service_proxy_; | 156 syncer::AttachmentServiceProxy attachment_service_proxy_; |
170 | 157 |
171 base::WeakPtrFactory<GenericChangeProcessor> weak_ptr_factory_; | |
172 | |
173 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor); | 158 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor); |
174 }; | 159 }; |
175 | 160 |
176 } // namespace sync_driver | 161 } // namespace sync_driver |
177 | 162 |
178 #endif // COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_ | 163 #endif // COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_ |
OLD | NEW |