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

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

Issue 5149001: Merge 65840 - Provide sync integration tests with a way to set a favicon for ... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/552d/src/
Patch Set: Created 10 years, 1 month 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/string16.h" 10 #include "base/string16.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // Set the properties of the item. 52 // Set the properties of the item.
53 dst->SetIsFolder(src->is_folder()); 53 dst->SetIsFolder(src->is_folder());
54 dst->SetTitle(UTF16ToWideHack(src->GetTitle())); 54 dst->SetTitle(UTF16ToWideHack(src->GetTitle()));
55 if (!src->is_folder()) 55 if (!src->is_folder())
56 dst->SetURL(src->GetURL()); 56 dst->SetURL(src->GetURL());
57 SetSyncNodeFavicon(src, model, dst); 57 SetSyncNodeFavicon(src, model, dst);
58 } 58 }
59 59
60 // static 60 // static
61 void BookmarkChangeProcessor::EncodeFavicon(const BookmarkNode* src, 61 void BookmarkChangeProcessor::EncodeFavicon(const BookmarkNode* src,
62 BookmarkModel* model, 62 BookmarkModel* model,
63 std::vector<unsigned char>* dst) { 63 std::vector<unsigned char>* dst) {
64 const SkBitmap& favicon = model->GetFavIcon(src); 64 const SkBitmap& favicon = model->GetFavIcon(src);
65 65
66 dst->clear(); 66 dst->clear();
67 67
68 // Check for zero-dimension images. This can happen if the favicon is 68 // Check for zero-dimension images. This can happen if the favicon is
69 // still being loaded. 69 // still being loaded.
70 if (favicon.empty()) 70 if (favicon.empty())
71 return; 71 return;
72 72
73 // Re-encode the BookmarkNode's favicon as a PNG, and pass the data to the 73 // Re-encode the BookmarkNode's favicon as a PNG, and pass the data to the
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Sets the favicon of the given bookmark node from the given sync node. 501 // Sets the favicon of the given bookmark node from the given sync node.
502 bool BookmarkChangeProcessor::SetBookmarkFavicon( 502 bool BookmarkChangeProcessor::SetBookmarkFavicon(
503 sync_api::BaseNode* sync_node, 503 sync_api::BaseNode* sync_node,
504 const BookmarkNode* bookmark_node, 504 const BookmarkNode* bookmark_node,
505 Profile* profile) { 505 Profile* profile) {
506 std::vector<unsigned char> icon_bytes_vector; 506 std::vector<unsigned char> icon_bytes_vector;
507 sync_node->GetFaviconBytes(&icon_bytes_vector); 507 sync_node->GetFaviconBytes(&icon_bytes_vector);
508 if (icon_bytes_vector.empty()) 508 if (icon_bytes_vector.empty())
509 return false; 509 return false;
510 510
511 ApplyBookmarkFavicon(bookmark_node, profile, icon_bytes_vector);
512
513 return true;
514 }
515
516 // static
517 // Applies the given favicon bytes vector to the given bookmark node.
518 void BookmarkChangeProcessor::ApplyBookmarkFavicon(
519 const BookmarkNode* bookmark_node,
520 Profile* profile,
521 const std::vector<unsigned char>& icon_bytes_vector) {
511 // Registering a favicon requires that we provide a source URL, but we 522 // Registering a favicon requires that we provide a source URL, but we
512 // don't know where these came from. Currently we just use the 523 // don't know where these came from. Currently we just use the
513 // destination URL, which is not correct, but since the favicon URL 524 // destination URL, which is not correct, but since the favicon URL
514 // is used as a key in the history's thumbnail DB, this gives us a value 525 // is used as a key in the history's thumbnail DB, this gives us a value
515 // which does not collide with others. 526 // which does not collide with others.
516 GURL fake_icon_url = bookmark_node->GetURL(); 527 GURL fake_icon_url = bookmark_node->GetURL();
517 528
518 HistoryService* history = 529 HistoryService* history =
519 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 530 profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
520 FaviconService* favicon_service = 531 FaviconService* favicon_service =
521 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); 532 profile->GetFaviconService(Profile::EXPLICIT_ACCESS);
522 533
523 history->AddPage(bookmark_node->GetURL(), history::SOURCE_SYNCED); 534 history->AddPage(bookmark_node->GetURL(), history::SOURCE_SYNCED);
524 favicon_service->SetFavicon(bookmark_node->GetURL(), 535 favicon_service->SetFavicon(bookmark_node->GetURL(),
525 fake_icon_url, 536 fake_icon_url,
526 icon_bytes_vector); 537 icon_bytes_vector);
527
528 return true;
529 } 538 }
530 539
531 // static 540 // static
532 void BookmarkChangeProcessor::SetSyncNodeFavicon( 541 void BookmarkChangeProcessor::SetSyncNodeFavicon(
533 const BookmarkNode* bookmark_node, 542 const BookmarkNode* bookmark_node,
534 BookmarkModel* model, 543 BookmarkModel* model,
535 sync_api::WriteNode* sync_node) { 544 sync_api::WriteNode* sync_node) {
536 std::vector<unsigned char> favicon_bytes; 545 std::vector<unsigned char> favicon_bytes;
537 EncodeFavicon(bookmark_node, model, &favicon_bytes); 546 EncodeFavicon(bookmark_node, model, &favicon_bytes);
538 if (!favicon_bytes.empty()) 547 if (!favicon_bytes.empty())
539 sync_node->SetFaviconBytes(favicon_bytes); 548 sync_node->SetFaviconBytes(favicon_bytes);
540 } 549 }
541 550
542 } // namespace browser_sync 551 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_change_processor.h ('k') | chrome/test/live_sync/bookmark_model_verifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698