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 NOTREACHED(); | |
144 } | |
145 | |
146 // Should have listed all the possible error cases above. | |
147 NOTREACHED(); | |
tim (not reviewing)
2012/05/14 22:50:08
*extra* unreachable :) One NR() might suffice, but
Ilya Sherman
2012/05/15 00:22:15
Done.
| |
148 return ""; | |
149 } | |
150 | |
151 bool AttemptDelete(const SyncChange& change, | |
152 sync_api::WriteNode* node, | |
153 std::string* error_message) { | |
132 DCHECK_EQ(change.change_type(), SyncChange::ACTION_DELETE); | 154 DCHECK_EQ(change.change_type(), SyncChange::ACTION_DELETE); |
133 if (change.sync_data().IsLocal()) { | 155 if (change.sync_data().IsLocal()) { |
134 const std::string& tag = change.sync_data().GetTag(); | 156 const std::string& tag = change.sync_data().GetTag(); |
135 if (tag.empty()) { | 157 if (tag.empty()) { |
158 *error_message = "Local data, empty tag."; | |
136 return false; | 159 return false; |
137 } | 160 } |
138 if (node->InitByClientTagLookup( | 161 |
139 change.sync_data().GetDataType(), tag) != | 162 sync_api::BaseNode::InitByLookupResult result = |
140 sync_api::BaseNode::INIT_OK) { | 163 node->InitByClientTagLookup(change.sync_data().GetDataType(), tag); |
164 if (result != sync_api::BaseNode::INIT_OK) { | |
165 *error_message = "Local data, " + GetErrorExplanation(result); | |
141 return false; | 166 return false; |
142 } | 167 } |
143 } else { | 168 } else { |
144 if (node->InitByIdLookup(change.sync_data().GetRemoteId()) != | 169 sync_api::BaseNode::InitByLookupResult result = |
145 sync_api::BaseNode::INIT_OK) { | 170 node->InitByIdLookup(change.sync_data().GetRemoteId()); |
171 if (result != sync_api::BaseNode::INIT_OK) { | |
172 *error_message = "Non-local data, " + GetErrorExplanation(result); | |
146 return false; | 173 return false; |
147 } | 174 } |
148 } | 175 } |
149 node->Remove(); | 176 node->Remove(); |
150 return true; | 177 return true; |
151 } | 178 } |
152 | 179 |
153 } // namespace | 180 } // namespace |
154 | 181 |
155 SyncError GenericChangeProcessor::ProcessSyncChanges( | 182 SyncError GenericChangeProcessor::ProcessSyncChanges( |
156 const tracked_objects::Location& from_here, | 183 const tracked_objects::Location& from_here, |
157 const SyncChangeList& list_of_changes) { | 184 const SyncChangeList& list_of_changes) { |
158 DCHECK(CalledOnValidThread()); | 185 DCHECK(CalledOnValidThread()); |
159 sync_api::WriteTransaction trans(from_here, share_handle()); | 186 sync_api::WriteTransaction trans(from_here, share_handle()); |
160 | 187 |
161 for (SyncChangeList::const_iterator iter = list_of_changes.begin(); | 188 for (SyncChangeList::const_iterator iter = list_of_changes.begin(); |
162 iter != list_of_changes.end(); | 189 iter != list_of_changes.end(); |
163 ++iter) { | 190 ++iter) { |
164 const SyncChange& change = *iter; | 191 const SyncChange& change = *iter; |
165 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); | 192 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); |
166 syncable::ModelType type = change.sync_data().GetDataType(); | 193 syncable::ModelType type = change.sync_data().GetDataType(); |
167 std::string type_str = syncable::ModelTypeToString(type); | 194 std::string type_str = syncable::ModelTypeToString(type); |
168 sync_api::WriteNode sync_node(&trans); | 195 sync_api::WriteNode sync_node(&trans); |
169 if (change.change_type() == SyncChange::ACTION_DELETE) { | 196 if (change.change_type() == SyncChange::ACTION_DELETE) { |
170 if (!AttemptDelete(change, &sync_node)) { | 197 std::string error_message; |
198 if (!AttemptDelete(change, &sync_node, &error_message)) { | |
171 NOTREACHED(); | 199 NOTREACHED(); |
172 SyncError error(FROM_HERE, | 200 SyncError error( |
173 "Failed to delete " + type_str + " node.", | 201 FROM_HERE, |
174 type); | 202 "Failed to delete " + type_str + " node. " + error_message, |
203 type); | |
175 error_handler()->OnSingleDatatypeUnrecoverableError(error.location(), | 204 error_handler()->OnSingleDatatypeUnrecoverableError(error.location(), |
tim (not reviewing)
2012/05/14 22:50:08
So, unfortunately this is actually the line that w
Ilya Sherman
2012/05/15 00:22:15
Ok, assuming I've understood things correctly, I b
| |
176 error.message()); | 205 error.message()); |
177 return error; | 206 return error; |
178 } | 207 } |
179 } else if (change.change_type() == SyncChange::ACTION_ADD) { | 208 } else if (change.change_type() == SyncChange::ACTION_ADD) { |
180 // TODO(sync): Handle other types of creation (custom parents, folders, | 209 // TODO(sync): Handle other types of creation (custom parents, folders, |
181 // etc.). | 210 // etc.). |
182 sync_api::ReadNode root_node(&trans); | 211 sync_api::ReadNode root_node(&trans); |
183 if (root_node.InitByTagLookup( | 212 if (root_node.InitByTagLookup( |
184 syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) != | 213 syncable::ModelTypeToRootTag(change.sync_data().GetDataType())) != |
185 sync_api::BaseNode::INIT_OK) { | 214 sync_api::BaseNode::INIT_OK) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 void GenericChangeProcessor::StopImpl() { | 364 void GenericChangeProcessor::StopImpl() { |
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
337 } | 366 } |
338 | 367 |
339 sync_api::UserShare* GenericChangeProcessor::share_handle() const { | 368 sync_api::UserShare* GenericChangeProcessor::share_handle() const { |
340 DCHECK(CalledOnValidThread()); | 369 DCHECK(CalledOnValidThread()); |
341 return share_handle_; | 370 return share_handle_; |
342 } | 371 } |
343 | 372 |
344 } // namespace browser_sync | 373 } // namespace browser_sync |
OLD | NEW |