Chromium Code Reviews| 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/favicon/favicon_handler.h" | 5 #include "chrome/browser/favicon/favicon_handler.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_service.h" | 15 #include "chrome/browser/bookmarks/bookmark_service.h" |
| 16 #include "chrome/browser/favicon/favicon_service_factory.h" | 16 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 17 #include "chrome/browser/favicon/favicon_util.h" | 17 #include "chrome/browser/favicon/favicon_util.h" |
| 18 #include "chrome/browser/history/select_favicon_frames.h" | 18 #include "chrome/browser/history/select_favicon_frames.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "components/favicon/content/content_favicon_driver.h" | |
|
blundell
2014/04/08 10:01:19
This should be the interface class, not the conten
| |
| 20 #include "content/public/browser/favicon_status.h" | 21 #include "content/public/browser/favicon_status.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 22 #include "skia/ext/image_operations.h" | 23 #include "skia/ext/image_operations.h" |
| 23 #include "ui/gfx/codec/png_codec.h" | 24 #include "ui/gfx/codec/png_codec.h" |
| 24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 25 #include "ui/gfx/image/image_skia.h" | 26 #include "ui/gfx/image/image_skia.h" |
| 26 #include "ui/gfx/image/image_util.h" | 27 #include "ui/gfx/image/image_util.h" |
| 27 | 28 |
| 28 using content::FaviconURL; | 29 using content::FaviconURL; |
| 29 using content::NavigationEntry; | 30 using content::NavigationEntry; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 : url(url), | 204 : url(url), |
| 204 image_url(image_url), | 205 image_url(image_url), |
| 205 image(image), | 206 image(image), |
| 206 score(score), | 207 score(score), |
| 207 icon_type(icon_type) { | 208 icon_type(icon_type) { |
| 208 } | 209 } |
| 209 | 210 |
| 210 //////////////////////////////////////////////////////////////////////////////// | 211 //////////////////////////////////////////////////////////////////////////////// |
| 211 | 212 |
| 212 FaviconHandler::FaviconHandler(Profile* profile, | 213 FaviconHandler::FaviconHandler(Profile* profile, |
| 214 FaviconDriver* driver, | |
| 213 FaviconHandlerDelegate* delegate, | 215 FaviconHandlerDelegate* delegate, |
| 214 Type icon_type) | 216 Type icon_type) |
| 215 : got_favicon_from_history_(false), | 217 : got_favicon_from_history_(false), |
| 216 favicon_expired_or_incomplete_(false), | 218 favicon_expired_or_incomplete_(false), |
| 217 icon_types_(icon_type == FAVICON ? chrome::FAVICON : | 219 icon_types_(icon_type == FAVICON |
| 218 chrome::TOUCH_ICON | chrome::TOUCH_PRECOMPOSED_ICON), | 220 ? chrome::FAVICON |
| 221 : chrome::TOUCH_ICON | chrome::TOUCH_PRECOMPOSED_ICON), | |
| 219 profile_(profile), | 222 profile_(profile), |
| 223 driver_(driver), | |
| 220 delegate_(delegate) { | 224 delegate_(delegate) { |
| 221 DCHECK(profile_); | 225 DCHECK(profile_); |
| 226 DCHECK(driver_); | |
| 222 DCHECK(delegate_); | 227 DCHECK(delegate_); |
| 223 } | 228 } |
| 224 | 229 |
| 225 FaviconHandler::~FaviconHandler() { | 230 FaviconHandler::~FaviconHandler() { |
| 226 } | 231 } |
| 227 | 232 |
| 228 void FaviconHandler::FetchFavicon(const GURL& url) { | 233 void FaviconHandler::FetchFavicon(const GURL& url) { |
| 229 cancelable_task_tracker_.TryCancelAll(); | 234 cancelable_task_tracker_.TryCancelAll(); |
| 230 | 235 |
| 231 url_ = url; | 236 url_ = url; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 } | 470 } |
| 466 | 471 |
| 467 void FaviconHandler::SetHistoryFavicons(const GURL& page_url, | 472 void FaviconHandler::SetHistoryFavicons(const GURL& page_url, |
| 468 const GURL& icon_url, | 473 const GURL& icon_url, |
| 469 chrome::IconType icon_type, | 474 chrome::IconType icon_type, |
| 470 const gfx::Image& image) { | 475 const gfx::Image& image) { |
| 471 GetFaviconService()->SetFavicons(page_url, icon_url, icon_type, image); | 476 GetFaviconService()->SetFavicons(page_url, icon_url, icon_type, image); |
| 472 } | 477 } |
| 473 | 478 |
| 474 bool FaviconHandler::ShouldSaveFavicon(const GURL& url) { | 479 bool FaviconHandler::ShouldSaveFavicon(const GURL& url) { |
| 475 if (!profile_->IsOffTheRecord()) | 480 if (!driver_->IsOffTheRecord()) |
| 476 return true; | 481 return true; |
| 477 | 482 |
| 478 // Otherwise store the favicon if the page is bookmarked. | 483 // Otherwise store the favicon if the page is bookmarked. |
| 479 BookmarkService* bookmark_service = | 484 BookmarkService* bookmark_service = |
| 480 BookmarkService::FromBrowserContext(profile_); | 485 BookmarkService::FromBrowserContext(profile_); |
| 481 return bookmark_service && bookmark_service->IsBookmarked(url); | 486 return bookmark_service && bookmark_service->IsBookmarked(url); |
| 482 } | 487 } |
| 483 | 488 |
| 484 void FaviconHandler::NotifyFaviconUpdated(bool icon_url_changed) { | 489 void FaviconHandler::NotifyFaviconUpdated(bool icon_url_changed) { |
| 485 delegate_->NotifyFaviconUpdated(icon_url_changed); | 490 delegate_->NotifyFaviconUpdated(icon_url_changed); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 const GURL& page_url, | 547 const GURL& page_url, |
| 543 const GURL& icon_url, | 548 const GURL& icon_url, |
| 544 chrome::IconType icon_type) { | 549 chrome::IconType icon_type) { |
| 545 if (favicon_expired_or_incomplete_) { | 550 if (favicon_expired_or_incomplete_) { |
| 546 // We have the mapping, but the favicon is out of date. Download it now. | 551 // We have the mapping, but the favicon is out of date. Download it now. |
| 547 ScheduleDownload(page_url, icon_url, icon_type); | 552 ScheduleDownload(page_url, icon_url, icon_type); |
| 548 } else if (GetFaviconService()) { | 553 } else if (GetFaviconService()) { |
| 549 // We don't know the favicon, but we may have previously downloaded the | 554 // We don't know the favicon, but we may have previously downloaded the |
| 550 // favicon for another page that shares the same favicon. Ask for the | 555 // favicon for another page that shares the same favicon. Ask for the |
| 551 // favicon given the favicon URL. | 556 // favicon given the favicon URL. |
| 552 if (profile_->IsOffTheRecord()) { | 557 if (driver_->IsOffTheRecord()) { |
| 553 GetFaviconFromFaviconService( | 558 GetFaviconFromFaviconService( |
| 554 icon_url, icon_type, | 559 icon_url, icon_type, |
| 555 base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this)), | 560 base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this)), |
| 556 &cancelable_task_tracker_); | 561 &cancelable_task_tracker_); |
| 557 } else { | 562 } else { |
| 558 // Ask the history service for the icon. This does two things: | 563 // Ask the history service for the icon. This does two things: |
| 559 // 1. Attempts to fetch the favicon data from the database. | 564 // 1. Attempts to fetch the favicon data from the database. |
| 560 // 2. If the favicon exists in the database, this updates the database to | 565 // 2. If the favicon exists in the database, this updates the database to |
| 561 // include the mapping between the page url and the favicon url. | 566 // include the mapping between the page url and the favicon url. |
| 562 // This is asynchronous. The history service will call back when done. | 567 // This is asynchronous. The history service will call back when done. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 GetMaximalIconSize(icon_type)); | 617 GetMaximalIconSize(icon_type)); |
| 613 if (download_id) { | 618 if (download_id) { |
| 614 // Download ids should be unique. | 619 // Download ids should be unique. |
| 615 DCHECK(download_requests_.find(download_id) == download_requests_.end()); | 620 DCHECK(download_requests_.find(download_id) == download_requests_.end()); |
| 616 download_requests_[download_id] = | 621 download_requests_[download_id] = |
| 617 DownloadRequest(url, image_url, icon_type); | 622 DownloadRequest(url, image_url, icon_type); |
| 618 } | 623 } |
| 619 | 624 |
| 620 return download_id; | 625 return download_id; |
| 621 } | 626 } |
| OLD | NEW |