Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(647)

Side by Side Diff: components/sync/driver/fake_data_type_controller.cc

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 using syncer::ModelType; 15 namespace syncer {
16
17 namespace sync_driver {
18 16
19 FakeDataTypeController::FakeDataTypeController(ModelType type) 17 FakeDataTypeController::FakeDataTypeController(ModelType type)
20 : DirectoryDataTypeController(type, base::Closure(), nullptr), 18 : DirectoryDataTypeController(type, base::Closure(), nullptr),
21 state_(NOT_RUNNING), 19 state_(NOT_RUNNING),
22 model_load_delayed_(false), 20 model_load_delayed_(false),
23 ready_for_start_(true), 21 ready_for_start_(true),
24 should_load_model_before_configure_(false), 22 should_load_model_before_configure_(false),
25 register_with_backend_call_count_(0) {} 23 register_with_backend_call_count_(0) {}
26 24
27 FakeDataTypeController::~FakeDataTypeController() {} 25 FakeDataTypeController::~FakeDataTypeController() {}
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // (depending on |result|) 66 // (depending on |result|)
69 void FakeDataTypeController::FinishStart(ConfigureResult result) { 67 void FakeDataTypeController::FinishStart(ConfigureResult result) {
70 DCHECK(CalledOnValidThread()); 68 DCHECK(CalledOnValidThread());
71 // We should have a callback from Start(). 69 // We should have a callback from Start().
72 if (last_start_callback_.is_null()) { 70 if (last_start_callback_.is_null()) {
73 ADD_FAILURE(); 71 ADD_FAILURE();
74 return; 72 return;
75 } 73 }
76 74
77 // Set |state_| first below since the callback may call state(). 75 // Set |state_| first below since the callback may call state().
78 syncer::SyncMergeResult local_merge_result(type()); 76 SyncMergeResult local_merge_result(type());
79 syncer::SyncMergeResult syncer_merge_result(type()); 77 SyncMergeResult syncer_merge_result(type());
80 if (result <= OK_FIRST_RUN) { 78 if (result <= OK_FIRST_RUN) {
81 state_ = RUNNING; 79 state_ = RUNNING;
82 } else if (result == ASSOCIATION_FAILED) { 80 } else if (result == ASSOCIATION_FAILED) {
83 state_ = DISABLED; 81 state_ = DISABLED;
84 local_merge_result.set_error( 82 local_merge_result.set_error(SyncError(FROM_HERE, SyncError::DATATYPE_ERROR,
85 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, 83 "Association failed", type()));
86 "Association failed", type()));
87 } else if (result == UNRECOVERABLE_ERROR) { 84 } else if (result == UNRECOVERABLE_ERROR) {
88 state_ = NOT_RUNNING; 85 state_ = NOT_RUNNING;
89 local_merge_result.set_error( 86 local_merge_result.set_error(SyncError(FROM_HERE,
90 syncer::SyncError(FROM_HERE, syncer::SyncError::UNRECOVERABLE_ERROR, 87 SyncError::UNRECOVERABLE_ERROR,
91 "Unrecoverable error", type())); 88 "Unrecoverable error", type()));
92 } else if (result == NEEDS_CRYPTO) { 89 } else if (result == NEEDS_CRYPTO) {
93 state_ = NOT_RUNNING; 90 state_ = NOT_RUNNING;
94 local_merge_result.set_error(syncer::SyncError( 91 local_merge_result.set_error(
95 FROM_HERE, syncer::SyncError::CRYPTO_ERROR, "Crypto error", type())); 92 SyncError(FROM_HERE, SyncError::CRYPTO_ERROR, "Crypto error", type()));
96 } else { 93 } else {
97 NOTREACHED(); 94 NOTREACHED();
98 } 95 }
99 last_start_callback_.Run(result, local_merge_result, syncer_merge_result); 96 last_start_callback_.Run(result, local_merge_result, syncer_merge_result);
100 } 97 }
101 98
102 // * -> NOT_RUNNING 99 // * -> NOT_RUNNING
103 void FakeDataTypeController::Stop() { 100 void FakeDataTypeController::Stop() {
104 DCHECK(CalledOnValidThread()); 101 DCHECK(CalledOnValidThread());
105 if (!model_load_callback_.is_null()) { 102 if (!model_load_callback_.is_null()) {
106 // Real data type controllers run the callback and specify "ABORTED" as an 103 // Real data type controllers run the callback and specify "ABORTED" as an
107 // error. We should probably find a way to use the real code and mock out 104 // error. We should probably find a way to use the real code and mock out
108 // unnecessary pieces. 105 // unnecessary pieces.
109 SimulateModelLoadFinishing(); 106 SimulateModelLoadFinishing();
110 } 107 }
111 state_ = NOT_RUNNING; 108 state_ = NOT_RUNNING;
112 } 109 }
113 110
114 std::string FakeDataTypeController::name() const { 111 std::string FakeDataTypeController::name() const {
115 return ModelTypeToString(type()); 112 return ModelTypeToString(type());
116 } 113 }
117 114
118 syncer::ModelSafeGroup FakeDataTypeController::model_safe_group() const { 115 ModelSafeGroup FakeDataTypeController::model_safe_group() const {
119 return syncer::GROUP_PASSIVE; 116 return GROUP_PASSIVE;
120 } 117 }
121 118
122 ChangeProcessor* FakeDataTypeController::GetChangeProcessor() const { 119 ChangeProcessor* FakeDataTypeController::GetChangeProcessor() const {
123 return NULL; 120 return NULL;
124 } 121 }
125 122
126 DataTypeController::State FakeDataTypeController::state() const { 123 DataTypeController::State FakeDataTypeController::state() const {
127 return state_; 124 return state_;
128 } 125 }
129 126
130 bool FakeDataTypeController::ReadyForStart() const { 127 bool FakeDataTypeController::ReadyForStart() const {
131 return ready_for_start_; 128 return ready_for_start_;
132 } 129 }
133 130
134 void FakeDataTypeController::SetDelayModelLoad() { 131 void FakeDataTypeController::SetDelayModelLoad() {
135 model_load_delayed_ = true; 132 model_load_delayed_ = true;
136 } 133 }
137 134
138 void FakeDataTypeController::SetModelLoadError(syncer::SyncError error) { 135 void FakeDataTypeController::SetModelLoadError(SyncError error) {
139 load_error_ = error; 136 load_error_ = error;
140 } 137 }
141 138
142 void FakeDataTypeController::SimulateModelLoadFinishing() { 139 void FakeDataTypeController::SimulateModelLoadFinishing() {
143 if (load_error_.IsSet()) 140 if (load_error_.IsSet())
144 state_ = DISABLED; 141 state_ = DISABLED;
145 else 142 else
146 state_ = MODEL_LOADED; 143 state_ = MODEL_LOADED;
147 model_load_callback_.Run(type(), load_error_); 144 model_load_callback_.Run(type(), load_error_);
148 } 145 }
149 146
150 void FakeDataTypeController::SetReadyForStart(bool ready) { 147 void FakeDataTypeController::SetReadyForStart(bool ready) {
151 ready_for_start_ = ready; 148 ready_for_start_ = ready;
152 } 149 }
153 150
154 void FakeDataTypeController::SetShouldLoadModelBeforeConfigure(bool value) { 151 void FakeDataTypeController::SetShouldLoadModelBeforeConfigure(bool value) {
155 should_load_model_before_configure_ = value; 152 should_load_model_before_configure_ = value;
156 } 153 }
157 154
158 std::unique_ptr<syncer::DataTypeErrorHandler> 155 std::unique_ptr<DataTypeErrorHandler>
159 FakeDataTypeController::CreateErrorHandler() { 156 FakeDataTypeController::CreateErrorHandler() {
160 DCHECK(CalledOnValidThread()); 157 DCHECK(CalledOnValidThread());
161 return base::MakeUnique<syncer::DataTypeErrorHandlerImpl>( 158 return base::MakeUnique<DataTypeErrorHandlerImpl>(
162 base::ThreadTaskRunnerHandle::Get(), base::Closure(), 159 base::ThreadTaskRunnerHandle::Get(), base::Closure(),
163 base::Bind(model_load_callback_, type())); 160 base::Bind(model_load_callback_, type()));
164 } 161 }
165 162
166 } // namespace sync_driver 163 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/fake_data_type_controller.h ('k') | components/sync/driver/fake_generic_change_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698