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

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, 4 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 FaviconData favicon_data;
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_data);
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 in icon_url if it exists in database instead of empty
1911 // vector.
1912 request->ForwardResult(request->handle(), favicon_data, std::vector<GURL>());
1918 } 1913 }
1919 1914
1920 void HistoryBackend::GetFaviconForURL( 1915 void HistoryBackend::GetFaviconForURL(
1921 scoped_refptr<GetFaviconRequest> request, 1916 scoped_refptr<GetFaviconRequest> request,
1922 const GURL& page_url, 1917 const GURL& page_url,
1923 int icon_types) { 1918 int icon_types) {
1924 if (request->canceled()) 1919 if (request->canceled())
1925 return; 1920 return;
1926 1921
1927 FaviconData favicon; 1922 FaviconData favicon_data;
1928 1923
1929 // Get the favicon from DB. 1924 // Get the favicon from DB.
1930 GetFaviconFromDB(page_url, icon_types, &favicon); 1925 GetFaviconFromDB(page_url, icon_types, &favicon_data);
1931 1926
1932 request->ForwardResult(request->handle(), favicon); 1927 // TODO(pkotwicz): Pass in matched icon URLs for icon_types instead of empty
1933 } 1928 // vector.
1934 1929 request->ForwardResult(request->handle(), favicon_data, std::vector<GURL>());
1935 void HistoryBackend::GetFaviconForID(scoped_refptr<GetFaviconRequest> request,
1936 FaviconID id) {
1937 if (request->canceled())
1938 return;
1939
1940 FaviconData favicon;
1941 GetFaviconFromDB(id, &favicon);
1942 request->ForwardResult(request->handle(), favicon);
1943 } 1930 }
1944 1931
1945 void HistoryBackend::SetFavicon( 1932 void HistoryBackend::SetFavicon(
1946 const GURL& page_url, 1933 const GURL& page_url,
1947 const GURL& icon_url, 1934 const GURL& icon_url,
1948 scoped_refptr<base::RefCountedMemory> data, 1935 scoped_refptr<base::RefCountedMemory> data,
1949 IconType icon_type) { 1936 IconType icon_type) {
1950 DCHECK(data.get()); 1937 DCHECK(data.get());
1951 if (!thumbnail_db_.get() || !db_.get()) 1938 if (!thumbnail_db_.get() || !db_.get())
1952 return; 1939 return;
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 2419
2433 BookmarkService* HistoryBackend::GetBookmarkService() { 2420 BookmarkService* HistoryBackend::GetBookmarkService() {
2434 if (bookmark_service_) 2421 if (bookmark_service_)
2435 bookmark_service_->BlockTillLoaded(); 2422 bookmark_service_->BlockTillLoaded();
2436 return bookmark_service_; 2423 return bookmark_service_;
2437 } 2424 }
2438 2425
2439 bool HistoryBackend::GetFaviconFromDB( 2426 bool HistoryBackend::GetFaviconFromDB(
2440 const GURL& page_url, 2427 const GURL& page_url,
2441 int icon_types, 2428 int icon_types,
2442 FaviconData* favicon) { 2429 FaviconData* favicon_data) {
2443 DCHECK(favicon); 2430 DCHECK(favicon_data);
2444 2431
2445 if (!db_.get() || !thumbnail_db_.get()) 2432 if (!db_.get() || !thumbnail_db_.get())
2446 return false; 2433 return false;
2447 2434
2448 bool success = false; 2435 bool success = false;
2449 // Time the query. 2436 // Time the query.
2450 TimeTicks beginning_time = TimeTicks::Now(); 2437 TimeTicks beginning_time = TimeTicks::Now();
2451 2438
2452 std::vector<IconMapping> icon_mappings; 2439 std::vector<IconMapping> icon_mappings;
2453 // Iterate over the known icons looking for one that includes one of the 2440 // Iterate over the known icons looking for one that includes one of the
2454 // requested types. 2441 // requested types.
2455 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) { 2442 if (thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings)) {
2456 for (std::vector<IconMapping>::iterator i = icon_mappings.begin(); 2443 for (std::vector<IconMapping>::iterator i = icon_mappings.begin();
2457 i != icon_mappings.end(); ++i) { 2444 i != icon_mappings.end(); ++i) {
2458 if ((i->icon_type & icon_types) && 2445 if ((i->icon_type & icon_types) &&
2459 GetFaviconFromDB(i->icon_id, favicon)) { 2446 GetFaviconFromDB(i->icon_id, favicon_data)) {
2460 success = true; 2447 success = true;
2461 break; 2448 break;
2462 } 2449 }
2463 } 2450 }
2464 } 2451 }
2465 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name 2452 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name
2466 TimeTicks::Now() - beginning_time); 2453 TimeTicks::Now() - beginning_time);
2467 return success; 2454 return success;
2468 } 2455 }
2469 2456
2470 bool HistoryBackend::GetFaviconFromDB(FaviconID favicon_id, 2457 bool HistoryBackend::GetFaviconFromDB(FaviconID favicon_id,
2471 FaviconData* favicon) { 2458 FaviconData* favicon_data) {
2472 Time last_updated; 2459 Time last_updated;
2473 scoped_refptr<base::RefCountedMemory> data; 2460 scoped_refptr<base::RefCountedMemory> data;
2474 2461
2462 favicon_data->known_icon = true;
sky 2012/08/23 15:50:38 How come this is set even if we don't have a favic
2475 if (!thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data, 2463 if (!thumbnail_db_->GetFavicon(favicon_id, &last_updated, &data,
2476 &favicon->icon_url, &favicon->icon_type)) 2464 &favicon_data->icon_url, &favicon_data->icon_type))
2477 return false; 2465 return false;
2478 2466
2479 favicon->expired = (Time::Now() - last_updated) > 2467 FaviconBitmapData favicon_bitmap_data;
2468 favicon_bitmap_data.expired = (Time::Now() - last_updated) >
2480 TimeDelta::FromDays(kFaviconRefetchDays); 2469 TimeDelta::FromDays(kFaviconRefetchDays);
2481 favicon->known_icon = true; 2470 favicon_bitmap_data.bitmap_data = data;
2482 favicon->image_data = data; 2471
2472 favicon_data->bitmaps.clear();
2473 favicon_data->bitmaps.push_back(favicon_bitmap_data);
2483 return true; 2474 return true;
2484 } 2475 }
2485 2476
2486 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) { 2477 void HistoryBackend::NotifyVisitObservers(const VisitRow& visit) {
2487 BriefVisitInfo info; 2478 BriefVisitInfo info;
2488 info.url_id = visit.url_id; 2479 info.url_id = visit.url_id;
2489 info.time = visit.visit_time; 2480 info.time = visit.visit_time;
2490 info.transition = visit.transition; 2481 info.transition = visit.transition;
2491 // If we don't have a delegate yet during setup or shutdown, we will drop 2482 // If we don't have a delegate yet during setup or shutdown, we will drop
2492 // these notifications. 2483 // these notifications.
2493 if (delegate_.get()) 2484 if (delegate_.get())
2494 delegate_->NotifyVisitDBObserversOnAddVisit(info); 2485 delegate_->NotifyVisitDBObserversOnAddVisit(info);
2495 } 2486 }
2496 2487
2497 } // namespace history 2488 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698