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