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