| 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 #include "components/sync/driver/fake_data_type_controller.h" | 5 #include "components/sync/driver/fake_data_type_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "components/sync/api/data_type_error_handler_impl.h" | 10 #include "components/sync/api/data_type_error_handler_impl.h" |
| 11 #include "components/sync/api/sync_merge_result.h" | 11 #include "components/sync/api/sync_merge_result.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace syncer { | 15 using syncer::ModelType; |
| 16 |
| 17 namespace sync_driver { |
| 16 | 18 |
| 17 FakeDataTypeController::FakeDataTypeController(ModelType type) | 19 FakeDataTypeController::FakeDataTypeController(ModelType type) |
| 18 : DirectoryDataTypeController(type, base::Closure(), nullptr), | 20 : DirectoryDataTypeController(type, base::Closure(), nullptr), |
| 19 state_(NOT_RUNNING), | 21 state_(NOT_RUNNING), |
| 20 model_load_delayed_(false), | 22 model_load_delayed_(false), |
| 21 ready_for_start_(true), | 23 ready_for_start_(true), |
| 22 should_load_model_before_configure_(false), | 24 should_load_model_before_configure_(false), |
| 23 register_with_backend_call_count_(0) {} | 25 register_with_backend_call_count_(0) {} |
| 24 | 26 |
| 25 FakeDataTypeController::~FakeDataTypeController() {} | 27 FakeDataTypeController::~FakeDataTypeController() {} |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // (depending on |result|) | 68 // (depending on |result|) |
| 67 void FakeDataTypeController::FinishStart(ConfigureResult result) { | 69 void FakeDataTypeController::FinishStart(ConfigureResult result) { |
| 68 DCHECK(CalledOnValidThread()); | 70 DCHECK(CalledOnValidThread()); |
| 69 // We should have a callback from Start(). | 71 // We should have a callback from Start(). |
| 70 if (last_start_callback_.is_null()) { | 72 if (last_start_callback_.is_null()) { |
| 71 ADD_FAILURE(); | 73 ADD_FAILURE(); |
| 72 return; | 74 return; |
| 73 } | 75 } |
| 74 | 76 |
| 75 // Set |state_| first below since the callback may call state(). | 77 // Set |state_| first below since the callback may call state(). |
| 76 SyncMergeResult local_merge_result(type()); | 78 syncer::SyncMergeResult local_merge_result(type()); |
| 77 SyncMergeResult syncer_merge_result(type()); | 79 syncer::SyncMergeResult syncer_merge_result(type()); |
| 78 if (result <= OK_FIRST_RUN) { | 80 if (result <= OK_FIRST_RUN) { |
| 79 state_ = RUNNING; | 81 state_ = RUNNING; |
| 80 } else if (result == ASSOCIATION_FAILED) { | 82 } else if (result == ASSOCIATION_FAILED) { |
| 81 state_ = DISABLED; | 83 state_ = DISABLED; |
| 82 local_merge_result.set_error(SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, | 84 local_merge_result.set_error( |
| 83 "Association failed", type())); | 85 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, |
| 86 "Association failed", type())); |
| 84 } else if (result == UNRECOVERABLE_ERROR) { | 87 } else if (result == UNRECOVERABLE_ERROR) { |
| 85 state_ = NOT_RUNNING; | 88 state_ = NOT_RUNNING; |
| 86 local_merge_result.set_error(SyncError(FROM_HERE, | 89 local_merge_result.set_error( |
| 87 SyncError::UNRECOVERABLE_ERROR, | 90 syncer::SyncError(FROM_HERE, syncer::SyncError::UNRECOVERABLE_ERROR, |
| 88 "Unrecoverable error", type())); | 91 "Unrecoverable error", type())); |
| 89 } else if (result == NEEDS_CRYPTO) { | 92 } else if (result == NEEDS_CRYPTO) { |
| 90 state_ = NOT_RUNNING; | 93 state_ = NOT_RUNNING; |
| 91 local_merge_result.set_error( | 94 local_merge_result.set_error(syncer::SyncError( |
| 92 SyncError(FROM_HERE, SyncError::CRYPTO_ERROR, "Crypto error", type())); | 95 FROM_HERE, syncer::SyncError::CRYPTO_ERROR, "Crypto error", type())); |
| 93 } else { | 96 } else { |
| 94 NOTREACHED(); | 97 NOTREACHED(); |
| 95 } | 98 } |
| 96 last_start_callback_.Run(result, local_merge_result, syncer_merge_result); | 99 last_start_callback_.Run(result, local_merge_result, syncer_merge_result); |
| 97 } | 100 } |
| 98 | 101 |
| 99 // * -> NOT_RUNNING | 102 // * -> NOT_RUNNING |
| 100 void FakeDataTypeController::Stop() { | 103 void FakeDataTypeController::Stop() { |
| 101 DCHECK(CalledOnValidThread()); | 104 DCHECK(CalledOnValidThread()); |
| 102 if (!model_load_callback_.is_null()) { | 105 if (!model_load_callback_.is_null()) { |
| 103 // Real data type controllers run the callback and specify "ABORTED" as an | 106 // Real data type controllers run the callback and specify "ABORTED" as an |
| 104 // error. We should probably find a way to use the real code and mock out | 107 // error. We should probably find a way to use the real code and mock out |
| 105 // unnecessary pieces. | 108 // unnecessary pieces. |
| 106 SimulateModelLoadFinishing(); | 109 SimulateModelLoadFinishing(); |
| 107 } | 110 } |
| 108 state_ = NOT_RUNNING; | 111 state_ = NOT_RUNNING; |
| 109 } | 112 } |
| 110 | 113 |
| 111 std::string FakeDataTypeController::name() const { | 114 std::string FakeDataTypeController::name() const { |
| 112 return ModelTypeToString(type()); | 115 return ModelTypeToString(type()); |
| 113 } | 116 } |
| 114 | 117 |
| 115 ModelSafeGroup FakeDataTypeController::model_safe_group() const { | 118 syncer::ModelSafeGroup FakeDataTypeController::model_safe_group() const { |
| 116 return GROUP_PASSIVE; | 119 return syncer::GROUP_PASSIVE; |
| 117 } | 120 } |
| 118 | 121 |
| 119 ChangeProcessor* FakeDataTypeController::GetChangeProcessor() const { | 122 ChangeProcessor* FakeDataTypeController::GetChangeProcessor() const { |
| 120 return NULL; | 123 return NULL; |
| 121 } | 124 } |
| 122 | 125 |
| 123 DataTypeController::State FakeDataTypeController::state() const { | 126 DataTypeController::State FakeDataTypeController::state() const { |
| 124 return state_; | 127 return state_; |
| 125 } | 128 } |
| 126 | 129 |
| 127 bool FakeDataTypeController::ReadyForStart() const { | 130 bool FakeDataTypeController::ReadyForStart() const { |
| 128 return ready_for_start_; | 131 return ready_for_start_; |
| 129 } | 132 } |
| 130 | 133 |
| 131 void FakeDataTypeController::SetDelayModelLoad() { | 134 void FakeDataTypeController::SetDelayModelLoad() { |
| 132 model_load_delayed_ = true; | 135 model_load_delayed_ = true; |
| 133 } | 136 } |
| 134 | 137 |
| 135 void FakeDataTypeController::SetModelLoadError(SyncError error) { | 138 void FakeDataTypeController::SetModelLoadError(syncer::SyncError error) { |
| 136 load_error_ = error; | 139 load_error_ = error; |
| 137 } | 140 } |
| 138 | 141 |
| 139 void FakeDataTypeController::SimulateModelLoadFinishing() { | 142 void FakeDataTypeController::SimulateModelLoadFinishing() { |
| 140 if (load_error_.IsSet()) | 143 if (load_error_.IsSet()) |
| 141 state_ = DISABLED; | 144 state_ = DISABLED; |
| 142 else | 145 else |
| 143 state_ = MODEL_LOADED; | 146 state_ = MODEL_LOADED; |
| 144 model_load_callback_.Run(type(), load_error_); | 147 model_load_callback_.Run(type(), load_error_); |
| 145 } | 148 } |
| 146 | 149 |
| 147 void FakeDataTypeController::SetReadyForStart(bool ready) { | 150 void FakeDataTypeController::SetReadyForStart(bool ready) { |
| 148 ready_for_start_ = ready; | 151 ready_for_start_ = ready; |
| 149 } | 152 } |
| 150 | 153 |
| 151 void FakeDataTypeController::SetShouldLoadModelBeforeConfigure(bool value) { | 154 void FakeDataTypeController::SetShouldLoadModelBeforeConfigure(bool value) { |
| 152 should_load_model_before_configure_ = value; | 155 should_load_model_before_configure_ = value; |
| 153 } | 156 } |
| 154 | 157 |
| 155 std::unique_ptr<DataTypeErrorHandler> | 158 std::unique_ptr<syncer::DataTypeErrorHandler> |
| 156 FakeDataTypeController::CreateErrorHandler() { | 159 FakeDataTypeController::CreateErrorHandler() { |
| 157 DCHECK(CalledOnValidThread()); | 160 DCHECK(CalledOnValidThread()); |
| 158 return base::MakeUnique<DataTypeErrorHandlerImpl>( | 161 return base::MakeUnique<syncer::DataTypeErrorHandlerImpl>( |
| 159 base::ThreadTaskRunnerHandle::Get(), base::Closure(), | 162 base::ThreadTaskRunnerHandle::Get(), base::Closure(), |
| 160 base::Bind(model_load_callback_, type())); | 163 base::Bind(model_load_callback_, type())); |
| 161 } | 164 } |
| 162 | 165 |
| 163 } // namespace syncer | 166 } // namespace sync_driver |
| OLD | NEW |