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

Side by Side Diff: chrome/browser/sync/glue/bookmark_change_processor.cc

Issue 9570055: [Sync] Add support for associating a new Synced Bookmarks node. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, address comments Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/sync/glue/bookmark_model_associator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/sync/internal_api/write_transaction.h" 21 #include "chrome/browser/sync/internal_api/write_transaction.h"
22 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "ui/gfx/codec/png_codec.h" 25 #include "ui/gfx/codec/png_codec.h"
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 28
29 namespace browser_sync { 29 namespace browser_sync {
30 30
31 static const char kMobileBookmarksTag[] = "synced_bookmarks";
32
31 BookmarkChangeProcessor::BookmarkChangeProcessor( 33 BookmarkChangeProcessor::BookmarkChangeProcessor(
32 BookmarkModelAssociator* model_associator, 34 BookmarkModelAssociator* model_associator,
33 DataTypeErrorHandler* error_handler) 35 DataTypeErrorHandler* error_handler)
34 : ChangeProcessor(error_handler), 36 : ChangeProcessor(error_handler),
35 bookmark_model_(NULL), 37 bookmark_model_(NULL),
36 model_associator_(model_associator) { 38 model_associator_(model_associator) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
38 DCHECK(model_associator); 40 DCHECK(model_associator);
39 DCHECK(error_handler); 41 DCHECK(error_handler);
40 } 42 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 passed_deletes = true; 444 passed_deletes = true;
443 445
444 sync_api::ReadNode src(trans); 446 sync_api::ReadNode src(trans);
445 if (!src.InitByIdLookup(it->id)) { 447 if (!src.InitByIdLookup(it->id)) {
446 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 448 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
447 "ApplyModelChanges was passed a bad ID"); 449 "ApplyModelChanges was passed a bad ID");
448 return; 450 return;
449 } 451 }
450 452
451 if (!CreateOrUpdateBookmarkNode(&src, model)) { 453 if (!CreateOrUpdateBookmarkNode(&src, model)) {
452 error_handler()->OnUnrecoverableError(FROM_HERE, 454 // Because the Synced Bookmarks node can be created server side, it's
453 "Failed to create bookmark node with title " + 455 // possible it'll arrive at the client as an update. In that case it
454 src.GetTitle() + " and url " + 456 // won't have been associated at startup, the GetChromeNodeFromSyncId
455 src.GetURL().possibly_invalid_spec()); 457 // call above will return NULL, and we won't detect it as a permanent
456 return; 458 // node, resulting in us trying to create it here (which will
459 // fail). Therefore, we add special logic here just to detect the
460 // Synced Bookmarks folder.
461 sync_api::ReadNode synced_bookmarks(trans);
462 if (synced_bookmarks.InitByTagLookup(kMobileBookmarksTag) &&
463 synced_bookmarks.GetId() == it->id) {
464 // This is a newly created Synced Bookmarks node. Associate it.
465 model_associator_->Associate(model->mobile_node(), it->id);
466 } else {
467 // We ignore bookmarks we can't add. Chances are this is caused by
468 // a bookmark that was not fully associated.
469 LOG(ERROR) << "Failed to create bookmark node with title "
470 << src.GetTitle() + " and url "
471 << src.GetURL().possibly_invalid_spec();
472 }
457 } 473 }
458 } 474 }
459 } 475 }
460 // Clean up the temporary node. 476 // Clean up the temporary node.
461 if (foster_parent) { 477 if (foster_parent) {
462 // There should be no nodes left under the foster parent. 478 // There should be no nodes left under the foster parent.
463 DCHECK_EQ(foster_parent->child_count(), 0); 479 DCHECK_EQ(foster_parent->child_count(), 0);
464 model->Remove(foster_parent->parent(), 480 model->Remove(foster_parent->parent(),
465 foster_parent->parent()->GetIndexOf(foster_parent)); 481 foster_parent->parent()->GetIndexOf(foster_parent));
466 foster_parent = NULL; 482 foster_parent = NULL;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 const BookmarkNode* bookmark_node, 600 const BookmarkNode* bookmark_node,
585 BookmarkModel* model, 601 BookmarkModel* model,
586 sync_api::WriteNode* sync_node) { 602 sync_api::WriteNode* sync_node) {
587 std::vector<unsigned char> favicon_bytes; 603 std::vector<unsigned char> favicon_bytes;
588 EncodeFavicon(bookmark_node, model, &favicon_bytes); 604 EncodeFavicon(bookmark_node, model, &favicon_bytes);
589 if (!favicon_bytes.empty()) 605 if (!favicon_bytes.empty())
590 sync_node->SetFaviconBytes(favicon_bytes); 606 sync_node->SetFaviconBytes(favicon_bytes);
591 } 607 }
592 608
593 } // namespace browser_sync 609 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/glue/bookmark_model_associator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698