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

Side by Side Diff: chrome/browser/sync/glue/favicon_cache.cc

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to tip Created 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/sync/glue/favicon_cache.h" 5 #include "chrome/browser/sync/glue/favicon_cache.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/favicon/favicon_service.h" 9 #include "chrome/browser/favicon/favicon_service.h"
11 #include "chrome/browser/favicon/favicon_service_factory.h" 10 #include "chrome/browser/favicon/favicon_service_factory.h"
12 #include "chrome/browser/history/history_notifications.h" 11 #include "chrome/browser/history/history_service.h"
12 #include "chrome/browser/history/history_service_factory.h"
13 #include "components/history/core/browser/history_types.h" 13 #include "components/history/core/browser/history_types.h"
14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h"
16 #include "sync/api/time.h" 14 #include "sync/api/time.h"
17 #include "sync/protocol/favicon_image_specifics.pb.h" 15 #include "sync/protocol/favicon_image_specifics.pb.h"
18 #include "sync/protocol/favicon_tracking_specifics.pb.h" 16 #include "sync/protocol/favicon_tracking_specifics.pb.h"
19 #include "sync/protocol/sync.pb.h" 17 #include "sync/protocol/sync.pb.h"
20 #include "ui/gfx/favicon_size.h" 18 #include "ui/gfx/favicon_size.h"
21 19
22 namespace browser_sync { 20 namespace browser_sync {
23 21
24 // Synced favicon storage and tracking. 22 // Synced favicon storage and tracking.
25 // Note: we don't use the favicon service for storing these because these 23 // Note: we don't use the favicon service for storing these because these
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return FaviconInfoHasTracking(favicon_info); 217 return FaviconInfoHasTracking(favicon_info);
220 NOTREACHED(); 218 NOTREACHED();
221 return false; 219 return false;
222 } 220 }
223 221
224 } // namespace 222 } // namespace
225 223
226 FaviconCache::FaviconCache(Profile* profile, int max_sync_favicon_limit) 224 FaviconCache::FaviconCache(Profile* profile, int max_sync_favicon_limit)
227 : profile_(profile), 225 : profile_(profile),
228 max_sync_favicon_limit_(max_sync_favicon_limit), 226 max_sync_favicon_limit_(max_sync_favicon_limit),
227 history_service_observer_(this),
229 weak_ptr_factory_(this) { 228 weak_ptr_factory_(this) {
230 notification_registrar_.Add(this, 229 HistoryService* hs = NULL;
231 chrome::NOTIFICATION_HISTORY_URLS_DELETED, 230 if (profile_) {
232 content::Source<Profile>(profile_)); 231 hs = HistoryServiceFactory::GetForProfile(
232 profile_, ServiceAccessType::EXPLICIT_ACCESS);
233 }
234 if (hs)
235 history_service_observer_.Add(hs);
233 DVLOG(1) << "Setting favicon limit to " << max_sync_favicon_limit; 236 DVLOG(1) << "Setting favicon limit to " << max_sync_favicon_limit;
234 } 237 }
235 238
236 FaviconCache::~FaviconCache() {} 239 FaviconCache::~FaviconCache() {}
237 240
238 syncer::SyncMergeResult FaviconCache::MergeDataAndStartSyncing( 241 syncer::SyncMergeResult FaviconCache::MergeDataAndStartSyncing(
239 syncer::ModelType type, 242 syncer::ModelType type,
240 const syncer::SyncDataList& initial_sync_data, 243 const syncer::SyncDataList& initial_sync_data,
241 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 244 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
242 scoped_ptr<syncer::SyncErrorFactory> error_handler) { 245 scoped_ptr<syncer::SyncErrorFactory> error_handler) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 UpdateFaviconVisitTime(icon_url, 567 UpdateFaviconVisitTime(icon_url,
565 syncer::ProtoTimeToTime(visit_time_ms)); 568 syncer::ProtoTimeToTime(visit_time_ms));
566 569
567 UpdateSyncState(icon_url, 570 UpdateSyncState(icon_url,
568 syncer::SyncChange::ACTION_ADD, 571 syncer::SyncChange::ACTION_ADD,
569 (added_tracking ? 572 (added_tracking ?
570 syncer::SyncChange::ACTION_ADD : 573 syncer::SyncChange::ACTION_ADD :
571 syncer::SyncChange::ACTION_UPDATE)); 574 syncer::SyncChange::ACTION_UPDATE));
572 } 575 }
573 576
574 void FaviconCache::Observe(int type,
575 const content::NotificationSource& source,
576 const content::NotificationDetails& details) {
577 DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URLS_DELETED);
578
579 content::Details<history::URLsDeletedDetails> deleted_details(details);
580
581 // We only care about actual user (or sync) deletions.
582 if (deleted_details->expired)
583 return;
584
585 if (!deleted_details->all_history) {
586 DeleteSyncedFavicons(deleted_details->favicon_urls);
587 return;
588 }
589
590 // All history was cleared: just delete all favicons.
591 DVLOG(1) << "History clear detected, deleting all synced favicons.";
592 syncer::SyncChangeList image_deletions, tracking_deletions;
593 while (!synced_favicons_.empty()) {
594 DeleteSyncedFavicon(synced_favicons_.begin(),
595 &image_deletions,
596 &tracking_deletions);
597 }
598
599 if (favicon_images_sync_processor_.get()) {
600 favicon_images_sync_processor_->ProcessSyncChanges(FROM_HERE,
601 image_deletions);
602 }
603 if (favicon_tracking_sync_processor_.get()) {
604 favicon_tracking_sync_processor_->ProcessSyncChanges(FROM_HERE,
605 tracking_deletions);
606 }
607 }
608
609 bool FaviconCache::FaviconRecencyFunctor::operator()( 577 bool FaviconCache::FaviconRecencyFunctor::operator()(
610 const linked_ptr<SyncedFaviconInfo>& lhs, 578 const linked_ptr<SyncedFaviconInfo>& lhs,
611 const linked_ptr<SyncedFaviconInfo>& rhs) const { 579 const linked_ptr<SyncedFaviconInfo>& rhs) const {
612 // TODO(zea): incorporate bookmarked status here once we care about it. 580 // TODO(zea): incorporate bookmarked status here once we care about it.
613 if (lhs->last_visit_time < rhs->last_visit_time) 581 if (lhs->last_visit_time < rhs->last_visit_time)
614 return true; 582 return true;
615 else if (lhs->last_visit_time == rhs->last_visit_time) 583 else if (lhs->last_visit_time == rhs->last_visit_time)
616 return lhs->favicon_url.spec() < rhs->favicon_url.spec(); 584 return lhs->favicon_url.spec() < rhs->favicon_url.spec();
617 return false; 585 return false;
618 } 586 }
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 } 1026 }
1059 1027
1060 size_t FaviconCache::NumFaviconsForTest() const { 1028 size_t FaviconCache::NumFaviconsForTest() const {
1061 return synced_favicons_.size(); 1029 return synced_favicons_.size();
1062 } 1030 }
1063 1031
1064 size_t FaviconCache::NumTasksForTest() const { 1032 size_t FaviconCache::NumTasksForTest() const {
1065 return page_task_map_.size(); 1033 return page_task_map_.size();
1066 } 1034 }
1067 1035
1036 void FaviconCache::OnURLsDeleted(HistoryService* history_service,
1037 bool all_history,
1038 bool expired,
1039 const history::URLRows& deleted_rows,
1040 const std::set<GURL>& favicon_urls) {
1041 // We only care about actual user (or sync) deletions.
1042 if (expired)
1043 return;
1044
1045 if (!all_history) {
1046 DeleteSyncedFavicons(favicon_urls);
1047 return;
1048 }
1049
1050 // All history was cleared: just delete all favicons.
1051 DVLOG(1) << "History clear detected, deleting all synced favicons.";
1052 syncer::SyncChangeList image_deletions, tracking_deletions;
1053 while (!synced_favicons_.empty()) {
1054 DeleteSyncedFavicon(synced_favicons_.begin(), &image_deletions,
1055 &tracking_deletions);
1056 }
1057
1058 if (favicon_images_sync_processor_.get()) {
1059 favicon_images_sync_processor_->ProcessSyncChanges(FROM_HERE,
1060 image_deletions);
1061 }
1062 if (favicon_tracking_sync_processor_.get()) {
1063 favicon_tracking_sync_processor_->ProcessSyncChanges(FROM_HERE,
1064 tracking_deletions);
1065 }
1066 }
1067
1068 } // namespace browser_sync 1068 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/favicon_cache.h ('k') | chrome/browser/sync/glue/favicon_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698