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

Side by Side Diff: components/favicon/core/favicon_handler.cc

Issue 2891333002: Introduce dedicated enum value for icons from Web Manifests (Closed)
Patch Set: Put browsertest behind #if. Created 3 years, 6 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
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 "components/favicon/core/favicon_handler.h" 5 #include "components/favicon/core/favicon_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 196
197 // static 197 // static
198 int FaviconHandler::GetIconTypesFromHandlerType( 198 int FaviconHandler::GetIconTypesFromHandlerType(
199 FaviconDriverObserver::NotificationIconType handler_type) { 199 FaviconDriverObserver::NotificationIconType handler_type) {
200 switch (handler_type) { 200 switch (handler_type) {
201 case FaviconDriverObserver::NON_TOUCH_16_DIP: 201 case FaviconDriverObserver::NON_TOUCH_16_DIP:
202 case FaviconDriverObserver::NON_TOUCH_LARGEST: 202 case FaviconDriverObserver::NON_TOUCH_LARGEST:
203 return favicon_base::FAVICON; 203 return favicon_base::FAVICON;
204 case FaviconDriverObserver::TOUCH_LARGEST: 204 case FaviconDriverObserver::TOUCH_LARGEST:
205 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON; 205 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON |
206 favicon_base::WEB_MANIFEST_ICON;
206 } 207 }
207 return 0; 208 return 0;
208 } 209 }
209 210
210 void FaviconHandler::FetchFavicon(const GURL& url) { 211 void FaviconHandler::FetchFavicon(const GURL& url) {
211 cancelable_task_tracker_for_page_url_.TryCancelAll(); 212 cancelable_task_tracker_for_page_url_.TryCancelAll();
212 cancelable_task_tracker_for_candidates_.TryCancelAll(); 213 cancelable_task_tracker_for_candidates_.TryCancelAll();
213 214
214 url_ = url; 215 url_ = url;
215 216
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 347
347 // If no manifest available, proceed with the regular candidates only. 348 // If no manifest available, proceed with the regular candidates only.
348 if (manifest_url_.is_empty()) { 349 if (manifest_url_.is_empty()) {
349 OnGotFinalIconURLCandidates(candidates); 350 OnGotFinalIconURLCandidates(candidates);
350 return; 351 return;
351 } 352 }
352 353
353 // See if there is a cached favicon for the manifest. This will update the DB 354 // See if there is a cached favicon for the manifest. This will update the DB
354 // mappings only if the manifest URL is cached. 355 // mappings only if the manifest URL is cached.
355 GetFaviconAndUpdateMappingsUnlessIncognito( 356 GetFaviconAndUpdateMappingsUnlessIncognito(
356 /*icon_url=*/manifest_url_, favicon_base::FAVICON, 357 /*icon_url=*/manifest_url_, favicon_base::WEB_MANIFEST_ICON,
357 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService, 358 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService,
358 base::Unretained(this))); 359 base::Unretained(this)));
359 } 360 }
360 361
361 void FaviconHandler::OnFaviconDataForManifestFromFaviconService( 362 void FaviconHandler::OnFaviconDataForManifestFromFaviconService(
362 const std::vector<favicon_base::FaviconRawBitmapResult>& 363 const std::vector<favicon_base::FaviconRawBitmapResult>&
363 favicon_bitmap_results) { 364 favicon_bitmap_results) {
364 // The database lookup for the page URL is guaranteed to be completed because 365 // The database lookup for the page URL is guaranteed to be completed because
365 // the HistoryBackend uses a SequencedTaskRunner, and we also know that 366 // the HistoryBackend uses a SequencedTaskRunner, and we also know that
366 // FetchFavicon() was called before OnUpdateCandidates(). 367 // FetchFavicon() was called before OnUpdateCandidates().
367 DCHECK(got_favicon_from_history_); 368 DCHECK(got_favicon_from_history_);
368 369
369 bool has_valid_result = HasValidResult(favicon_bitmap_results); 370 bool has_valid_result = HasValidResult(favicon_bitmap_results);
370 bool has_expired_or_incomplete_result = 371 bool has_expired_or_incomplete_result =
371 !has_valid_result || HasExpiredOrIncompleteResult(preferred_icon_size(), 372 !has_valid_result || HasExpiredOrIncompleteResult(preferred_icon_size(),
372 favicon_bitmap_results); 373 favicon_bitmap_results);
373 374
374 if (has_valid_result && (notification_icon_url_ != manifest_url_ || 375 if (has_valid_result &&
375 notification_icon_type_ != favicon_base::FAVICON)) { 376 (notification_icon_url_ != manifest_url_ ||
377 notification_icon_type_ != favicon_base::WEB_MANIFEST_ICON)) {
376 // There is a valid favicon. Notify any observers. It is useful to notify 378 // There is a valid favicon. Notify any observers. It is useful to notify
377 // the observers even if the favicon is expired or incomplete (incorrect 379 // the observers even if the favicon is expired or incomplete (incorrect
378 // size) because temporarily showing the user an expired favicon or 380 // size) because temporarily showing the user an expired favicon or
379 // streched favicon is preferable to showing the user the default favicon. 381 // streched favicon is preferable to showing the user the default favicon.
380 NotifyFaviconUpdated(favicon_bitmap_results); 382 NotifyFaviconUpdated(favicon_bitmap_results);
381 } 383 }
382 384
383 if (has_expired_or_incomplete_result) { 385 if (has_expired_or_incomplete_result) {
384 manifest_download_request_.Reset(base::Bind( 386 manifest_download_request_.Reset(base::Bind(
385 &FaviconHandler::OnDidDownloadManifest, base::Unretained(this))); 387 &FaviconHandler::OnDidDownloadManifest, base::Unretained(this)));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // OnDidDownloadFavicon() can only be called after requesting a download, so 518 // OnDidDownloadFavicon() can only be called after requesting a download, so
517 // |num_image_download_requests_| can never be 0. 519 // |num_image_download_requests_| can never be 0.
518 RecordDownloadAttemptsForHandlerType(handler_type_, 520 RecordDownloadAttemptsForHandlerType(handler_type_,
519 num_image_download_requests_); 521 num_image_download_requests_);
520 // We have either found the ideal candidate or run out of candidates. 522 // We have either found the ideal candidate or run out of candidates.
521 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) { 523 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) {
522 // No more icons to request, set the favicon from the candidate. The 524 // No more icons to request, set the favicon from the candidate. The
523 // manifest URL, if available, is used instead of the icon URL. 525 // manifest URL, if available, is used instead of the icon URL.
524 SetFavicon(manifest_url_.is_empty() ? best_favicon_.candidate.icon_url 526 SetFavicon(manifest_url_.is_empty() ? best_favicon_.candidate.icon_url
525 : manifest_url_, 527 : manifest_url_,
526 best_favicon_.image, best_favicon_.candidate.icon_type); 528 best_favicon_.image,
529 manifest_url_.is_empty() ? best_favicon_.candidate.icon_type
530 : favicon_base::WEB_MANIFEST_ICON);
527 } 531 }
528 // Clear download related state. 532 // Clear download related state.
529 current_candidate_index_ = candidates_.size(); 533 current_candidate_index_ = candidates_.size();
530 num_image_download_requests_ = 0; 534 num_image_download_requests_ = 0;
531 best_favicon_ = DownloadedFavicon(); 535 best_favicon_ = DownloadedFavicon();
532 } 536 }
533 } 537 }
534 538
535 const std::vector<GURL> FaviconHandler::GetIconURLs() const { 539 const std::vector<GURL> FaviconHandler::GetIconURLs() const {
536 std::vector<GURL> icon_urls; 540 std::vector<GURL> icon_urls;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 // A max bitmap size is specified to avoid receiving huge bitmaps in 664 // A max bitmap size is specified to avoid receiving huge bitmaps in
661 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() 665 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload()
662 // for more details about the max bitmap size. 666 // for more details about the max bitmap size.
663 const int download_id = 667 const int download_id =
664 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), 668 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_),
665 image_download_request_.callback()); 669 image_download_request_.callback());
666 DCHECK_NE(download_id, 0); 670 DCHECK_NE(download_id, 0);
667 } 671 }
668 672
669 } // namespace favicon 673 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/favicon_driver_impl.cc ('k') | components/favicon/core/favicon_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698