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/history/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 // downloading the favicon and invoking SetFavicon. | 1936 // downloading the favicon and invoking SetFavicon. |
1937 request->ForwardResult(request->handle(), favicon); | 1937 request->ForwardResult(request->handle(), favicon); |
1938 } | 1938 } |
1939 | 1939 |
1940 FaviconID HistoryBackend::GetFaviconID( | 1940 FaviconID HistoryBackend::GetFaviconID( |
1941 const std::vector<FaviconIDSize>& favicon_id_size_listing, | 1941 const std::vector<FaviconIDSize>& favicon_id_size_listing, |
1942 const gfx::Size& desired_pixel_size) const { | 1942 const gfx::Size& desired_pixel_size) const { |
1943 // Find favicon size which most closely matches |desired_pixel_size|. | 1943 // Find favicon size which most closely matches |desired_pixel_size|. |
1944 // Give preference to favicon sizes which will result in downscaling rather | 1944 // Give preference to favicon sizes which will result in downscaling rather |
1945 // than upscaling. | 1945 // than upscaling. |
| 1946 // XXX needs to be closer to what cole wants. ideally, we'd just load |
| 1947 // all variants? |
1946 FaviconID closest_favicon_id = 0; | 1948 FaviconID closest_favicon_id = 0; |
1947 gfx::Size closest_pixel_size; | 1949 gfx::Size closest_pixel_size; |
1948 for (size_t i = 0; i < favicon_id_size_listing.size(); ++i) { | 1950 for (size_t i = 0; i < favicon_id_size_listing.size(); ++i) { |
1949 gfx::Size size = favicon_id_size_listing[i].icon_size; | 1951 gfx::Size size = favicon_id_size_listing[i].icon_size; |
1950 if (closest_pixel_size.GetArea() < desired_pixel_size.GetArea() && | 1952 if (closest_pixel_size.GetArea() < desired_pixel_size.GetArea() && |
1951 size.GetArea() > closest_pixel_size.GetArea()) { | 1953 size.GetArea() > closest_pixel_size.GetArea()) { |
1952 closest_favicon_id = favicon_id_size_listing[i].icon_id; | 1954 closest_favicon_id = favicon_id_size_listing[i].icon_id; |
1953 closest_pixel_size = size; | 1955 closest_pixel_size = size; |
1954 } else if (closest_pixel_size.GetArea() > desired_pixel_size.GetArea() && | 1956 } else if (closest_pixel_size.GetArea() > desired_pixel_size.GetArea() && |
1955 size.GetArea() < closest_pixel_size.GetArea() && | 1957 size.GetArea() < closest_pixel_size.GetArea() && |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2545 TimeTicks::Now() - beginning_time); | 2547 TimeTicks::Now() - beginning_time); |
2546 return !icon_mappings.empty(); | 2548 return !icon_mappings.empty(); |
2547 } | 2549 } |
2548 | 2550 |
2549 bool HistoryBackend::GetFaviconFromDB(FaviconID favicon_id, | 2551 bool HistoryBackend::GetFaviconFromDB(FaviconID favicon_id, |
2550 FaviconData* favicon) { | 2552 FaviconData* favicon) { |
2551 Time last_updated; | 2553 Time last_updated; |
2552 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | 2554 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); |
2553 | 2555 |
2554 favicon->known_icon = true; | 2556 favicon->known_icon = true; |
| 2557 favicon->variants.resize(1); // XXX |
2555 if (!thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data->data(), | 2558 if (!thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data->data(), |
2556 &favicon->icon_url, &favicon->pixel_size, &favicon->icon_type)) | 2559 &favicon->icon_url, &favicon->variants[0].pixel_size, |
| 2560 &favicon->icon_type)) |
2557 return false; | 2561 return false; |
2558 | 2562 |
2559 favicon->expired = (Time::Now() - last_updated) > | 2563 favicon->expired = (Time::Now() - last_updated) > |
2560 TimeDelta::FromDays(kFaviconRefetchDays); | 2564 TimeDelta::FromDays(kFaviconRefetchDays); |
2561 favicon->bitmap_data = data; | 2565 favicon->variants[0].bitmap_data = data; |
2562 return true; | 2566 return true; |
2563 } | 2567 } |
2564 | 2568 |
2565 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) { | 2569 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) { |
2566 BriefVisitInfo info; | 2570 BriefVisitInfo info; |
2567 info.url_id = visit.url_id; | 2571 info.url_id = visit.url_id; |
2568 info.time = visit.visit_time; | 2572 info.time = visit.visit_time; |
2569 info.transition = visit.transition; | 2573 info.transition = visit.transition; |
2570 // If we don't have a delegate yet during setup or shutdown, we will drop | 2574 // If we don't have a delegate yet during setup or shutdown, we will drop |
2571 // these notifications. | 2575 // these notifications. |
2572 if (delegate_.get()) | 2576 if (delegate_.get()) |
2573 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 2577 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
2574 } | 2578 } |
2575 | 2579 |
2576 } // namespace history | 2580 } // namespace history |
OLD | NEW |