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

Side by Side Diff: chrome/browser/bookmarks/bookmark_html_writer.cc

Issue 10870022: Change FaviconData to be able to return data for multiple bitmaps for same icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
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/bookmarks/bookmark_html_writer.h" 5 #include "chrome/browser/bookmarks/bookmark_html_writer.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/history/history_types.h" 24 #include "chrome/browser/history/history_types.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
27 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
29 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
30 #include "net/base/escape.h" 30 #include "net/base/escape.h"
31 #include "net/base/file_stream.h" 31 #include "net/base/file_stream.h"
32 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
33 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/gfx/favicon_size.h"
34 35
35 using content::BrowserThread; 36 using content::BrowserThread;
36 37
37 namespace { 38 namespace {
38 39
39 static BookmarkFaviconFetcher* fetcher = NULL; 40 static BookmarkFaviconFetcher* fetcher = NULL;
40 41
41 // File header. 42 // File header.
42 const char kHeader[] = 43 const char kHeader[] =
43 "<!DOCTYPE NETSCAPE-Bookmark-file-1>\r\n" 44 "<!DOCTYPE NETSCAPE-Bookmark-file-1>\r\n"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 if (bookmark_urls_.empty()) { 454 if (bookmark_urls_.empty()) {
454 return false; 455 return false;
455 } 456 }
456 do { 457 do {
457 std::string url = bookmark_urls_.front(); 458 std::string url = bookmark_urls_.front();
458 // Filter out urls that we've already got favicon for. 459 // Filter out urls that we've already got favicon for.
459 URLFaviconMap::const_iterator iter = favicons_map_->find(url); 460 URLFaviconMap::const_iterator iter = favicons_map_->find(url);
460 if (favicons_map_->end() == iter) { 461 if (favicons_map_->end() == iter) {
461 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 462 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
462 profile_, Profile::EXPLICIT_ACCESS); 463 profile_, Profile::EXPLICIT_ACCESS);
463 favicon_service->GetFaviconForURL(profile_, GURL(url), history::FAVICON, 464 favicon_service->GetRawFaviconForURL(profile_, GURL(url),
465 history::FAVICON, gfx::kFaviconSize, ui::SCALE_FACTOR_100P,
464 &favicon_consumer_, 466 &favicon_consumer_,
465 base::Bind(&BookmarkFaviconFetcher::OnFaviconDataAvailable, 467 base::Bind(&BookmarkFaviconFetcher::OnFaviconDataAvailable,
466 base::Unretained(this))); 468 base::Unretained(this)));
467 return true; 469 return true;
468 } else { 470 } else {
469 bookmark_urls_.pop_front(); 471 bookmark_urls_.pop_front();
470 } 472 }
471 } while (!bookmark_urls_.empty()); 473 } while (!bookmark_urls_.empty());
472 return false; 474 return false;
473 } 475 }
474 476
475 void BookmarkFaviconFetcher::OnFaviconDataAvailable( 477 void BookmarkFaviconFetcher::OnFaviconDataAvailable(
476 FaviconService::Handle handle, 478 FaviconService::Handle handle,
477 history::FaviconData favicon) { 479 const history::FaviconBitmapResult& bitmap_result) {
478 GURL url; 480 GURL url;
479 if (!bookmark_urls_.empty()) { 481 if (!bookmark_urls_.empty()) {
480 url = GURL(bookmark_urls_.front()); 482 url = GURL(bookmark_urls_.front());
481 bookmark_urls_.pop_front(); 483 bookmark_urls_.pop_front();
482 } 484 }
483 if (favicon.is_valid() && !url.is_empty()) { 485 if (bitmap_result.is_valid() && !url.is_empty()) {
484 favicons_map_->insert(make_pair(url.spec(), favicon.image_data)); 486 favicons_map_->insert(
487 make_pair(url.spec(), bitmap_result.bitmap_data));
485 } 488 }
486 489
487 if (FetchNextFavicon()) { 490 if (FetchNextFavicon()) {
488 return; 491 return;
489 } 492 }
490 ExecuteWriter(); 493 ExecuteWriter();
491 } 494 }
492 495
493 namespace bookmark_html_writer { 496 namespace bookmark_html_writer {
494 497
495 void WriteBookmarks(Profile* profile, 498 void WriteBookmarks(Profile* profile,
496 const FilePath& path, 499 const FilePath& path,
497 BookmarksExportObserver* observer) { 500 BookmarksExportObserver* observer) {
498 // BookmarkModel isn't thread safe (nor would we want to lock it down 501 // BookmarkModel isn't thread safe (nor would we want to lock it down
499 // for the duration of the write), as such we make a copy of the 502 // for the duration of the write), as such we make a copy of the
500 // BookmarkModel using BookmarkCodec then write from that. 503 // BookmarkModel using BookmarkCodec then write from that.
501 if (fetcher == NULL) { 504 if (fetcher == NULL) {
502 fetcher = new BookmarkFaviconFetcher(profile, path, observer); 505 fetcher = new BookmarkFaviconFetcher(profile, path, observer);
503 fetcher->ExportBookmarks(); 506 fetcher->ExportBookmarks();
504 } 507 }
505 } 508 }
506 509
507 } // namespace bookmark_html_writer 510 } // namespace bookmark_html_writer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698