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

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 2796343003: Remove preferences among favicon types when choosing large icons
Patch Set: Rebased. Created 3 years, 8 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/history/core/browser/history_backend.h" 5 #include "components/history/core/browser/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 const std::vector<GURL>& icon_urls, 1425 const std::vector<GURL>& icon_urls,
1426 int icon_types, 1426 int icon_types,
1427 const std::vector<int>& desired_sizes, 1427 const std::vector<int>& desired_sizes,
1428 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { 1428 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) {
1429 UpdateFaviconMappingsAndFetchImpl(nullptr, icon_urls, icon_types, 1429 UpdateFaviconMappingsAndFetchImpl(nullptr, icon_urls, icon_types,
1430 desired_sizes, bitmap_results); 1430 desired_sizes, bitmap_results);
1431 } 1431 }
1432 1432
1433 void HistoryBackend::GetLargestFaviconForURL( 1433 void HistoryBackend::GetLargestFaviconForURL(
1434 const GURL& page_url, 1434 const GURL& page_url,
1435 const std::vector<int>& icon_types,
1436 int minimum_size_in_pixels,
1437 favicon_base::FaviconRawBitmapResult* favicon_bitmap_result) { 1435 favicon_base::FaviconRawBitmapResult* favicon_bitmap_result) {
1438 DCHECK(favicon_bitmap_result); 1436 DCHECK(favicon_bitmap_result);
1439 1437
1440 if (!db_ || !thumbnail_db_) 1438 if (!db_ || !thumbnail_db_)
1441 return; 1439 return;
1442 1440
1443 TimeTicks beginning_time = TimeTicks::Now(); 1441 TimeTicks beginning_time = TimeTicks::Now();
1444 1442
1445 std::vector<IconMapping> icon_mappings; 1443 std::vector<IconMapping> icon_mappings;
1446 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) || 1444 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) ||
1447 icon_mappings.empty()) 1445 icon_mappings.empty())
1448 return; 1446 return;
1449 1447
1450 int required_icon_types = 0; 1448 // Find the largest bitmap.
1451 for (std::vector<int>::const_iterator i = icon_types.begin(); 1449 FaviconBitmap largest_icon;
1452 i != icon_types.end(); ++i) {
1453 required_icon_types |= *i;
1454 }
1455
1456 // Find the largest bitmap for each IconType placing in
1457 // |largest_favicon_bitmaps|.
1458 std::map<favicon_base::IconType, FaviconBitmap> largest_favicon_bitmaps;
1459 for (std::vector<IconMapping>::const_iterator i = icon_mappings.begin(); 1450 for (std::vector<IconMapping>::const_iterator i = icon_mappings.begin();
1460 i != icon_mappings.end(); ++i) { 1451 i != icon_mappings.end(); ++i) {
1461 if (!(i->icon_type & required_icon_types))
1462 continue;
1463 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; 1452 std::vector<FaviconBitmapIDSize> bitmap_id_sizes;
1464 thumbnail_db_->GetFaviconBitmapIDSizes(i->icon_id, &bitmap_id_sizes); 1453 thumbnail_db_->GetFaviconBitmapIDSizes(i->icon_id, &bitmap_id_sizes);
1465 FaviconBitmap& largest = largest_favicon_bitmaps[i->icon_type];
1466 for (std::vector<FaviconBitmapIDSize>::const_iterator j = 1454 for (std::vector<FaviconBitmapIDSize>::const_iterator j =
1467 bitmap_id_sizes.begin(); 1455 bitmap_id_sizes.begin();
1468 j != bitmap_id_sizes.end(); ++j) { 1456 j != bitmap_id_sizes.end(); ++j) {
1469 if (largest.bitmap_id == 0 || 1457 if (largest_icon.bitmap_id == 0 ||
1470 (largest.pixel_size.width() < j->pixel_size.width() && 1458 (largest_icon.pixel_size.width() < j->pixel_size.width() &&
1471 largest.pixel_size.height() < j->pixel_size.height())) { 1459 largest_icon.pixel_size.height() < j->pixel_size.height())) {
1472 largest.icon_id = i->icon_id; 1460 largest_icon.icon_id = i->icon_id;
1473 largest.bitmap_id = j->bitmap_id; 1461 largest_icon.bitmap_id = j->bitmap_id;
1474 largest.pixel_size = j->pixel_size; 1462 largest_icon.pixel_size = j->pixel_size;
1475 } 1463 }
1476 } 1464 }
1477 } 1465 }
1478 if (largest_favicon_bitmaps.empty()) 1466 if (largest_icon.bitmap_id == 0)
1479 return; 1467 return;
1480 1468
1481 // Find an icon which is larger than minimum_size_in_pixels in the order of
1482 // icon_types.
1483 FaviconBitmap largest_icon;
1484 for (std::vector<int>::const_iterator t = icon_types.begin();
1485 t != icon_types.end(); ++t) {
1486 for (std::map<favicon_base::IconType, FaviconBitmap>::const_iterator f =
1487 largest_favicon_bitmaps.begin();
1488 f != largest_favicon_bitmaps.end(); ++f) {
1489 if (f->first & *t &&
1490 (largest_icon.bitmap_id == 0 ||
1491 (largest_icon.pixel_size.height() < f->second.pixel_size.height() &&
1492 largest_icon.pixel_size.width() < f->second.pixel_size.width()))) {
1493 largest_icon = f->second;
1494 }
1495 }
1496 if (largest_icon.pixel_size.width() > minimum_size_in_pixels &&
1497 largest_icon.pixel_size.height() > minimum_size_in_pixels)
1498 break;
1499 }
1500
1501 GURL icon_url; 1469 GURL icon_url;
1502 favicon_base::IconType icon_type; 1470 favicon_base::IconType icon_type;
1503 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url, 1471 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url,
1504 &icon_type)) { 1472 &icon_type)) {
1505 return; 1473 return;
1506 } 1474 }
1507 1475
1508 base::Time last_updated; 1476 base::Time last_updated;
1509 favicon_base::FaviconRawBitmapResult bitmap_result; 1477 favicon_base::FaviconRawBitmapResult bitmap_result;
1510 bitmap_result.icon_url = icon_url; 1478 bitmap_result.icon_url = icon_url;
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 // transaction is currently open. 2628 // transaction is currently open.
2661 db_->CommitTransaction(); 2629 db_->CommitTransaction();
2662 db_->Vacuum(); 2630 db_->Vacuum();
2663 db_->BeginTransaction(); 2631 db_->BeginTransaction();
2664 db_->GetStartDate(&first_recorded_time_); 2632 db_->GetStartDate(&first_recorded_time_);
2665 2633
2666 return true; 2634 return true;
2667 } 2635 }
2668 2636
2669 } // namespace history 2637 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.h ('k') | components/history/core/browser/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698