| 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_UI_DATA_TYPE_CONTROLLER_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_UI_DATA_TYPE_CONTROLLER_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_UI_DATA_TYPE_CONTROLLER_H_ | 6 #define COMPONENTS_SYNC_DRIVER_UI_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 "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/sync/driver/directory_data_type_controller.h" | 15 #include "components/sync/driver/directory_data_type_controller.h" |
| 16 #include "components/sync/driver/shared_change_processor.h" | 16 #include "components/sync/driver/shared_change_processor.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class TimeDelta; | 19 class TimeDelta; |
| 20 } | 20 } // namespace base |
| 21 | 21 |
| 22 namespace syncer { | 22 namespace syncer { |
| 23 |
| 23 class SyncableService; | 24 class SyncableService; |
| 24 class SyncClient; | 25 class SyncClient; |
| 25 class SyncError; | 26 class SyncError; |
| 26 } | |
| 27 | |
| 28 namespace sync_driver { | |
| 29 | 27 |
| 30 // Implementation for datatypes that reside on the (UI thread). This is the same | 28 // Implementation for datatypes that reside on the (UI thread). This is the same |
| 31 // thread we perform initialization on, so we don't have to worry about thread | 29 // thread we perform initialization on, so we don't have to worry about thread |
| 32 // safety. The main start/stop funtionality is implemented by default. | 30 // safety. The main start/stop funtionality is implemented by default. |
| 33 // Note: RefCountedThreadSafe by way of DataTypeController. | 31 // Note: RefCountedThreadSafe by way of DataTypeController. |
| 34 class UIDataTypeController : public DirectoryDataTypeController { | 32 class UIDataTypeController : public DirectoryDataTypeController { |
| 35 public: | 33 public: |
| 36 // |dump_stack| is called when an unrecoverable error occurs. | 34 // |dump_stack| is called when an unrecoverable error occurs. |
| 37 UIDataTypeController(syncer::ModelType type, | 35 UIDataTypeController(ModelType type, |
| 38 const base::Closure& dump_stack, | 36 const base::Closure& dump_stack, |
| 39 SyncClient* sync_client); | 37 SyncClient* sync_client); |
| 40 ~UIDataTypeController() override; | 38 ~UIDataTypeController() override; |
| 41 | 39 |
| 42 // DataTypeController interface. | 40 // DataTypeController interface. |
| 43 void LoadModels(const ModelLoadCallback& model_load_callback) override; | 41 void LoadModels(const ModelLoadCallback& model_load_callback) override; |
| 44 void StartAssociating(const StartCallback& start_callback) override; | 42 void StartAssociating(const StartCallback& start_callback) override; |
| 45 void Stop() override; | 43 void Stop() override; |
| 46 syncer::ModelSafeGroup model_safe_group() const override; | 44 ModelSafeGroup model_safe_group() const override; |
| 47 ChangeProcessor* GetChangeProcessor() const override; | 45 ChangeProcessor* GetChangeProcessor() const override; |
| 48 std::string name() const override; | 46 std::string name() const override; |
| 49 State state() const override; | 47 State state() const override; |
| 50 | 48 |
| 51 // Used by tests to override the factory used to create | 49 // Used by tests to override the factory used to create |
| 52 // GenericChangeProcessors. | 50 // GenericChangeProcessors. |
| 53 void SetGenericChangeProcessorFactoryForTest( | 51 void SetGenericChangeProcessorFactoryForTest( |
| 54 std::unique_ptr<GenericChangeProcessorFactory> factory); | 52 std::unique_ptr<GenericChangeProcessorFactory> factory); |
| 55 | 53 |
| 56 protected: | 54 protected: |
| 57 // For testing only. | 55 // For testing only. |
| 58 UIDataTypeController(); | 56 UIDataTypeController(); |
| 59 | 57 |
| 60 // Start any dependent services that need to be running before we can | 58 // Start any dependent services that need to be running before we can |
| 61 // associate models. The default implementation is a no-op. | 59 // associate models. The default implementation is a no-op. |
| 62 // Return value: | 60 // Return value: |
| 63 // True - if models are ready and association can proceed. | 61 // True - if models are ready and association can proceed. |
| 64 // False - if models are not ready. OnModelLoaded() should be called when | 62 // False - if models are not ready. OnModelLoaded() should be called when |
| 65 // the models are ready. | 63 // the models are ready. |
| 66 virtual bool StartModels(); | 64 virtual bool StartModels(); |
| 67 | 65 |
| 68 // Perform any DataType controller specific state cleanup before stopping | 66 // Perform any DataType controller specific state cleanup before stopping |
| 69 // the datatype controller. The default implementation is a no-op. | 67 // the datatype controller. The default implementation is a no-op. |
| 70 virtual void StopModels(); | 68 virtual void StopModels(); |
| 71 | 69 |
| 72 // Helper method for cleaning up state and invoking the start callback. | 70 // Helper method for cleaning up state and invoking the start callback. |
| 73 virtual void StartDone(ConfigureResult result, | 71 virtual void StartDone(ConfigureResult result, |
| 74 const syncer::SyncMergeResult& local_merge_result, | 72 const SyncMergeResult& local_merge_result, |
| 75 const syncer::SyncMergeResult& syncer_merge_result); | 73 const SyncMergeResult& syncer_merge_result); |
| 76 | 74 |
| 77 // Record association time. | 75 // Record association time. |
| 78 virtual void RecordAssociationTime(base::TimeDelta time); | 76 virtual void RecordAssociationTime(base::TimeDelta time); |
| 79 // Record causes of start failure. | 77 // Record causes of start failure. |
| 80 virtual void RecordStartFailure(ConfigureResult result); | 78 virtual void RecordStartFailure(ConfigureResult result); |
| 81 | 79 |
| 82 // If the DTC is waiting for models to load, once the models are | 80 // If the DTC is waiting for models to load, once the models are |
| 83 // loaded the datatype service will call this function on DTC to let | 81 // loaded the datatype service will call this function on DTC to let |
| 84 // us know that it is safe to start associating. | 82 // us know that it is safe to start associating. |
| 85 void OnModelLoaded(); | 83 void OnModelLoaded(); |
| 86 | 84 |
| 87 std::unique_ptr<syncer::DataTypeErrorHandler> CreateErrorHandler() override; | 85 std::unique_ptr<DataTypeErrorHandler> CreateErrorHandler() override; |
| 88 | 86 |
| 89 State state_; | 87 State state_; |
| 90 | 88 |
| 91 StartCallback start_callback_; | 89 StartCallback start_callback_; |
| 92 ModelLoadCallback model_load_callback_; | 90 ModelLoadCallback model_load_callback_; |
| 93 | 91 |
| 94 // Sync's interface to the datatype. All sync changes for |type_| are pushed | 92 // Sync's interface to the datatype. All sync changes for |type_| are pushed |
| 95 // through it to the datatype as well as vice versa. | 93 // through it to the datatype as well as vice versa. |
| 96 // | 94 // |
| 97 // Lifetime: it gets created when Start()) is called, and a reference to it | 95 // Lifetime: it gets created when Start()) is called, and a reference to it |
| 98 // is passed to |local_service_| during Associate(). We release our reference | 96 // is passed to |local_service_| during Associate(). We release our reference |
| 99 // when Stop() or StartFailed() is called, and |local_service_| releases its | 97 // when Stop() or StartFailed() is called, and |local_service_| releases its |
| 100 // reference when local_service_->StopSyncing() is called or when it is | 98 // reference when local_service_->StopSyncing() is called or when it is |
| 101 // destroyed. | 99 // destroyed. |
| 102 // | 100 // |
| 103 // Note: we use refcounting here primarily so that we can keep a uniform | 101 // Note: we use refcounting here primarily so that we can keep a uniform |
| 104 // SyncableService API, whether the datatype lives on the UI thread or not | 102 // SyncableService API, whether the datatype lives on the UI thread or not |
| 105 // (a syncer::SyncableService takes ownership of its SyncChangeProcessor when | 103 // (a SyncableService takes ownership of its SyncChangeProcessor when |
| 106 // MergeDataAndStartSyncing is called). This will help us eventually merge the | 104 // MergeDataAndStartSyncing is called). This will help us eventually merge the |
| 107 // two datatype controller implementations (for ui and non-ui thread | 105 // two datatype controller implementations (for ui and non-ui thread |
| 108 // datatypes). | 106 // datatypes). |
| 109 scoped_refptr<SharedChangeProcessor> shared_change_processor_; | 107 scoped_refptr<SharedChangeProcessor> shared_change_processor_; |
| 110 | 108 |
| 111 std::unique_ptr<GenericChangeProcessorFactory> processor_factory_; | 109 std::unique_ptr<GenericChangeProcessorFactory> processor_factory_; |
| 112 | 110 |
| 113 // A weak pointer to the actual local syncable service, which performs all the | 111 // A weak pointer to the actual local syncable service, which performs all the |
| 114 // real work. We do not own the object. | 112 // real work. We do not own the object. |
| 115 base::WeakPtr<syncer::SyncableService> local_service_; | 113 base::WeakPtr<SyncableService> local_service_; |
| 116 | 114 |
| 117 private: | 115 private: |
| 118 // Associate the sync model with the service's model, then start syncing. | 116 // Associate the sync model with the service's model, then start syncing. |
| 119 virtual void Associate(); | 117 virtual void Associate(); |
| 120 | 118 |
| 121 virtual void AbortModelLoad(); | 119 virtual void AbortModelLoad(); |
| 122 | 120 |
| 123 void OnUnrecoverableError(const syncer::SyncError& error); | 121 void OnUnrecoverableError(const SyncError& error); |
| 124 | 122 |
| 125 DISALLOW_COPY_AND_ASSIGN(UIDataTypeController); | 123 DISALLOW_COPY_AND_ASSIGN(UIDataTypeController); |
| 126 }; | 124 }; |
| 127 | 125 |
| 128 } // namespace sync_driver | 126 } // namespace syncer |
| 129 | 127 |
| 130 #endif // COMPONENTS_SYNC_DRIVER_UI_DATA_TYPE_CONTROLLER_H_ | 128 #endif // COMPONENTS_SYNC_DRIVER_UI_DATA_TYPE_CONTROLLER_H_ |
| OLD | NEW |