| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FRONTEND_DATA_TYPE_CONTROLLER_H__ | 5 #ifndef COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
| 6 #define COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_H__ | 6 #define COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 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/driver/directory_data_type_controller.h" | 14 #include "components/sync/driver/directory_data_type_controller.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class TimeDelta; | 17 class TimeDelta; |
| 18 } // namespace base | 18 } |
| 19 | 19 |
| 20 namespace syncer { | 20 namespace syncer { |
| 21 class SyncError; |
| 22 } |
| 21 | 23 |
| 24 namespace sync_driver { |
| 22 class AssociatorInterface; | 25 class AssociatorInterface; |
| 23 class ChangeProcessor; | 26 class ChangeProcessor; |
| 24 class SyncClient; | 27 class SyncClient; |
| 25 class SyncError; | 28 } |
| 29 |
| 30 namespace browser_sync { |
| 26 | 31 |
| 27 // Implementation for datatypes that reside on the frontend thread | 32 // Implementation for datatypes that reside on the frontend thread |
| 28 // (UI thread). This is the same thread we perform initialization on, so we | 33 // (UI thread). This is the same thread we perform initialization on, so we |
| 29 // don't have to worry about thread safety. The main start/stop funtionality is | 34 // don't have to worry about thread safety. The main start/stop funtionality is |
| 30 // implemented by default. | 35 // implemented by default. |
| 31 // Derived classes must implement (at least): | 36 // Derived classes must implement (at least): |
| 32 // ModelType type() const | 37 // syncer::ModelType type() const |
| 33 // void CreateSyncComponents(); | 38 // void CreateSyncComponents(); |
| 34 // NOTE: This class is deprecated! New sync datatypes should be using the | 39 // NOTE: This class is deprecated! New sync datatypes should be using the |
| 35 // SyncableService API and the UIDataTypeController instead. | 40 // syncer::SyncableService API and the UIDataTypeController instead. |
| 36 // TODO(zea): Delete this once all types are on the new API. | 41 // TODO(zea): Delete this once all types are on the new API. |
| 37 class FrontendDataTypeController : public DirectoryDataTypeController { | 42 class FrontendDataTypeController |
| 43 : public sync_driver::DirectoryDataTypeController { |
| 38 public: | 44 public: |
| 39 // |dump_stack| is called when an unrecoverable error occurs. | 45 // |dump_stack| is called when an unrecoverable error occurs. |
| 40 FrontendDataTypeController(ModelType type, | 46 FrontendDataTypeController(syncer::ModelType type, |
| 41 const base::Closure& dump_stack, | 47 const base::Closure& dump_stack, |
| 42 SyncClient* sync_client); | 48 sync_driver::SyncClient* sync_client); |
| 43 ~FrontendDataTypeController() override; | 49 ~FrontendDataTypeController() override; |
| 44 | 50 |
| 45 // DataTypeController interface. | 51 // DataTypeController interface. |
| 46 void LoadModels(const ModelLoadCallback& model_load_callback) override; | 52 void LoadModels(const ModelLoadCallback& model_load_callback) override; |
| 47 void StartAssociating(const StartCallback& start_callback) override; | 53 void StartAssociating(const StartCallback& start_callback) override; |
| 48 void Stop() override; | 54 void Stop() override; |
| 49 ModelSafeGroup model_safe_group() const override; | 55 syncer::ModelSafeGroup model_safe_group() const override; |
| 50 std::string name() const override; | 56 std::string name() const override; |
| 51 State state() const override; | 57 State state() const override; |
| 52 | 58 |
| 53 protected: | 59 protected: |
| 54 friend class FrontendDataTypeControllerMock; | 60 friend class FrontendDataTypeControllerMock; |
| 55 | 61 |
| 56 // For testing only. | 62 // For testing only. |
| 57 FrontendDataTypeController(); | 63 FrontendDataTypeController(); |
| 58 | 64 |
| 59 // Kick off any dependent services that need to be running before we can | 65 // Kick off any dependent services that need to be running before we can |
| 60 // associate models. The default implementation is a no-op. | 66 // associate models. The default implementation is a no-op. |
| 61 // Return value: | 67 // Return value: |
| 62 // True - if models are ready and association can proceed. | 68 // True - if models are ready and association can proceed. |
| 63 // False - if models are not ready. Associate() should be called when the | 69 // False - if models are not ready. Associate() should be called when the |
| 64 // models are ready. Refer to Start(_) implementation. | 70 // models are ready. Refer to Start(_) implementation. |
| 65 virtual bool StartModels(); | 71 virtual bool StartModels(); |
| 66 | 72 |
| 67 // Datatype specific creation of sync components. | 73 // Datatype specific creation of sync components. |
| 68 virtual void CreateSyncComponents() = 0; | 74 virtual void CreateSyncComponents() = 0; |
| 69 | 75 |
| 70 // Perform any DataType controller specific state cleanup before stopping | 76 // Perform any DataType controller specific state cleanup before stopping |
| 71 // the datatype controller. The default implementation is a no-op. | 77 // the datatype controller. The default implementation is a no-op. |
| 72 virtual void CleanUpState(); | 78 virtual void CleanUpState(); |
| 73 | 79 |
| 74 // Helper method for cleaning up state and running the start callback. | 80 // Helper method for cleaning up state and running the start callback. |
| 75 virtual void StartDone(ConfigureResult start_result, | 81 virtual void StartDone(ConfigureResult start_result, |
| 76 const SyncMergeResult& local_merge_result, | 82 const syncer::SyncMergeResult& local_merge_result, |
| 77 const SyncMergeResult& syncer_merge_result); | 83 const syncer::SyncMergeResult& syncer_merge_result); |
| 78 | 84 |
| 79 // Record association time. | 85 // Record association time. |
| 80 virtual void RecordAssociationTime(base::TimeDelta time); | 86 virtual void RecordAssociationTime(base::TimeDelta time); |
| 81 // Record causes of start failure. | 87 // Record causes of start failure. |
| 82 virtual void RecordStartFailure(ConfigureResult result); | 88 virtual void RecordStartFailure(ConfigureResult result); |
| 83 | 89 |
| 84 virtual AssociatorInterface* model_associator() const; | 90 virtual sync_driver::AssociatorInterface* model_associator() const; |
| 85 virtual void set_model_associator(AssociatorInterface* associator); | 91 virtual void set_model_associator( |
| 86 ChangeProcessor* GetChangeProcessor() const override; | 92 sync_driver::AssociatorInterface* associator); |
| 87 virtual void set_change_processor(ChangeProcessor* processor); | 93 sync_driver::ChangeProcessor* GetChangeProcessor() const override; |
| 94 virtual void set_change_processor(sync_driver::ChangeProcessor* processor); |
| 88 | 95 |
| 89 // If the DTC is waiting for models to load, once the models are | 96 // If the DTC is waiting for models to load, once the models are |
| 90 // loaded the datatype service will call this function on DTC to let | 97 // loaded the datatype service will call this function on DTC to let |
| 91 // us know that it is safe to start associating. | 98 // us know that it is safe to start associating. |
| 92 void OnModelLoaded(); | 99 void OnModelLoaded(); |
| 93 | 100 |
| 94 std::unique_ptr<DataTypeErrorHandler> CreateErrorHandler() override; | 101 std::unique_ptr<syncer::DataTypeErrorHandler> CreateErrorHandler() override; |
| 95 | 102 |
| 96 State state_; | 103 State state_; |
| 97 | 104 |
| 98 StartCallback start_callback_; | 105 StartCallback start_callback_; |
| 99 ModelLoadCallback model_load_callback_; | 106 ModelLoadCallback model_load_callback_; |
| 100 | 107 |
| 101 // TODO(sync): transition all datatypes to SyncableService and deprecate | 108 // TODO(sync): transition all datatypes to SyncableService and deprecate |
| 102 // AssociatorInterface. | 109 // AssociatorInterface. |
| 103 std::unique_ptr<AssociatorInterface> model_associator_; | 110 std::unique_ptr<sync_driver::AssociatorInterface> model_associator_; |
| 104 std::unique_ptr<ChangeProcessor> change_processor_; | 111 std::unique_ptr<sync_driver::ChangeProcessor> change_processor_; |
| 105 | 112 |
| 106 private: | 113 private: |
| 107 // Build sync components and associate models. | 114 // Build sync components and associate models. |
| 108 virtual void Associate(); | 115 virtual void Associate(); |
| 109 | 116 |
| 110 void AbortModelLoad(); | 117 void AbortModelLoad(); |
| 111 | 118 |
| 112 // Clean up our state and state variables. Called in response | 119 // Clean up our state and state variables. Called in response |
| 113 // to a failure or abort or stop. | 120 // to a failure or abort or stop. |
| 114 void CleanUp(); | 121 void CleanUp(); |
| 115 | 122 |
| 116 // Handle an unrecoverable error. | 123 // Handle an unrecoverable error. |
| 117 void OnUnrecoverableError(const SyncError& error); | 124 void OnUnrecoverableError(const syncer::SyncError& error); |
| 118 | 125 |
| 119 DISALLOW_COPY_AND_ASSIGN(FrontendDataTypeController); | 126 DISALLOW_COPY_AND_ASSIGN(FrontendDataTypeController); |
| 120 }; | 127 }; |
| 121 | 128 |
| 122 } // namespace syncer | 129 } // namespace browser_sync |
| 123 | 130 |
| 124 #endif // COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_H__ | 131 #endif // COMPONENTS_SYNC_DRIVER_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
| OLD | NEW |