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/bookmark_change_processor.h" | 5 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
15 #include "chrome/browser/bookmarks/bookmark_utils.h" | 15 #include "chrome/browser/bookmarks/bookmark_utils.h" |
16 #include "chrome/browser/favicon/favicon_service.h" | 16 #include "chrome/browser/favicon/favicon_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "sync/internal_api/public/change_record.h" | 20 #include "sync/internal_api/public/change_record.h" |
21 #include "sync/internal_api/public/read_node.h" | 21 #include "sync/internal_api/public/read_node.h" |
22 #include "sync/internal_api/public/write_node.h" | 22 #include "sync/internal_api/public/write_node.h" |
23 #include "sync/internal_api/public/write_transaction.h" | 23 #include "sync/internal_api/public/write_transaction.h" |
24 #include "sync/syncable/entry.h" // TODO(tim): Investigating bug 121587. | |
25 #include "ui/gfx/image/image_util.h" | 24 #include "ui/gfx/image/image_util.h" |
26 | 25 |
27 using content::BrowserThread; | 26 using content::BrowserThread; |
28 | 27 |
29 namespace browser_sync { | 28 namespace browser_sync { |
30 | 29 |
31 static const char kMobileBookmarksTag[] = "synced_bookmarks"; | 30 static const char kMobileBookmarksTag[] = "synced_bookmarks"; |
32 | 31 |
33 BookmarkChangeProcessor::BookmarkChangeProcessor( | 32 BookmarkChangeProcessor::BookmarkChangeProcessor( |
34 BookmarkModelAssociator* model_associator, | 33 BookmarkModelAssociator* model_associator, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 NOTREACHED() << "Saw update to permanent node!"; | 206 NOTREACHED() << "Saw update to permanent node!"; |
208 return; | 207 return; |
209 } | 208 } |
210 | 209 |
211 // Acquire a scoped write lock via a transaction. | 210 // Acquire a scoped write lock via a transaction. |
212 syncer::WriteTransaction trans(FROM_HERE, share_handle()); | 211 syncer::WriteTransaction trans(FROM_HERE, share_handle()); |
213 | 212 |
214 // Lookup the sync node that's associated with |node|. | 213 // Lookup the sync node that's associated with |node|. |
215 syncer::WriteNode sync_node(&trans); | 214 syncer::WriteNode sync_node(&trans); |
216 if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { | 215 if (!model_associator_->InitSyncNodeFromChromeId(node->id(), &sync_node)) { |
217 // TODO(tim): Investigating bug 121587. | 216 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
218 if (model_associator_->GetSyncIdFromChromeId(node->id()) == | 217 "Failed to load sync node for updated bookmark."); |
219 syncer::kInvalidId) { | |
220 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | |
221 "Bookmark id not found in model associator on BookmarkNodeChanged"); | |
222 LOG(ERROR) << "Bad id."; | |
223 } else if (!sync_node.GetEntry()->good()) { | |
224 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | |
225 "Could not InitByIdLookup on BookmarkNodeChanged, good() failed"); | |
226 LOG(ERROR) << "Bad entry."; | |
227 } else if (sync_node.GetEntry()->Get(syncer::syncable::IS_DEL)) { | |
228 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | |
229 "Could not InitByIdLookup on BookmarkNodeChanged, is_del true"); | |
230 LOG(ERROR) << "Deleted entry."; | |
231 } else { | |
232 syncer::Cryptographer* crypto = trans.GetCryptographer(); | |
233 syncer::ModelTypeSet encrypted_types(crypto->GetEncryptedTypes()); | |
234 const sync_pb::EntitySpecifics& specifics = | |
235 sync_node.GetEntry()->Get(syncer::syncable::SPECIFICS); | |
236 CHECK(specifics.has_encrypted()); | |
237 const bool can_decrypt = crypto->CanDecrypt(specifics.encrypted()); | |
238 const bool agreement = encrypted_types.Has(syncer::BOOKMARKS); | |
239 if (!agreement && !can_decrypt) { | |
240 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | |
241 "Could not InitByIdLookup on BookmarkNodeChanged, " | |
242 " Cryptographer thinks bookmarks not encrypted, and CanDecrypt" | |
243 " failed."); | |
244 LOG(ERROR) << "Case 1."; | |
245 } else if (agreement && can_decrypt) { | |
246 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | |
247 "Could not InitByIdLookup on BookmarkNodeChanged, " | |
248 " Cryptographer thinks bookmarks are encrypted, and CanDecrypt" | |
249 " succeeded (?!), but DecryptIfNecessary failed."); | |
250 LOG(ERROR) << "Case 2."; | |
251 } else if (agreement) { | |
252 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | |
253 "Could not InitByIdLookup on BookmarkNodeChanged, " | |
254 " Cryptographer thinks bookmarks are encrypted, but CanDecrypt" | |
255 " failed."); | |
256 LOG(ERROR) << "Case 3."; | |
257 } else { | |
258 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | |
259 "Could not InitByIdLookup on BookmarkNodeChanged, " | |
260 " Cryptographer thinks bookmarks not encrypted, but CanDecrypt" | |
261 " succeeded (super weird, btw)"); | |
262 LOG(ERROR) << "Case 4."; | |
263 } | |
264 } | |
265 return; | 218 return; |
266 } | 219 } |
267 | 220 |
268 UpdateSyncNodeProperties(node, model, &sync_node); | 221 UpdateSyncNodeProperties(node, model, &sync_node); |
269 | 222 |
270 DCHECK_EQ(sync_node.GetIsFolder(), node->is_folder()); | 223 DCHECK_EQ(sync_node.GetIsFolder(), node->is_folder()); |
271 DCHECK_EQ(model_associator_->GetChromeNodeFromSyncId( | 224 DCHECK_EQ(model_associator_->GetChromeNodeFromSyncId( |
272 sync_node.GetParentId()), | 225 sync_node.GetParentId()), |
273 node->parent()); | 226 node->parent()); |
274 // This node's index should be one more than the predecessor's index. | 227 // This node's index should be one more than the predecessor's index. |
(...skipping 30 matching lines...) Expand all Loading... |
305 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 258 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
306 std::string()); | 259 std::string()); |
307 return; | 260 return; |
308 } | 261 } |
309 } | 262 } |
310 | 263 |
311 void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( | 264 void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( |
312 BookmarkModel* model, | 265 BookmarkModel* model, |
313 const BookmarkNode* node) { | 266 const BookmarkNode* node) { |
314 DCHECK(running()); | 267 DCHECK(running()); |
| 268 // Because favicon changes come from a different thread, it's possible we're |
| 269 // being notified of a favicon change for a url whose bookmark was recently |
| 270 // deleted. Check if we have a sync node for this bookmark, and if not ignore |
| 271 // the favicon change. |
| 272 if (model_associator_->GetSyncIdFromChromeId(node->id()) == |
| 273 syncer::kInvalidId) |
| 274 return; |
315 BookmarkNodeChanged(model, node); | 275 BookmarkNodeChanged(model, node); |
316 } | 276 } |
317 | 277 |
318 void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( | 278 void BookmarkChangeProcessor::BookmarkNodeChildrenReordered( |
319 BookmarkModel* model, const BookmarkNode* node) { | 279 BookmarkModel* model, const BookmarkNode* node) { |
320 | 280 |
321 // Acquire a scoped write lock via a transaction. | 281 // Acquire a scoped write lock via a transaction. |
322 syncer::WriteTransaction trans(FROM_HERE, share_handle()); | 282 syncer::WriteTransaction trans(FROM_HERE, share_handle()); |
323 | 283 |
324 // The given node's children got reordered. We need to reorder all the | 284 // The given node's children got reordered. We need to reorder all the |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 const BookmarkNode* bookmark_node, | 610 const BookmarkNode* bookmark_node, |
651 BookmarkModel* model, | 611 BookmarkModel* model, |
652 syncer::WriteNode* sync_node) { | 612 syncer::WriteNode* sync_node) { |
653 std::vector<unsigned char> favicon_bytes; | 613 std::vector<unsigned char> favicon_bytes; |
654 EncodeFavicon(bookmark_node, model, &favicon_bytes); | 614 EncodeFavicon(bookmark_node, model, &favicon_bytes); |
655 if (!favicon_bytes.empty()) | 615 if (!favicon_bytes.empty()) |
656 sync_node->SetFaviconBytes(favicon_bytes); | 616 sync_node->SetFaviconBytes(favicon_bytes); |
657 } | 617 } |
658 | 618 |
659 } // namespace browser_sync | 619 } // namespace browser_sync |
OLD | NEW |