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

Side by Side Diff: chrome/browser/history/history_backend.cc

Issue 11830007: Avoid sending notifications when the bitmap data in history has not changed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split the changes to MergeFavicon() and SetFavicons() into two CLs as only the changes to MergeFavi… Created 7 years, 11 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 <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 } 1924 }
1925 1925
1926 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; 1926 std::vector<FaviconBitmapIDSize> bitmap_id_sizes;
1927 thumbnail_db_->GetFaviconBitmapIDSizes(favicon_id, &bitmap_id_sizes); 1927 thumbnail_db_->GetFaviconBitmapIDSizes(favicon_id, &bitmap_id_sizes);
1928 1928
1929 // If there is already a favicon bitmap of |pixel_size| at |icon_url|, 1929 // If there is already a favicon bitmap of |pixel_size| at |icon_url|,
1930 // replace it. 1930 // replace it.
1931 bool replaced_bitmap = false; 1931 bool replaced_bitmap = false;
1932 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { 1932 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) {
1933 if (bitmap_id_sizes[i].pixel_size == pixel_size) { 1933 if (bitmap_id_sizes[i].pixel_size == pixel_size) {
1934 if (IsFaviconBitmapDataEqual(bitmap_id_sizes[i].bitmap_id, bitmap_data)) {
1935 thumbnail_db_->SetFaviconBitmapLastUpdateTime(
1936 bitmap_id_sizes[i].bitmap_id, base::Time::Now());
1937 // Return early as merging did not alter the bitmap data.
1938 ScheduleCommit();
1939 return;
1940 }
1934 thumbnail_db_->SetFaviconBitmap(bitmap_id_sizes[i].bitmap_id, bitmap_data, 1941 thumbnail_db_->SetFaviconBitmap(bitmap_id_sizes[i].bitmap_id, bitmap_data,
1935 base::Time::Now()); 1942 base::Time::Now());
1936 replaced_bitmap = true; 1943 replaced_bitmap = true;
1937 break; 1944 break;
1938 } 1945 }
1939 } 1946 }
1940 1947
1941 // Create a vector of the pixel sizes of the favicon bitmaps currently at 1948 // Create a vector of the pixel sizes of the favicon bitmaps currently at
1942 // |icon_url|. 1949 // |icon_url|.
1943 std::vector<gfx::Size> favicon_sizes; 1950 std::vector<gfx::Size> favicon_sizes;
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; 2316 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size;
2310 FaviconSizes::const_iterator sizes_it = std::find(favicon_sizes.begin(), 2317 FaviconSizes::const_iterator sizes_it = std::find(favicon_sizes.begin(),
2311 favicon_sizes.end(), pixel_size); 2318 favicon_sizes.end(), pixel_size);
2312 if (sizes_it == favicon_sizes.end()) 2319 if (sizes_it == favicon_sizes.end())
2313 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[i].bitmap_id); 2320 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[i].bitmap_id);
2314 } 2321 }
2315 2322
2316 thumbnail_db_->SetFaviconSizes(icon_id, favicon_sizes); 2323 thumbnail_db_->SetFaviconSizes(icon_id, favicon_sizes);
2317 } 2324 }
2318 2325
2326 bool HistoryBackend::IsFaviconBitmapDataEqual(
2327 FaviconBitmapID bitmap_id,
2328 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) {
2329 if (!new_bitmap_data.get())
2330 return false;
2331
2332 scoped_refptr<base::RefCountedMemory> original_bitmap_data;
2333 thumbnail_db_->GetFaviconBitmap(bitmap_id,
2334 NULL,
2335 &original_bitmap_data,
2336 NULL);
2337 return new_bitmap_data->Equals(original_bitmap_data);
2338 }
2339
2319 bool HistoryBackend::GetFaviconsFromDB( 2340 bool HistoryBackend::GetFaviconsFromDB(
2320 const GURL& page_url, 2341 const GURL& page_url,
2321 int icon_types, 2342 int icon_types,
2322 int desired_size_in_dip, 2343 int desired_size_in_dip,
2323 const std::vector<ui::ScaleFactor>& desired_scale_factors, 2344 const std::vector<ui::ScaleFactor>& desired_scale_factors,
2324 std::vector<FaviconBitmapResult>* favicon_bitmap_results, 2345 std::vector<FaviconBitmapResult>* favicon_bitmap_results,
2325 IconURLSizesMap* icon_url_sizes) { 2346 IconURLSizesMap* icon_url_sizes) {
2326 DCHECK(favicon_bitmap_results); 2347 DCHECK(favicon_bitmap_results);
2327 DCHECK(icon_url_sizes); 2348 DCHECK(icon_url_sizes);
2328 favicon_bitmap_results->clear(); 2349 favicon_bitmap_results->clear();
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 info.url_id = visit.url_id; 2998 info.url_id = visit.url_id;
2978 info.time = visit.visit_time; 2999 info.time = visit.visit_time;
2979 info.transition = visit.transition; 3000 info.transition = visit.transition;
2980 // If we don't have a delegate yet during setup or shutdown, we will drop 3001 // If we don't have a delegate yet during setup or shutdown, we will drop
2981 // these notifications. 3002 // these notifications.
2982 if (delegate_.get()) 3003 if (delegate_.get())
2983 delegate_->NotifyVisitDBObserversOnAddVisit(info); 3004 delegate_->NotifyVisitDBObserversOnAddVisit(info);
2984 } 3005 }
2985 3006
2986 } // namespace history 3007 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698