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

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 Time last_updated;
1903 if (thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data,
1904 NULL, NULL)) {
1905 favicon.known_icon = true;
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
1929 // sizes that each icon URL is available at from the web instead of an
1930 // empty map.
1931 request->ForwardResult(request->handle(), favicon_bitmap_results,
1932 IconURLSizesMap());
1933 } 1933 }
1934 1934
1935 void HistoryBackend::GetFaviconForID(scoped_refptr<GetFaviconRequest> request, 1935 void HistoryBackend::GetFaviconForID(scoped_refptr<GetFaviconRequest> request,
1936 FaviconID id) { 1936 FaviconID id) {
1937 if (request->canceled()) 1937 if (request->canceled())
1938 return; 1938 return;
1939 1939
1940 FaviconData favicon; 1940 std::vector<FaviconBitmapResult> favicon_bitmap_results;
1941 GetFaviconFromDB(id, &favicon); 1941
1942 request->ForwardResult(request->handle(), favicon); 1942 // Get the favicon from DB.
1943 GetFaviconFromDB(id, &favicon_bitmap_results);
1944
1945 // TODO(pkotwicz): Pass map of the matched icon URL to the sizes that it is
1946 // available from the web instead of an empty map.
1947 request->ForwardResult(request->handle(), favicon_bitmap_results,
1948 IconURLSizesMap());
1943 } 1949 }
1944 1950
1945 void HistoryBackend::SetFavicon( 1951 void HistoryBackend::SetFavicon(
1946 const GURL& page_url, 1952 const GURL& page_url,
1947 const GURL& icon_url, 1953 const GURL& icon_url,
1948 scoped_refptr<base::RefCountedMemory> data, 1954 scoped_refptr<base::RefCountedMemory> data,
1949 IconType icon_type) { 1955 IconType icon_type) {
1950 DCHECK(data.get()); 1956 DCHECK(data.get());
1951 if (!thumbnail_db_.get() || !db_.get()) 1957 if (!thumbnail_db_.get() || !db_.get())
1952 return; 1958 return;
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2434 2440
2435 BookmarkService* HistoryBackend::GetBookmarkService() { 2441 BookmarkService* HistoryBackend::GetBookmarkService() {
2436 if (bookmark_service_) 2442 if (bookmark_service_)
2437 bookmark_service_->BlockTillLoaded(); 2443 bookmark_service_->BlockTillLoaded();
2438 return bookmark_service_; 2444 return bookmark_service_;
2439 } 2445 }
2440 2446
2441 bool HistoryBackend::GetFaviconFromDB( 2447 bool HistoryBackend::GetFaviconFromDB(
2442 const GURL& page_url, 2448 const GURL& page_url,
2443 int icon_types, 2449 int icon_types,
2444 FaviconData* favicon) { 2450 std::vector<FaviconBitmapResult>* favicon_bitmap_results) {
2445 DCHECK(favicon); 2451 DCHECK(favicon_bitmap_results);
2446 2452
2447 if (!db_.get() || !thumbnail_db_.get()) 2453 if (!db_.get() || !thumbnail_db_.get())
2448 return false; 2454 return false;
2449 2455
2450 bool success = false; 2456 bool success = false;
2451 // Time the query. 2457 // Time the query.
2452 TimeTicks beginning_time = TimeTicks::Now(); 2458 TimeTicks beginning_time = TimeTicks::Now();
2453 2459
2454 std::vector<IconMapping> icon_mappings; 2460 std::vector<IconMapping> icon_mappings;
2455 // Iterate over the known icons looking for one that includes one of the 2461 // Iterate over the known icons looking for one that includes one of the
2456 // requested types. 2462 // requested types.
2457 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) { 2463 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) {
2458 for (std::vector<IconMapping>::iterator i = icon_mappings.begin(); 2464 for (std::vector<IconMapping>::iterator i = icon_mappings.begin();
2459 i != icon_mappings.end(); ++i) { 2465 i != icon_mappings.end(); ++i) {
2460 if ((i->icon_type & icon_types) && 2466 if ((i->icon_type & icon_types) &&
2461 GetFaviconFromDB(i->icon_id, favicon)) { 2467 GetFaviconFromDB(i->icon_id, favicon_bitmap_results)) {
2462 success = true; 2468 success = true;
2463 break; 2469 break;
2464 } 2470 }
2465 } 2471 }
2466 } 2472 }
2467 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name 2473 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name
2468 TimeTicks::Now() - beginning_time); 2474 TimeTicks::Now() - beginning_time);
2469 return success; 2475 return success;
2470 } 2476 }
2471 2477
2472 bool HistoryBackend::GetFaviconFromDB(FaviconID favicon_id, 2478 bool HistoryBackend::GetFaviconFromDB(
2473 FaviconData* favicon) { 2479 FaviconID favicon_id,
2480 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) {
2481 FaviconBitmapResult bitmap_result;
2474 Time last_updated; 2482 Time last_updated;
2475 scoped_refptr<base::RefCountedMemory> data; 2483 if (!thumbnail_db_->GetFavicon(favicon_id,
2484 &last_updated,
2485 &bitmap_result.bitmap_data,
2486 &bitmap_result.icon_url,
2487 &bitmap_result.icon_type)) {
2488 return false;
2489 }
2476 2490
2477 if (!thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data, 2491 bitmap_result.expired = (Time::Now() - last_updated) >
2478 &favicon->icon_url, &favicon->icon_type)) 2492 TimeDelta::FromDays(kFaviconRefetchDays);
2479 return false;
2480 2493
2481 favicon->expired = (Time::Now() - last_updated) > 2494 favicon_bitmap_results->clear();
2482 TimeDelta::FromDays(kFaviconRefetchDays); 2495 if (bitmap_result.is_valid())
2483 favicon->known_icon = true; 2496 favicon_bitmap_results->push_back(bitmap_result);
2484 favicon->image_data = data;
2485 return true; 2497 return true;
2486 } 2498 }
2487 2499
2488 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) { 2500 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) {
2489 BriefVisitInfo info; 2501 BriefVisitInfo info;
2490 info.url_id = visit.url_id; 2502 info.url_id = visit.url_id;
2491 info.time = visit.visit_time; 2503 info.time = visit.visit_time;
2492 info.transition = visit.transition; 2504 info.transition = visit.transition;
2493 // If we don't have a delegate yet during setup or shutdown, we will drop 2505 // If we don't have a delegate yet during setup or shutdown, we will drop
2494 // these notifications. 2506 // these notifications.
2495 if (delegate_.get()) 2507 if (delegate_.get())
2496 delegate_->NotifyVisitDBObserversOnAddVisit(info); 2508 delegate_->NotifyVisitDBObserversOnAddVisit(info);
2497 } 2509 }
2498 2510
2499 } // namespace history 2511 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698