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_NON_BLOCKING_DATA_TYPE_CONTROLLER_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_CONTROLLER_H_ |
6 #define COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_CONTROLLER_H_ | 6 #define COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "components/sync/base/model_type.h" | 13 #include "components/sync/base/model_type.h" |
14 #include "components/sync/driver/data_type_controller.h" | 14 #include "components/sync/driver/data_type_controller.h" |
15 #include "components/sync/driver/sync_prefs.h" | 15 #include "components/sync/driver/sync_prefs.h" |
16 | 16 |
17 namespace syncer { | 17 namespace sync_driver { |
| 18 class SyncClient; |
| 19 } |
18 | 20 |
19 class SyncClient; | 21 namespace syncer_v2 { |
20 struct ActivationContext; | 22 struct ActivationContext; |
| 23 } |
| 24 |
| 25 namespace sync_driver_v2 { |
21 | 26 |
22 // Base class for DataType controllers for Unified Sync and Storage datatypes. | 27 // Base class for DataType controllers for Unified Sync and Storage datatypes. |
23 // Derived types must implement the following methods: | 28 // Derived types must implement the following methods: |
24 // - RunOnModelThread | 29 // - RunOnModelThread |
25 // - RunOnUIThread | 30 // - RunOnUIThread |
26 class NonBlockingDataTypeController : public DataTypeController { | 31 class NonBlockingDataTypeController : public sync_driver::DataTypeController { |
27 public: | 32 public: |
28 // |dump_stack| is called when an unrecoverable error occurs. | 33 // |dump_stack| is called when an unrecoverable error occurs. |
29 NonBlockingDataTypeController(ModelType type, | 34 NonBlockingDataTypeController(syncer::ModelType type, |
30 const base::Closure& dump_stack, | 35 const base::Closure& dump_stack, |
31 SyncClient* sync_client); | 36 sync_driver::SyncClient* sync_client); |
32 ~NonBlockingDataTypeController() override; | 37 ~NonBlockingDataTypeController() override; |
33 | 38 |
34 // DataTypeController interface. | 39 // DataTypeController interface. |
35 bool ShouldLoadModelBeforeConfigure() const override; | 40 bool ShouldLoadModelBeforeConfigure() const override; |
36 void LoadModels(const ModelLoadCallback& model_load_callback) override; | 41 void LoadModels(const ModelLoadCallback& model_load_callback) override; |
37 void GetAllNodes(const AllNodesCallback& callback) override; | 42 void GetAllNodes(const AllNodesCallback& callback) override; |
38 | 43 |
39 // Registers non-blocking data type with sync backend. In the process the | 44 // Registers non-blocking data type with sync backend. In the process the |
40 // activation context is passed to ModelTypeRegistry, where ModelTypeWorker | 45 // activation context is passed to ModelTypeRegistry, where ModelTypeWorker |
41 // gets created and connected with ModelTypeProcessor. | 46 // gets created and connected with ModelTypeProcessor. |
42 void RegisterWithBackend(BackendDataTypeConfigurer* configurer) override; | 47 void RegisterWithBackend( |
| 48 sync_driver::BackendDataTypeConfigurer* configurer) override; |
43 void StartAssociating(const StartCallback& start_callback) override; | 49 void StartAssociating(const StartCallback& start_callback) override; |
44 void ActivateDataType(BackendDataTypeConfigurer* configurer) override; | 50 void ActivateDataType( |
45 void DeactivateDataType(BackendDataTypeConfigurer* configurer) override; | 51 sync_driver::BackendDataTypeConfigurer* configurer) override; |
| 52 void DeactivateDataType( |
| 53 sync_driver::BackendDataTypeConfigurer* configurer) override; |
46 void Stop() override; | 54 void Stop() override; |
47 std::string name() const override; | 55 std::string name() const override; |
48 State state() const override; | 56 State state() const override; |
49 | 57 |
50 protected: | 58 protected: |
51 // Posts the given task to the model thread, i.e. the thread the | 59 // Posts the given task to the model thread, i.e. the thread the |
52 // datatype lives on. Return value: True if task posted successfully, | 60 // datatype lives on. Return value: True if task posted successfully, |
53 // false otherwise. | 61 // false otherwise. |
54 virtual bool RunOnModelThread(const tracked_objects::Location& from_here, | 62 virtual bool RunOnModelThread(const tracked_objects::Location& from_here, |
55 const base::Closure& task) = 0; | 63 const base::Closure& task) = 0; |
56 | 64 |
57 std::unique_ptr<DataTypeErrorHandler> CreateErrorHandler() override; | 65 std::unique_ptr<syncer::DataTypeErrorHandler> CreateErrorHandler() override; |
58 | 66 |
59 private: | 67 private: |
60 void RecordStartFailure(ConfigureResult result) const; | 68 void RecordStartFailure(ConfigureResult result) const; |
61 void ReportLoadModelError(const SyncError& error); | 69 void ReportLoadModelError(const syncer::SyncError& error); |
62 | 70 |
63 // If the DataType controller is waiting for models to load, once the models | 71 // If the DataType controller is waiting for models to load, once the models |
64 // are loaded this function should be called to let the base class | 72 // are loaded this function should be called to let the base class |
65 // implementation know that it is safe to continue with the activation. | 73 // implementation know that it is safe to continue with the activation. |
66 // The error indicates whether the loading completed successfully. | 74 // The error indicates whether the loading completed successfully. |
67 void LoadModelsDone(ConfigureResult result, const SyncError& error); | 75 void LoadModelsDone(ConfigureResult result, const syncer::SyncError& error); |
68 | 76 |
69 // The function will do the real work when OnProcessorStarted got called. This | 77 // The function will do the real work when OnProcessorStarted got called. This |
70 // is called on the UI thread. | 78 // is called on the UI thread. |
71 void OnProcessorStarted( | 79 void OnProcessorStarted( |
72 SyncError error, | 80 syncer::SyncError error, |
73 std::unique_ptr<ActivationContext> activation_context); | 81 std::unique_ptr<syncer_v2::ActivationContext> activation_context); |
74 | 82 |
75 // Sync client | 83 // Sync client |
76 SyncClient* const sync_client_; | 84 sync_driver::SyncClient* const sync_client_; |
77 | 85 |
78 // Sync prefs. Used for determinig if DisableSync should be called during call | 86 // Sync prefs. Used for determinig if DisableSync should be called during call |
79 // to Stop(). | 87 // to Stop(). |
80 SyncPrefs sync_prefs_; | 88 sync_driver::SyncPrefs sync_prefs_; |
81 | 89 |
82 // State of this datatype controller. | 90 // State of this datatype controller. |
83 State state_; | 91 State state_; |
84 | 92 |
85 // Callbacks for use when starting the datatype. | 93 // Callbacks for use when starting the datatype. |
86 ModelLoadCallback model_load_callback_; | 94 ModelLoadCallback model_load_callback_; |
87 | 95 |
88 // Controller receives |activation_context_| from SharedModelTypeProcessor | 96 // Controller receives |activation_context_| from SharedModelTypeProcessor |
89 // callback and must temporarily own it until ActivateDataType is called. | 97 // callback and must temporarily own it until ActivateDataType is called. |
90 std::unique_ptr<ActivationContext> activation_context_; | 98 std::unique_ptr<syncer_v2::ActivationContext> activation_context_; |
91 | 99 |
92 // This is a hack to prevent reconfigurations from crashing, because USS | 100 // This is a hack to prevent reconfigurations from crashing, because USS |
93 // activation is not idempotent. RegisterWithBackend only needs to actually do | 101 // activation is not idempotent. RegisterWithBackend only needs to actually do |
94 // something the first time after the type is enabled. | 102 // something the first time after the type is enabled. |
95 // TODO(crbug.com/647505): Remove this once the DTM handles things better. | 103 // TODO(crbug.com/647505): Remove this once the DTM handles things better. |
96 bool activated_ = false; | 104 bool activated_ = false; |
97 | 105 |
98 DISALLOW_COPY_AND_ASSIGN(NonBlockingDataTypeController); | 106 DISALLOW_COPY_AND_ASSIGN(NonBlockingDataTypeController); |
99 }; | 107 }; |
100 | 108 |
101 } // namespace syncer | 109 } // namespace sync_driver_v2 |
102 | 110 |
103 #endif // COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_CONTROLLER_H_ | 111 #endif // COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_CONTROLLER_H_ |
OLD | NEW |