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

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: Remove NotificationObserver from InMemoryURLIndex Created 6 years 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" 9 #include "chrome/browser/chrome_notification_types.h"
sdefresne 2014/12/04 17:21:13 Again, unused #include ;-)
nshaik 2014/12/07 09:34:50 Done.
10 #include "chrome/browser/favicon/favicon_service.h" 10 #include "chrome/browser/favicon/favicon_service.h"
11 #include "chrome/browser/favicon/favicon_service_factory.h" 11 #include "chrome/browser/favicon/favicon_service_factory.h"
12 #include "chrome/browser/history/history_notifications.h" 12 #include "chrome/browser/history/history_notifications.h"
13 #include "chrome/browser/history/history_service.h"
14 #include "chrome/browser/history/history_service_factory.h"
13 #include "components/history/core/browser/history_types.h" 15 #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" 16 #include "sync/api/time.h"
17 #include "sync/protocol/favicon_image_specifics.pb.h" 17 #include "sync/protocol/favicon_image_specifics.pb.h"
18 #include "sync/protocol/favicon_tracking_specifics.pb.h" 18 #include "sync/protocol/favicon_tracking_specifics.pb.h"
19 #include "sync/protocol/sync.pb.h" 19 #include "sync/protocol/sync.pb.h"
20 #include "ui/gfx/favicon_size.h" 20 #include "ui/gfx/favicon_size.h"
21 21
22 namespace browser_sync { 22 namespace browser_sync {
23 23
24 // Synced favicon storage and tracking. 24 // Synced favicon storage and tracking.
25 // Note: we don't use the favicon service for storing these because these 25 // 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); 219 return FaviconInfoHasTracking(favicon_info);
220 NOTREACHED(); 220 NOTREACHED();
221 return false; 221 return false;
222 } 222 }
223 223
224 } // namespace 224 } // namespace
225 225
226 FaviconCache::FaviconCache(Profile* profile, int max_sync_favicon_limit) 226 FaviconCache::FaviconCache(Profile* profile, int max_sync_favicon_limit)
227 : profile_(profile), 227 : profile_(profile),
228 max_sync_favicon_limit_(max_sync_favicon_limit), 228 max_sync_favicon_limit_(max_sync_favicon_limit),
229 history_service_observer_(this),
229 weak_ptr_factory_(this) { 230 weak_ptr_factory_(this) {
230 notification_registrar_.Add(this, 231 HistoryService* hs = NULL;
231 chrome::NOTIFICATION_HISTORY_URLS_DELETED, 232 if (profile_)
232 content::Source<Profile>(profile_)); 233 hs = HistoryServiceFactory::GetForProfile(profile_,
234 Profile::EXPLICIT_ACCESS);
235 if (hs)
236 history_service_observer_.Add(hs);
233 DVLOG(1) << "Setting favicon limit to " << max_sync_favicon_limit; 237 DVLOG(1) << "Setting favicon limit to " << max_sync_favicon_limit;
234 } 238 }
235 239
236 FaviconCache::~FaviconCache() {} 240 FaviconCache::~FaviconCache() {}
237 241
238 syncer::SyncMergeResult FaviconCache::MergeDataAndStartSyncing( 242 syncer::SyncMergeResult FaviconCache::MergeDataAndStartSyncing(
239 syncer::ModelType type, 243 syncer::ModelType type,
240 const syncer::SyncDataList& initial_sync_data, 244 const syncer::SyncDataList& initial_sync_data,
241 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 245 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
242 scoped_ptr<syncer::SyncErrorFactory> error_handler) { 246 scoped_ptr<syncer::SyncErrorFactory> error_handler) {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 UpdateFaviconVisitTime(icon_url, 568 UpdateFaviconVisitTime(icon_url,
565 syncer::ProtoTimeToTime(visit_time_ms)); 569 syncer::ProtoTimeToTime(visit_time_ms));
566 570
567 UpdateSyncState(icon_url, 571 UpdateSyncState(icon_url,
568 syncer::SyncChange::ACTION_ADD, 572 syncer::SyncChange::ACTION_ADD,
569 (added_tracking ? 573 (added_tracking ?
570 syncer::SyncChange::ACTION_ADD : 574 syncer::SyncChange::ACTION_ADD :
571 syncer::SyncChange::ACTION_UPDATE)); 575 syncer::SyncChange::ACTION_UPDATE));
572 } 576 }
573 577
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()( 578 bool FaviconCache::FaviconRecencyFunctor::operator()(
610 const linked_ptr<SyncedFaviconInfo>& lhs, 579 const linked_ptr<SyncedFaviconInfo>& lhs,
611 const linked_ptr<SyncedFaviconInfo>& rhs) const { 580 const linked_ptr<SyncedFaviconInfo>& rhs) const {
612 // TODO(zea): incorporate bookmarked status here once we care about it. 581 // TODO(zea): incorporate bookmarked status here once we care about it.
613 if (lhs->last_visit_time < rhs->last_visit_time) 582 if (lhs->last_visit_time < rhs->last_visit_time)
614 return true; 583 return true;
615 else if (lhs->last_visit_time == rhs->last_visit_time) 584 else if (lhs->last_visit_time == rhs->last_visit_time)
616 return lhs->favicon_url.spec() < rhs->favicon_url.spec(); 585 return lhs->favicon_url.spec() < rhs->favicon_url.spec();
617 return false; 586 return false;
618 } 587 }
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 } 1027 }
1059 1028
1060 size_t FaviconCache::NumFaviconsForTest() const { 1029 size_t FaviconCache::NumFaviconsForTest() const {
1061 return synced_favicons_.size(); 1030 return synced_favicons_.size();
1062 } 1031 }
1063 1032
1064 size_t FaviconCache::NumTasksForTest() const { 1033 size_t FaviconCache::NumTasksForTest() const {
1065 return page_task_map_.size(); 1034 return page_task_map_.size();
1066 } 1035 }
1067 1036
1037 void FaviconCache::OnURLsDeleted(
1038 HistoryService* history_service,
1039 const history::URLsDeletedDetails& deleted_details) {
1040 // We only care about actual user (or sync) deletions.
1041 if (deleted_details.expired)
1042 return;
1043
1044 if (!deleted_details.all_history) {
1045 DeleteSyncedFavicons(deleted_details.favicon_urls);
1046 return;
1047 }
1048
1049 // All history was cleared: just delete all favicons.
1050 DVLOG(1) << "History clear detected, deleting all synced favicons.";
1051 syncer::SyncChangeList image_deletions, tracking_deletions;
1052 while (!synced_favicons_.empty()) {
1053 DeleteSyncedFavicon(synced_favicons_.begin(), &image_deletions,
1054 &tracking_deletions);
1055 }
1056
1057 if (favicon_images_sync_processor_.get()) {
1058 favicon_images_sync_processor_->ProcessSyncChanges(FROM_HERE,
1059 image_deletions);
1060 }
1061 if (favicon_tracking_sync_processor_.get()) {
1062 favicon_tracking_sync_processor_->ProcessSyncChanges(FROM_HERE,
1063 tracking_deletions);
1064 }
1065 }
1066
1068 } // namespace browser_sync 1067 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698