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

Side by Side Diff: chrome/browser/history/history_backend.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/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 <vector> 10 #include <vector>
(...skipping 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 const GURL& icon_url, 1884 const GURL& icon_url,
1885 scoped_refptr<GetFaviconRequest> request, 1885 scoped_refptr<GetFaviconRequest> request,
1886 int icon_types) { 1886 int icon_types) {
1887 // Check only a single type was given when the page_url was specified. 1887 // Check only a single type was given when the page_url was specified.
1888 DCHECK(!page_url || (page_url && (icon_types == FAVICON || 1888 DCHECK(!page_url || (page_url && (icon_types == FAVICON ||
1889 icon_types == TOUCH_ICON || icon_types == TOUCH_PRECOMPOSED_ICON))); 1889 icon_types == TOUCH_ICON || icon_types == TOUCH_PRECOMPOSED_ICON)));
1890 1890
1891 if (request->canceled()) 1891 if (request->canceled())
1892 return; 1892 return;
1893 1893
1894 FaviconData favicon; 1894 std::vector<history::FaviconBitmapResult> favicon_bitmap_results;
1895 1895
1896 if (thumbnail_db_.get()) { 1896 if (thumbnail_db_.get()) {
1897 IconType icon_type;
1897 const FaviconID favicon_id = 1898 const FaviconID favicon_id =
1898 thumbnail_db_->GetFaviconIDForFaviconURL( 1899 thumbnail_db_->GetFaviconIDForFaviconURL(
1899 icon_url, icon_types, &favicon.icon_type); 1900 icon_url, icon_types, &icon_type);
1900 if (favicon_id) { 1901 if (favicon_id) {
1901 scoped_refptr<base::RefCountedMemory> data; 1902 GetFaviconFromDB(favicon_id, &favicon_bitmap_results);
1902 favicon.known_icon = true;
1903 Time last_updated;
1904 if (thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data,
1905 NULL, NULL)) {
1906 favicon.expired = (Time::Now() - last_updated) >
1907 TimeDelta::FromDays(kFaviconRefetchDays);
1908 favicon.image_data = data;
1909 }
1910 1903
1911 if (page_url) 1904 if (page_url)
1912 SetFaviconMapping(*page_url, favicon_id, favicon.icon_type); 1905 SetFaviconMapping(*page_url, favicon_id, icon_type);
1913 } 1906 }
1914 // else case, haven't cached entry yet. Caller is responsible for 1907 // else case, haven't cached entry yet. Caller is responsible for
1915 // downloading the favicon and invoking SetFavicon. 1908 // downloading the favicon and invoking SetFavicon.
1916 } 1909 }
1917 request->ForwardResult(request->handle(), favicon); 1910 // TODO(pkotwicz): Pass map of |icon_url| to the sizes available from the web
1911 // at |icon_url| instead of an empty map.
1912 request->ForwardResult(request->handle(), favicon_bitmap_results,
1913 IconURLSizesMap());
1918 } 1914 }
1919 1915
1920 void HistoryBackend::GetFaviconForURL( 1916 void HistoryBackend::GetFaviconForURL(
1921 scoped_refptr<GetFaviconRequest> request, 1917 scoped_refptr<GetFaviconRequest> request,
1922 const GURL& page_url, 1918 const GURL& page_url,
1923 int icon_types) { 1919 int icon_types) {
1924 if (request->canceled()) 1920 if (request->canceled())
1925 return; 1921 return;
1926 1922
1927 FaviconData favicon; 1923 std::vector<FaviconBitmapResult> favicon_bitmap_results;
1928 1924
1929 // Get the favicon from DB. 1925 // Get the favicon from DB.
1930 GetFaviconFromDB(page_url, icon_types, &favicon); 1926 GetFaviconFromDB(page_url, icon_types, &favicon_bitmap_results);
1931 1927
1932 request->ForwardResult(request->handle(), favicon); 1928 // TODO(pkotwicz): Pass map of matched icon URLs for |icon_types| to the
1933 } 1929 // sizes that each icon URL is available at from the web instead of an
1934 1930 // empty map.
1935 void HistoryBackend::GetFaviconForID(scoped_refptr<GetFaviconRequest> request, 1931 request->ForwardResult(request->handle(), favicon_bitmap_results,
1936 FaviconID id) { 1932 IconURLSizesMap());
1937 if (request->canceled())
1938 return;
1939
1940 FaviconData favicon;
1941 GetFaviconFromDB(id, &favicon);
1942 request->ForwardResult(request->handle(), favicon);
1943 } 1933 }
1944 1934
1945 void HistoryBackend::SetFavicon( 1935 void HistoryBackend::SetFavicon(
1946 const GURL& page_url, 1936 const GURL& page_url,
1947 const GURL& icon_url, 1937 const GURL& icon_url,
1948 scoped_refptr<base::RefCountedMemory> data, 1938 scoped_refptr<base::RefCountedMemory> data,
1949 IconType icon_type) { 1939 IconType icon_type) {
1950 DCHECK(data.get()); 1940 DCHECK(data.get());
1951 if (!thumbnail_db_.get() || !db_.get()) 1941 if (!thumbnail_db_.get() || !db_.get())
1952 return; 1942 return;
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 2422
2433 BookmarkService* HistoryBackend::GetBookmarkService() { 2423 BookmarkService* HistoryBackend::GetBookmarkService() {
2434 if (bookmark_service_) 2424 if (bookmark_service_)
2435 bookmark_service_->BlockTillLoaded(); 2425 bookmark_service_->BlockTillLoaded();
2436 return bookmark_service_; 2426 return bookmark_service_;
2437 } 2427 }
2438 2428
2439 bool HistoryBackend::GetFaviconFromDB( 2429 bool HistoryBackend::GetFaviconFromDB(
2440 const GURL& page_url, 2430 const GURL& page_url,
2441 int icon_types, 2431 int icon_types,
2442 FaviconData* favicon) { 2432 std::vector<FaviconBitmapResult>* favicon_bitmap_results) {
2443 DCHECK(favicon); 2433 DCHECK(favicon_bitmap_results);
2444 2434
2445 if (!db_.get() || !thumbnail_db_.get()) 2435 if (!db_.get() || !thumbnail_db_.get())
2446 return false; 2436 return false;
2447 2437
2448 bool success = false; 2438 bool success = false;
2449 // Time the query. 2439 // Time the query.
2450 TimeTicks beginning_time = TimeTicks::Now(); 2440 TimeTicks beginning_time = TimeTicks::Now();
2451 2441
2452 std::vector<IconMapping> icon_mappings; 2442 std::vector<IconMapping> icon_mappings;
2453 // Iterate over the known icons looking for one that includes one of the 2443 // Iterate over the known icons looking for one that includes one of the
2454 // requested types. 2444 // requested types.
2455 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) { 2445 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) {
2456 for (std::vector<IconMapping>::iterator i = icon_mappings.begin(); 2446 for (std::vector<IconMapping>::iterator i = icon_mappings.begin();
2457 i != icon_mappings.end(); ++i) { 2447 i != icon_mappings.end(); ++i) {
2458 if ((i->icon_type & icon_types) && 2448 if ((i->icon_type & icon_types) &&
2459 GetFaviconFromDB(i->icon_id, favicon)) { 2449 GetFaviconFromDB(i->icon_id, favicon_bitmap_results)) {
2460 success = true; 2450 success = true;
2461 break; 2451 break;
2462 } 2452 }
2463 } 2453 }
2464 } 2454 }
2465 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name 2455 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name
2466 TimeTicks::Now() - beginning_time); 2456 TimeTicks::Now() - beginning_time);
2467 return success; 2457 return success;
2468 } 2458 }
2469 2459
2470 bool HistoryBackend::GetFaviconFromDB(FaviconID favicon_id, 2460 bool HistoryBackend::GetFaviconFromDB(
2471 FaviconData* favicon) { 2461 FaviconID favicon_id,
2462 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) {
2463 FaviconBitmapResult bitmap_result;
2472 Time last_updated; 2464 Time last_updated;
2473 scoped_refptr<base::RefCountedMemory> data; 2465 if (!thumbnail_db_->GetFavicon(favicon_id,
2466 &last_updated,
2467 &bitmap_result.bitmap_data,
2468 &bitmap_result.icon_url,
2469 &bitmap_result.icon_type)) {
2470 return false;
2471 }
2474 2472
2475 if (!thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data, 2473 bitmap_result.expired = (Time::Now() - last_updated) >
2476 &favicon->icon_url, &favicon->icon_type)) 2474 TimeDelta::FromDays(kFaviconRefetchDays);
2477 return false;
2478 2475
2479 favicon->expired = (Time::Now() - last_updated) > 2476 favicon_bitmap_results->clear();
2480 TimeDelta::FromDays(kFaviconRefetchDays); 2477 if (bitmap_result.is_valid())
2481 favicon->known_icon = true; 2478 favicon_bitmap_results->push_back(bitmap_result);
2482 favicon->image_data = data;
2483 return true; 2479 return true;
2484 } 2480 }
2485 2481
2486 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) { 2482 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) {
2487 BriefVisitInfo info; 2483 BriefVisitInfo info;
2488 info.url_id = visit.url_id; 2484 info.url_id = visit.url_id;
2489 info.time = visit.visit_time; 2485 info.time = visit.visit_time;
2490 info.transition = visit.transition; 2486 info.transition = visit.transition;
2491 // If we don't have a delegate yet during setup or shutdown, we will drop 2487 // If we don't have a delegate yet during setup or shutdown, we will drop
2492 // these notifications. 2488 // these notifications.
2493 if (delegate_.get()) 2489 if (delegate_.get())
2494 delegate_->NotifyVisitDBObserversOnAddVisit(info); 2490 delegate_->NotifyVisitDBObserversOnAddVisit(info);
2495 } 2491 }
2496 2492
2497 } // namespace history 2493 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698