OLD | NEW |
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 Loading... |
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(profile_, |
| 232 Profile::EXPLICIT_ACCESS); |
| 233 if (hs) |
| 234 history_service_observer_.Add(hs); |
233 DVLOG(1) << "Setting favicon limit to " << max_sync_favicon_limit; | 235 DVLOG(1) << "Setting favicon limit to " << max_sync_favicon_limit; |
234 } | 236 } |
235 | 237 |
236 FaviconCache::~FaviconCache() {} | 238 FaviconCache::~FaviconCache() {} |
237 | 239 |
238 syncer::SyncMergeResult FaviconCache::MergeDataAndStartSyncing( | 240 syncer::SyncMergeResult FaviconCache::MergeDataAndStartSyncing( |
239 syncer::ModelType type, | 241 syncer::ModelType type, |
240 const syncer::SyncDataList& initial_sync_data, | 242 const syncer::SyncDataList& initial_sync_data, |
241 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 243 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
242 scoped_ptr<syncer::SyncErrorFactory> error_handler) { | 244 scoped_ptr<syncer::SyncErrorFactory> error_handler) { |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 UpdateFaviconVisitTime(icon_url, | 566 UpdateFaviconVisitTime(icon_url, |
565 syncer::ProtoTimeToTime(visit_time_ms)); | 567 syncer::ProtoTimeToTime(visit_time_ms)); |
566 | 568 |
567 UpdateSyncState(icon_url, | 569 UpdateSyncState(icon_url, |
568 syncer::SyncChange::ACTION_ADD, | 570 syncer::SyncChange::ACTION_ADD, |
569 (added_tracking ? | 571 (added_tracking ? |
570 syncer::SyncChange::ACTION_ADD : | 572 syncer::SyncChange::ACTION_ADD : |
571 syncer::SyncChange::ACTION_UPDATE)); | 573 syncer::SyncChange::ACTION_UPDATE)); |
572 } | 574 } |
573 | 575 |
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()( | 576 bool FaviconCache::FaviconRecencyFunctor::operator()( |
610 const linked_ptr<SyncedFaviconInfo>& lhs, | 577 const linked_ptr<SyncedFaviconInfo>& lhs, |
611 const linked_ptr<SyncedFaviconInfo>& rhs) const { | 578 const linked_ptr<SyncedFaviconInfo>& rhs) const { |
612 // TODO(zea): incorporate bookmarked status here once we care about it. | 579 // TODO(zea): incorporate bookmarked status here once we care about it. |
613 if (lhs->last_visit_time < rhs->last_visit_time) | 580 if (lhs->last_visit_time < rhs->last_visit_time) |
614 return true; | 581 return true; |
615 else if (lhs->last_visit_time == rhs->last_visit_time) | 582 else if (lhs->last_visit_time == rhs->last_visit_time) |
616 return lhs->favicon_url.spec() < rhs->favicon_url.spec(); | 583 return lhs->favicon_url.spec() < rhs->favicon_url.spec(); |
617 return false; | 584 return false; |
618 } | 585 } |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 } | 1025 } |
1059 | 1026 |
1060 size_t FaviconCache::NumFaviconsForTest() const { | 1027 size_t FaviconCache::NumFaviconsForTest() const { |
1061 return synced_favicons_.size(); | 1028 return synced_favicons_.size(); |
1062 } | 1029 } |
1063 | 1030 |
1064 size_t FaviconCache::NumTasksForTest() const { | 1031 size_t FaviconCache::NumTasksForTest() const { |
1065 return page_task_map_.size(); | 1032 return page_task_map_.size(); |
1066 } | 1033 } |
1067 | 1034 |
| 1035 void FaviconCache::OnURLsDeleted(HistoryService* history_service, |
| 1036 bool all_history, |
| 1037 bool expired, |
| 1038 const history::URLRows& deleted_rows, |
| 1039 const std::set<GURL>& favicon_urls) { |
| 1040 // We only care about actual user (or sync) deletions. |
| 1041 if (expired) |
| 1042 return; |
| 1043 |
| 1044 if (!all_history) { |
| 1045 DeleteSyncedFavicons(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 |
OLD | NEW |