| 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 <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/sequence_checker.h" |
| 18 #include "components/sync/model/attachments/attachment_service.h" | 18 #include "components/sync/model/attachments/attachment_service.h" |
| 19 #include "components/sync/model/attachments/attachment_service_proxy.h" | 19 #include "components/sync/model/attachments/attachment_service_proxy.h" |
| 20 #include "components/sync/model/attachments/attachment_store.h" | 20 #include "components/sync/model/attachments/attachment_store.h" |
| 21 #include "components/sync/model/change_processor.h" | 21 #include "components/sync/model/change_processor.h" |
| 22 #include "components/sync/model/data_type_error_handler.h" | 22 #include "components/sync/model/data_type_error_handler.h" |
| 23 #include "components/sync/model/sync_change_processor.h" | 23 #include "components/sync/model/sync_change_processor.h" |
| 24 #include "components/sync/model/sync_merge_result.h" | 24 #include "components/sync/model/sync_merge_result.h" |
| 25 | 25 |
| 26 namespace syncer { | 26 namespace syncer { |
| 27 | 27 |
| 28 class SyncClient; | 28 class SyncClient; |
| 29 class SyncData; | 29 class SyncData; |
| 30 class SyncableService; | 30 class SyncableService; |
| 31 class WriteNode; | 31 class WriteNode; |
| 32 class WriteTransaction; | 32 class WriteTransaction; |
| 33 | 33 |
| 34 namespace syncable { | 34 namespace syncable { |
| 35 class Entry; | 35 class Entry; |
| 36 } // namespace syncable | 36 } // namespace syncable |
| 37 | 37 |
| 38 typedef std::vector<SyncData> SyncDataList; | 38 typedef std::vector<SyncData> SyncDataList; |
| 39 | 39 |
| 40 // Datatype agnostic change processor. One instance of GenericChangeProcessor | 40 // Datatype agnostic change processor. One instance of GenericChangeProcessor |
| 41 // is created for each datatype and lives on the datatype's thread. It then | 41 // is created for each datatype and lives on the datatype's sequence. It then |
| 42 // handles all interaction with the sync api, both translating pushes from the | 42 // handles all interaction with the sync api, both translating pushes from the |
| 43 // local service into transactions and receiving changes from the sync model, | 43 // local service into transactions and receiving changes from the sync model, |
| 44 // which then get converted into SyncChange's and sent to the local service. | 44 // which then get converted into SyncChange's and sent to the local service. |
| 45 // | 45 // |
| 46 // As a rule, the GenericChangeProcessor is not thread safe, and should only | 46 // As a rule, the GenericChangeProcessor is not thread safe, and should only |
| 47 // be used on the same thread in which it was created. | 47 // be used on the same sequence in which it was created. |
| 48 class GenericChangeProcessor : public ChangeProcessor, | 48 class GenericChangeProcessor : public ChangeProcessor, |
| 49 public SyncChangeProcessor, | 49 public SyncChangeProcessor, |
| 50 public AttachmentService::Delegate, | 50 public AttachmentService::Delegate { |
| 51 public base::NonThreadSafe { | |
| 52 public: | 51 public: |
| 53 // Create a change processor for |type| and connect it to the syncer. | 52 // Create a change processor for |type| and connect it to the syncer. |
| 54 // |attachment_store| can be null which means that datatype will not use sync | 53 // |attachment_store| can be null which means that datatype will not use sync |
| 55 // attachments. | 54 // attachments. |
| 56 GenericChangeProcessor( | 55 GenericChangeProcessor( |
| 57 ModelType type, | 56 ModelType type, |
| 58 std::unique_ptr<DataTypeErrorHandler> error_handler, | 57 std::unique_ptr<DataTypeErrorHandler> error_handler, |
| 59 const base::WeakPtr<SyncableService>& local_service, | 58 const base::WeakPtr<SyncableService>& local_service, |
| 60 const base::WeakPtr<SyncMergeResult>& merge_result, | 59 const base::WeakPtr<SyncMergeResult>& merge_result, |
| 61 UserShare* user_share, | 60 UserShare* user_share, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 139 |
| 141 // Begin uploading attachments that have not yet been uploaded to the sync | 140 // Begin uploading attachments that have not yet been uploaded to the sync |
| 142 // server. | 141 // server. |
| 143 void UploadAllAttachmentsNotOnServer(); | 142 void UploadAllAttachmentsNotOnServer(); |
| 144 | 143 |
| 145 // Notify every registered local change observer that |change| is about to be | 144 // Notify every registered local change observer that |change| is about to be |
| 146 // applied to |current_entry|. | 145 // applied to |current_entry|. |
| 147 void NotifyLocalChangeObservers(const syncable::Entry* current_entry, | 146 void NotifyLocalChangeObservers(const syncable::Entry* current_entry, |
| 148 const SyncChange& change); | 147 const SyncChange& change); |
| 149 | 148 |
| 149 base::SequenceChecker sequence_checker_; |
| 150 |
| 150 const ModelType type_; | 151 const ModelType type_; |
| 151 | 152 |
| 152 // The SyncableService this change processor will forward changes on to. | 153 // The SyncableService this change processor will forward changes on to. |
| 153 const base::WeakPtr<SyncableService> local_service_; | 154 const base::WeakPtr<SyncableService> local_service_; |
| 154 | 155 |
| 155 // A SyncMergeResult used to track the changes made during association. The | 156 // A SyncMergeResult used to track the changes made during association. The |
| 156 // owner will invalidate the weak pointer when association is complete. While | 157 // owner will invalidate the weak pointer when association is complete. While |
| 157 // the pointer is valid though, we increment it with any changes received | 158 // the pointer is valid though, we increment it with any changes received |
| 158 // via ProcessSyncChanges. | 159 // via ProcessSyncChanges. |
| 159 const base::WeakPtr<SyncMergeResult> merge_result_; | 160 const base::WeakPtr<SyncMergeResult> merge_result_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 185 attachment_service_weak_ptr_factory_; | 186 attachment_service_weak_ptr_factory_; |
| 186 AttachmentServiceProxy attachment_service_proxy_; | 187 AttachmentServiceProxy attachment_service_proxy_; |
| 187 base::WeakPtrFactory<GenericChangeProcessor> weak_ptr_factory_; | 188 base::WeakPtrFactory<GenericChangeProcessor> weak_ptr_factory_; |
| 188 | 189 |
| 189 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor); | 190 DISALLOW_COPY_AND_ASSIGN(GenericChangeProcessor); |
| 190 }; | 191 }; |
| 191 | 192 |
| 192 } // namespace syncer | 193 } // namespace syncer |
| 193 | 194 |
| 194 #endif // COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_ | 195 #endif // COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_H_ |
| OLD | NEW |