Chromium Code Reviews| 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 std::string GetErrorExplanation(sync_api::BaseNode::InitByLookupResult result) { | |
| 133 switch (result) { | |
| 134 case sync_api::BaseNode::INIT_FAILED_ENTRY_NOT_GOOD: | |
| 135 return " could not find entry matching the lookup criteria."; | |
| 136 case sync_api::BaseNode::INIT_FAILED_ENTRY_IS_DEL: | |
| 137 return " entry is already deleted."; | |
| 138 case sync_api::BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY: | |
| 139 return " unable to decrypt."; | |
| 140 case sync_api::BaseNode::INIT_FAILED_PRECONDITION: | |
| 141 return " a precondition was not met for calling init."; | |
| 142 default: | |
| 143 // Should have listed all the possible error cases above. | |
| 144 NOTREACHED(); | |
| 145 return ""; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 SyncError AttemptDelete(const SyncChange& change, | |
| 150 syncable::ModelType type, | |
| 151 std::string type_str, | |
| 152 sync_api::WriteNode* node) { | |
| 132 DCHECK_EQ(change.change_type(), SyncChange::ACTION_DELETE); | 153 DCHECK_EQ(change.change_type(), SyncChange::ACTION_DELETE); |
| 133 if (change.sync_data().IsLocal()) { | 154 if (change.sync_data().IsLocal()) { |
| 134 const std::string& tag = change.sync_data().GetTag(); | 155 const std::string& tag = change.sync_data().GetTag(); |
| 135 if (tag.empty()) { | 156 if (tag.empty()) { |
| 136 return false; | 157 return SyncError( |
| 158 FROM_HERE, | |
| 159 "Failed to delete " + type_str + " node. Local data, empty tag.", | |
| 160 type); | |
| 137 } | 161 } |
| 138 if (node->InitByClientTagLookup( | 162 |
| 139 change.sync_data().GetDataType(), tag) != | 163 sync_api::BaseNode::InitByLookupResult result = |
| 140 sync_api::BaseNode::INIT_OK) { | 164 node->InitByClientTagLookup(change.sync_data().GetDataType(), tag); |
| 141 return false; | 165 if (result != sync_api::BaseNode::INIT_OK) { |
| 166 return SyncError(FROM_HERE, | |
| 167 "Failed to delete " + type_str + " node. " | |
| 168 "Local data, " + GetErrorExplanation(result), | |
| 169 type); | |
| 142 } | 170 } |
| 143 } else { | 171 } else { |
| 144 if (node->InitByIdLookup(change.sync_data().GetRemoteId()) != | 172 sync_api::BaseNode::InitByLookupResult result = |
| 145 sync_api::BaseNode::INIT_OK) { | 173 node->InitByIdLookup(change.sync_data().GetRemoteId()); |
| 146 return false; | 174 if (result != sync_api::BaseNode::INIT_OK) { |
| 175 return SyncError(FROM_HERE, | |
| 176 "Failed to delete " + type_str + " node. " | |
| 177 "Non-local data, " + GetErrorExplanation(result), | |
| 178 type); | |
| 147 } | 179 } |
| 148 } | 180 } |
| 149 node->Remove(); | 181 node->Remove(); |
| 150 return true; | 182 return SyncError(); |
| 151 } | 183 } |
| 152 | 184 |
| 153 } // namespace | 185 } // namespace |
| 154 | 186 |
| 155 SyncError GenericChangeProcessor::ProcessSyncChanges( | 187 SyncError GenericChangeProcessor::ProcessSyncChanges( |
| 156 const tracked_objects::Location& from_here, | 188 const tracked_objects::Location& from_here, |
| 157 const SyncChangeList& list_of_changes) { | 189 const SyncChangeList& list_of_changes) { |
| 158 DCHECK(CalledOnValidThread()); | 190 DCHECK(CalledOnValidThread()); |
| 159 sync_api::WriteTransaction trans(from_here, share_handle()); | 191 sync_api::WriteTransaction trans(from_here, share_handle()); |
| 160 | 192 |
| 161 for (SyncChangeList::const_iterator iter = list_of_changes.begin(); | 193 for (SyncChangeList::const_iterator iter = list_of_changes.begin(); |
| 162 iter != list_of_changes.end(); | 194 iter != list_of_changes.end(); |
| 163 ++iter) { | 195 ++iter) { |
| 164 const SyncChange& change = *iter; | 196 const SyncChange& change = *iter; |
| 165 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); | 197 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); |
| 166 syncable::ModelType type = change.sync_data().GetDataType(); | 198 syncable::ModelType type = change.sync_data().GetDataType(); |
| 167 std::string type_str = syncable::ModelTypeToString(type); | 199 std::string type_str = syncable::ModelTypeToString(type); |
| 168 sync_api::WriteNode sync_node(&trans); | 200 sync_api::WriteNode sync_node(&trans); |
| 169 if (change.change_type() == SyncChange::ACTION_DELETE) { | 201 if (change.change_type() == SyncChange::ACTION_DELETE) { |
| 170 if (!AttemptDelete(change, &sync_node)) { | 202 SyncError error = AttemptDelete(change, type, type_str, &sync_node); |
|
tim (not reviewing)
2012/05/15 16:44:12
This still doesn't quite do it :P Think of OnSingl
Ilya Sherman
2012/05/16 00:43:06
*sigh* ok, new patch set up... lots of repeated co
| |
| 203 if (error.IsSet()) { | |
| 171 NOTREACHED(); | 204 NOTREACHED(); |
| 172 SyncError error(FROM_HERE, | |
| 173 "Failed to delete " + type_str + " node.", | |
| 174 type); | |
| 175 error_handler()->OnSingleDatatypeUnrecoverableError(error.location(), | 205 error_handler()->OnSingleDatatypeUnrecoverableError(error.location(), |
| 176 error.message()); | 206 error.message()); |
| 177 return error; | 207 return error; |
| 178 } | 208 } |
| 179 } else if (change.change_type() == SyncChange::ACTION_ADD) { | 209 } else if (change.change_type() == SyncChange::ACTION_ADD) { |
| 180 // TODO(sync): Handle other types of creation (custom parents, folders, | 210 // TODO(sync): Handle other types of creation (custom parents, folders, |
| 181 // etc.). | 211 // etc.). |
| 182 sync_api::ReadNode root_node(&trans); | 212 sync_api::ReadNode root_node(&trans); |
| 183 if (root_node.InitByTagLookup( | 213 if (root_node.InitByTagLookup( |
| 184 syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) != | 214 syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) != |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 void GenericChangeProcessor::StopImpl() { | 365 void GenericChangeProcessor::StopImpl() { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 337 } | 367 } |
| 338 | 368 |
| 339 sync_api::UserShare* GenericChangeProcessor::share_handle() const { | 369 sync_api::UserShare* GenericChangeProcessor::share_handle() const { |
| 340 DCHECK(CalledOnValidThread()); | 370 DCHECK(CalledOnValidThread()); |
| 341 return share_handle_; | 371 return share_handle_; |
| 342 } | 372 } |
| 343 | 373 |
| 344 } // namespace browser_sync | 374 } // namespace browser_sync |
| OLD | NEW |