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