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_CHANGE_PROCESSOR_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_CHANGE_PROCESSOR_H_ |
6 #define COMPONENTS_SYNC_DRIVER_CHANGE_PROCESSOR_H_ | 6 #define COMPONENTS_SYNC_DRIVER_CHANGE_PROCESSOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "components/sync/api/data_type_error_handler.h" | 13 #include "components/sync/api/data_type_error_handler.h" |
14 #include "components/sync/core/base_transaction.h" | 14 #include "components/sync/core/base_transaction.h" |
15 #include "components/sync/core/change_record.h" | 15 #include "components/sync/core/change_record.h" |
16 #include "components/sync/core/user_share.h" | 16 #include "components/sync/core/user_share.h" |
17 | 17 |
18 namespace syncer { | 18 namespace syncer { |
19 class UnrecoverableErrorHandler; | |
20 } // namespace syncer | |
21 | |
22 namespace sync_driver { | |
23 | 19 |
24 class ModelAssociator; | 20 class ModelAssociator; |
| 21 class UnrecoverableErrorHandler; |
25 | 22 |
26 // An interface used to apply changes from the sync model to the browser's | 23 // An interface used to apply changes from the sync model to the browser's |
27 // native model. This does not currently distinguish between model data types. | 24 // native model. This does not currently distinguish between model data types. |
28 class ChangeProcessor { | 25 class ChangeProcessor { |
29 public: | 26 public: |
30 explicit ChangeProcessor( | 27 explicit ChangeProcessor(std::unique_ptr<DataTypeErrorHandler> error_handler); |
31 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler); | |
32 virtual ~ChangeProcessor(); | 28 virtual ~ChangeProcessor(); |
33 | 29 |
34 // Call when the processor should accept changes from either provided model | 30 // Call when the processor should accept changes from either provided model |
35 // and apply them to the other. Both the native model and sync_api are | 31 // and apply them to the other. Both the native model and sync_api are |
36 // expected to be initialized and loaded. You must have set a valid | 32 // expected to be initialized and loaded. You must have set a valid |
37 // ModelAssociator and UnrecoverableErrorHandler before using this method, and | 33 // ModelAssociator and UnrecoverableErrorHandler before using this method, and |
38 // the two models should be associated w.r.t the ModelAssociator provided. | 34 // the two models should be associated w.r.t the ModelAssociator provided. |
39 void Start(syncer::UserShare* share_handle); | 35 void Start(UserShare* share_handle); |
40 | 36 |
41 // Changes have been applied to the backend model and are ready to be | 37 // Changes have been applied to the backend model and are ready to be |
42 // applied to the frontend model. | 38 // applied to the frontend model. |
43 virtual void ApplyChangesFromSyncModel( | 39 virtual void ApplyChangesFromSyncModel( |
44 const syncer::BaseTransaction* trans, | 40 const BaseTransaction* trans, |
45 int64_t model_version, | 41 int64_t model_version, |
46 const syncer::ImmutableChangeRecordList& changes) = 0; | 42 const ImmutableChangeRecordList& changes) = 0; |
47 | 43 |
48 // The changes found in ApplyChangesFromSyncModel may be too slow to be | 44 // The changes found in ApplyChangesFromSyncModel may be too slow to be |
49 // performed while holding a [Read/Write]Transaction lock or may interact | 45 // performed while holding a [Read/Write]Transaction lock or may interact |
50 // with another thread, which might itself be waiting on the transaction lock, | 46 // with another thread, which might itself be waiting on the transaction lock, |
51 // putting us at risk of deadlock. | 47 // putting us at risk of deadlock. |
52 // This function is called once the transactional lock is released and it is | 48 // This function is called once the transactional lock is released and it is |
53 // safe to perform inter-thread or slow I/O operations. Note that not all | 49 // safe to perform inter-thread or slow I/O operations. Note that not all |
54 // datatypes need this, so we provide an empty default version. | 50 // datatypes need this, so we provide an empty default version. |
55 virtual void CommitChangesFromSyncModel(); | 51 virtual void CommitChangesFromSyncModel(); |
56 | 52 |
57 protected: | 53 protected: |
58 // These methods are invoked by Start() and Stop() to do | 54 // These methods are invoked by Start() and Stop() to do |
59 // implementation-specific work. | 55 // implementation-specific work. |
60 virtual void StartImpl() = 0; | 56 virtual void StartImpl() = 0; |
61 | 57 |
62 syncer::DataTypeErrorHandler* error_handler() const; | 58 DataTypeErrorHandler* error_handler() const; |
63 virtual syncer::UserShare* share_handle() const; | 59 virtual UserShare* share_handle() const; |
64 | 60 |
65 private: | 61 private: |
66 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler_; | 62 std::unique_ptr<DataTypeErrorHandler> error_handler_; |
67 | 63 |
68 // The sync model we are processing changes from. | 64 // The sync model we are processing changes from. |
69 syncer::UserShare* share_handle_; | 65 UserShare* share_handle_; |
70 | 66 |
71 DISALLOW_COPY_AND_ASSIGN(ChangeProcessor); | 67 DISALLOW_COPY_AND_ASSIGN(ChangeProcessor); |
72 }; | 68 }; |
73 | 69 |
74 } // namespace sync_driver | 70 } // namespace syncer |
75 | 71 |
76 #endif // COMPONENTS_SYNC_DRIVER_CHANGE_PROCESSOR_H_ | 72 #endif // COMPONENTS_SYNC_DRIVER_CHANGE_PROCESSOR_H_ |
OLD | NEW |