| 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_DATA_TYPE_CONTROLLER_H__ | 5 #ifndef COMPONENTS_SYNC_DRIVER_DATA_TYPE_CONTROLLER_H__ |
| 6 #define COMPONENTS_SYNC_DRIVER_DATA_TYPE_CONTROLLER_H__ | 6 #define COMPONENTS_SYNC_DRIVER_DATA_TYPE_CONTROLLER_H__ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "components/sync/api/data_type_error_handler.h" | 16 #include "components/sync/api/data_type_error_handler.h" |
| 17 #include "components/sync/base/model_type.h" | 17 #include "components/sync/base/model_type.h" |
| 18 #include "components/sync/base/unrecoverable_error_handler.h" | 18 #include "components/sync/base/unrecoverable_error_handler.h" |
| 19 | 19 |
| 20 namespace syncer { | 20 namespace syncer { |
| 21 |
| 22 class BackendDataTypeConfigurer; |
| 21 class SyncError; | 23 class SyncError; |
| 22 class SyncMergeResult; | 24 class SyncMergeResult; |
| 23 } | |
| 24 | |
| 25 namespace sync_driver { | |
| 26 class BackendDataTypeConfigurer; | |
| 27 | 25 |
| 28 // DataTypeControllers are responsible for managing the state of a single data | 26 // DataTypeControllers are responsible for managing the state of a single data |
| 29 // type. They are not thread safe and should only be used on the UI thread. | 27 // type. They are not thread safe and should only be used on the UI thread. |
| 30 class DataTypeController : public base::SupportsWeakPtr<DataTypeController> { | 28 class DataTypeController : public base::SupportsWeakPtr<DataTypeController> { |
| 31 public: | 29 public: |
| 32 enum State { | 30 enum State { |
| 33 NOT_RUNNING, // The controller has never been started or has previously | 31 NOT_RUNNING, // The controller has never been started or has previously |
| 34 // been stopped. Must be in this state to start. | 32 // been stopped. Must be in this state to start. |
| 35 MODEL_STARTING, // The controller is waiting on dependent services | 33 MODEL_STARTING, // The controller is waiting on dependent services |
| 36 // that need to be available before model | 34 // that need to be available before model |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 // determined by cloud state. | 53 // determined by cloud state. |
| 56 ASSOCIATION_FAILED, // An error occurred during model association. | 54 ASSOCIATION_FAILED, // An error occurred during model association. |
| 57 ABORTED, // Start was aborted by calling Stop(). | 55 ABORTED, // Start was aborted by calling Stop(). |
| 58 UNRECOVERABLE_ERROR, // An unrecoverable error occured. | 56 UNRECOVERABLE_ERROR, // An unrecoverable error occured. |
| 59 NEEDS_CRYPTO, // The data type cannot be started yet because it | 57 NEEDS_CRYPTO, // The data type cannot be started yet because it |
| 60 // depends on the cryptographer. | 58 // depends on the cryptographer. |
| 61 RUNTIME_ERROR, // After starting, a runtime error was encountered. | 59 RUNTIME_ERROR, // After starting, a runtime error was encountered. |
| 62 MAX_CONFIGURE_RESULT | 60 MAX_CONFIGURE_RESULT |
| 63 }; | 61 }; |
| 64 | 62 |
| 65 typedef base::Callback<void(ConfigureResult, | 63 typedef base::Callback< |
| 66 const syncer::SyncMergeResult&, | 64 void(ConfigureResult, const SyncMergeResult&, const SyncMergeResult&)> |
| 67 const syncer::SyncMergeResult&)> | |
| 68 StartCallback; | 65 StartCallback; |
| 69 | 66 |
| 70 typedef base::Callback<void(syncer::ModelType, const syncer::SyncError&)> | 67 typedef base::Callback<void(ModelType, const SyncError&)> ModelLoadCallback; |
| 71 ModelLoadCallback; | |
| 72 | 68 |
| 73 typedef base::Callback<void(const syncer::ModelType, | 69 typedef base::Callback<void(const ModelType, |
| 74 std::unique_ptr<base::ListValue>)> | 70 std::unique_ptr<base::ListValue>)> |
| 75 AllNodesCallback; | 71 AllNodesCallback; |
| 76 | 72 |
| 77 typedef std::map<syncer::ModelType, std::unique_ptr<DataTypeController>> | 73 typedef std::map<ModelType, std::unique_ptr<DataTypeController>> TypeMap; |
| 78 TypeMap; | 74 typedef std::map<ModelType, DataTypeController::State> StateMap; |
| 79 typedef std::map<syncer::ModelType, DataTypeController::State> StateMap; | |
| 80 | 75 |
| 81 // Returns true if the start result should trigger an unrecoverable error. | 76 // Returns true if the start result should trigger an unrecoverable error. |
| 82 // Public so unit tests can use this function as well. | 77 // Public so unit tests can use this function as well. |
| 83 static bool IsUnrecoverableResult(ConfigureResult result); | 78 static bool IsUnrecoverableResult(ConfigureResult result); |
| 84 | 79 |
| 85 // Returns true if the datatype started successfully. | 80 // Returns true if the datatype started successfully. |
| 86 static bool IsSuccessfulResult(ConfigureResult result); | 81 static bool IsSuccessfulResult(ConfigureResult result); |
| 87 | 82 |
| 88 virtual ~DataTypeController(); | 83 virtual ~DataTypeController(); |
| 89 | 84 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // propagate from sync again from point where Stop() is called. | 125 // propagate from sync again from point where Stop() is called. |
| 131 virtual void Stop() = 0; | 126 virtual void Stop() = 0; |
| 132 | 127 |
| 133 // Name of this data type. For logging purposes only. | 128 // Name of this data type. For logging purposes only. |
| 134 virtual std::string name() const = 0; | 129 virtual std::string name() const = 0; |
| 135 | 130 |
| 136 // Current state of the data type controller. | 131 // Current state of the data type controller. |
| 137 virtual State state() const = 0; | 132 virtual State state() const = 0; |
| 138 | 133 |
| 139 // Unique model type for this data type controller. | 134 // Unique model type for this data type controller. |
| 140 syncer::ModelType type() const { return type_; } | 135 ModelType type() const { return type_; } |
| 141 | 136 |
| 142 // Whether the DataTypeController is ready to start. This is useful if the | 137 // Whether the DataTypeController is ready to start. This is useful if the |
| 143 // datatype itself must make the decision about whether it should be enabled | 138 // datatype itself must make the decision about whether it should be enabled |
| 144 // at all (and therefore whether the initial download of the sync data for | 139 // at all (and therefore whether the initial download of the sync data for |
| 145 // the type should be performed). | 140 // the type should be performed). |
| 146 // Returns true by default. | 141 // Returns true by default. |
| 147 virtual bool ReadyForStart() const; | 142 virtual bool ReadyForStart() const; |
| 148 | 143 |
| 149 // Returns a ListValue representing all nodes for this data type through | 144 // Returns a ListValue representing all nodes for this data type through |
| 150 // |callback| on this thread. | 145 // |callback| on this thread. |
| 151 // Used for populating nodes in Sync Node Browser of chrome://sync-internals. | 146 // Used for populating nodes in Sync Node Browser of chrome://sync-internals. |
| 152 virtual void GetAllNodes(const AllNodesCallback& callback) = 0; | 147 virtual void GetAllNodes(const AllNodesCallback& callback) = 0; |
| 153 | 148 |
| 154 protected: | 149 protected: |
| 155 DataTypeController(syncer::ModelType type, const base::Closure& dump_stack); | 150 DataTypeController(ModelType type, const base::Closure& dump_stack); |
| 156 | 151 |
| 157 // Create an error handler that reports back to this controller. | 152 // Create an error handler that reports back to this controller. |
| 158 virtual std::unique_ptr<syncer::DataTypeErrorHandler> | 153 virtual std::unique_ptr<DataTypeErrorHandler> CreateErrorHandler() = 0; |
| 159 CreateErrorHandler() = 0; | |
| 160 | 154 |
| 161 // Allows subclasses to DCHECK that they're on the correct thread. | 155 // Allows subclasses to DCHECK that they're on the correct thread. |
| 162 bool CalledOnValidThread() const; | 156 bool CalledOnValidThread() const; |
| 163 | 157 |
| 164 // Callback to dump and upload a stack trace when an error occurs. | 158 // Callback to dump and upload a stack trace when an error occurs. |
| 165 base::Closure dump_stack_; | 159 base::Closure dump_stack_; |
| 166 | 160 |
| 167 private: | 161 private: |
| 168 // The type this object is responsible for controlling. | 162 // The type this object is responsible for controlling. |
| 169 const syncer::ModelType type_; | 163 const ModelType type_; |
| 170 | 164 |
| 171 // Used to check that functions are called on the correct thread. | 165 // Used to check that functions are called on the correct thread. |
| 172 base::ThreadChecker thread_checker_; | 166 base::ThreadChecker thread_checker_; |
| 173 }; | 167 }; |
| 174 | 168 |
| 175 } // namespace sync_driver | 169 } // namespace syncer |
| 176 | 170 |
| 177 #endif // COMPONENTS_SYNC_DRIVER_DATA_TYPE_CONTROLLER_H__ | 171 #endif // COMPONENTS_SYNC_DRIVER_DATA_TYPE_CONTROLLER_H__ |
| OLD | NEW |