OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/sync/glue/generic_change_processor.h" | 5 #include "chrome/browser/sync/glue/generic_change_processor.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/sync/api/sync_change.h" | 10 #include "chrome/browser/sync/api/sync_change.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 } | 121 } |
122 current_sync_data->push_back(SyncData::CreateRemoteData( | 122 current_sync_data->push_back(SyncData::CreateRemoteData( |
123 sync_child_node.GetId(), sync_child_node.GetEntitySpecifics())); | 123 sync_child_node.GetId(), sync_child_node.GetEntitySpecifics())); |
124 sync_child_id = sync_child_node.GetSuccessorId(); | 124 sync_child_id = sync_child_node.GetSuccessorId(); |
125 } | 125 } |
126 return SyncError(); | 126 return SyncError(); |
127 } | 127 } |
128 | 128 |
129 namespace { | 129 namespace { |
130 | 130 |
131 bool AttemptDelete(const SyncChange& change, sync_api::WriteNode* node) { | 131 // TODO(isherman): Investigating http://crbug.com/121592 |
132 SyncError AttemptDelete(const SyncChange& change, | |
133 syncable::ModelType type, | |
134 std::string type_str, | |
135 sync_api::WriteNode* node, | |
136 DataTypeErrorHandler* error_handler) { | |
132 DCHECK_EQ(change.change_type(), SyncChange::ACTION_DELETE); | 137 DCHECK_EQ(change.change_type(), SyncChange::ACTION_DELETE); |
133 if (change.sync_data().IsLocal()) { | 138 if (change.sync_data().IsLocal()) { |
134 const std::string& tag = change.sync_data().GetTag(); | 139 const std::string& tag = change.sync_data().GetTag(); |
135 if (tag.empty()) { | 140 if (tag.empty()) { |
136 return false; | 141 SyncError error( |
142 FROM_HERE, | |
143 "Failed to delete " + type_str + " node. Local data, empty tag.", | |
144 type); | |
145 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
146 error.message()); | |
147 return error; | |
137 } | 148 } |
138 if (node->InitByClientTagLookup( | 149 |
139 change.sync_data().GetDataType(), tag) != | 150 sync_api::BaseNode::InitByLookupResult result = |
140 sync_api::BaseNode::INIT_OK) { | 151 node->InitByClientTagLookup(change.sync_data().GetDataType(), tag); |
141 return false; | 152 if (result != sync_api::BaseNode::INIT_OK) { |
153 SyncError error; | |
154 switch (result) { | |
155 case sync_api::BaseNode::INIT_FAILED_ENTRY_NOT_GOOD: | |
156 error.Reset(FROM_HERE, | |
157 "Failed to delete " + type_str + " node. Local data, " | |
158 "could not find entry matching the lookup criteria.", | |
159 type); | |
160 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
161 error.message()); | |
162 case sync_api::BaseNode::INIT_FAILED_ENTRY_IS_DEL: | |
tim (not reviewing)
2012/05/16 17:19:37
You need to add good old break/return statements i
Ilya Sherman
2012/05/16 21:10:01
Done.
| |
163 error.Reset(FROM_HERE, | |
164 "Failed to delete " + type_str + " node. Local data, " | |
165 "entry is already deleted.", | |
166 type); | |
167 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
168 error.message()); | |
169 case sync_api::BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY: | |
170 error.Reset(FROM_HERE, | |
171 "Failed to delete " + type_str + " node. Local data, " | |
172 "unable to decrypt", | |
173 type); | |
174 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
175 error.message()); | |
176 case sync_api::BaseNode::INIT_FAILED_PRECONDITION: | |
177 error.Reset(FROM_HERE, | |
178 "Failed to delete " + type_str + " node. Local data, " | |
179 "a precondition was not met for calling init.", | |
180 type); | |
181 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
182 error.message()); | |
183 default: | |
184 // Should have listed all the possible error cases above. | |
185 NOTREACHED(); | |
186 error.Reset(FROM_HERE, | |
187 "Failed to delete " + type_str + " node. Local data, " | |
188 "unknown error", | |
189 type); | |
190 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
191 error.message()); | |
192 } | |
193 return error; | |
142 } | 194 } |
143 } else { | 195 } else { |
144 if (node->InitByIdLookup(change.sync_data().GetRemoteId()) != | 196 sync_api::BaseNode::InitByLookupResult result = |
145 sync_api::BaseNode::INIT_OK) { | 197 node->InitByIdLookup(change.sync_data().GetRemoteId()); |
146 return false; | 198 if (result != sync_api::BaseNode::INIT_OK) { |
199 SyncError error; | |
200 switch (result) { | |
201 case sync_api::BaseNode::INIT_FAILED_ENTRY_NOT_GOOD: | |
tim (not reviewing)
2012/05/16 17:19:37
One possible way we could reduce the code explosio
tim (not reviewing)
2012/05/16 17:23:30
Doh, I guess that will neuter the FROM_HERE in the
Ilya Sherman
2012/05/16 21:10:01
Good call, done.
| |
202 error.Reset(FROM_HERE, | |
203 "Failed to delete " + type_str + " node. Non-local data, " | |
204 "could not find entry matching the lookup criteria.", | |
205 type); | |
206 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
207 error.message()); | |
208 case sync_api::BaseNode::INIT_FAILED_ENTRY_IS_DEL: | |
209 error.Reset(FROM_HERE, | |
210 "Failed to delete " + type_str + " node. Non-local data, " | |
211 "entry is already deleted.", | |
212 type); | |
213 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
214 error.message()); | |
215 case sync_api::BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY: | |
216 error.Reset(FROM_HERE, | |
217 "Failed to delete " + type_str + " node. Non-local data, " | |
218 "unable to decrypt", | |
219 type); | |
220 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
221 error.message()); | |
222 case sync_api::BaseNode::INIT_FAILED_PRECONDITION: | |
223 error.Reset(FROM_HERE, | |
224 "Failed to delete " + type_str + " node. Non-local data, " | |
225 "a precondition was not met for calling init.", | |
226 type); | |
227 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
228 error.message()); | |
229 default: | |
230 // Should have listed all the possible error cases above. | |
231 NOTREACHED(); | |
232 error.Reset(FROM_HERE, | |
233 "Failed to delete " + type_str + " node. Non-local data, " | |
234 "unknown error", | |
235 type); | |
236 error_handler->OnSingleDatatypeUnrecoverableError(error.location(), | |
237 error.message()); | |
238 } | |
239 return error; | |
147 } | 240 } |
148 } | 241 } |
149 node->Remove(); | 242 node->Remove(); |
150 return true; | 243 return SyncError(); |
151 } | 244 } |
152 | 245 |
153 } // namespace | 246 } // namespace |
154 | 247 |
155 SyncError GenericChangeProcessor::ProcessSyncChanges( | 248 SyncError GenericChangeProcessor::ProcessSyncChanges( |
156 const tracked_objects::Location& from_here, | 249 const tracked_objects::Location& from_here, |
157 const SyncChangeList& list_of_changes) { | 250 const SyncChangeList& list_of_changes) { |
158 DCHECK(CalledOnValidThread()); | 251 DCHECK(CalledOnValidThread()); |
159 sync_api::WriteTransaction trans(from_here, share_handle()); | 252 sync_api::WriteTransaction trans(from_here, share_handle()); |
160 | 253 |
161 for (SyncChangeList::const_iterator iter = list_of_changes.begin(); | 254 for (SyncChangeList::const_iterator iter = list_of_changes.begin(); |
162 iter != list_of_changes.end(); | 255 iter != list_of_changes.end(); |
163 ++iter) { | 256 ++iter) { |
164 const SyncChange& change = *iter; | 257 const SyncChange& change = *iter; |
165 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); | 258 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); |
166 syncable::ModelType type = change.sync_data().GetDataType(); | 259 syncable::ModelType type = change.sync_data().GetDataType(); |
167 std::string type_str = syncable::ModelTypeToString(type); | 260 std::string type_str = syncable::ModelTypeToString(type); |
168 sync_api::WriteNode sync_node(&trans); | 261 sync_api::WriteNode sync_node(&trans); |
169 if (change.change_type() == SyncChange::ACTION_DELETE) { | 262 if (change.change_type() == SyncChange::ACTION_DELETE) { |
170 if (!AttemptDelete(change, &sync_node)) { | 263 SyncError error = AttemptDelete(change, type, type_str, &sync_node, |
264 error_handler()); | |
265 if (error.IsSet()) { | |
171 NOTREACHED(); | 266 NOTREACHED(); |
172 SyncError error(FROM_HERE, | |
173 "Failed to delete " + type_str + " node.", | |
174 type); | |
175 error_handler()->OnSingleDatatypeUnrecoverableError(error.location(), | |
176 error.message()); | |
177 return error; | 267 return error; |
178 } | 268 } |
179 } else if (change.change_type() == SyncChange::ACTION_ADD) { | 269 } else if (change.change_type() == SyncChange::ACTION_ADD) { |
180 // TODO(sync): Handle other types of creation (custom parents, folders, | 270 // TODO(sync): Handle other types of creation (custom parents, folders, |
181 // etc.). | 271 // etc.). |
182 sync_api::ReadNode root_node(&trans); | 272 sync_api::ReadNode root_node(&trans); |
183 if (root_node.InitByTagLookup( | 273 if (root_node.InitByTagLookup( |
184 syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) != | 274 syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) != |
185 sync_api::BaseNode::INIT_OK) { | 275 sync_api::BaseNode::INIT_OK) { |
186 NOTREACHED(); | 276 NOTREACHED(); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 void GenericChangeProcessor::StopImpl() { | 425 void GenericChangeProcessor::StopImpl() { |
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
337 } | 427 } |
338 | 428 |
339 sync_api::UserShare* GenericChangeProcessor::share_handle() const { | 429 sync_api::UserShare* GenericChangeProcessor::share_handle() const { |
340 DCHECK(CalledOnValidThread()); | 430 DCHECK(CalledOnValidThread()); |
341 return share_handle_; | 431 return share_handle_; |
342 } | 432 } |
343 | 433 |
344 } // namespace browser_sync | 434 } // namespace browser_sync |
OLD | NEW |