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

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

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, 10 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #ifndef CHROME_BROWSER_SYNC_GLUE_FAVICON_CACHE_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_FAVICON_CACHE_H_
6 #define CHROME_BROWSER_SYNC_GLUE_FAVICON_CACHE_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_FAVICON_CACHE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/scoped_observer.h"
18 #include "base/task/cancelable_task_tracker.h" 19 #include "base/task/cancelable_task_tracker.h"
20 #include "components/history/core/browser/history_service_observer.h"
19 #include "components/history/core/browser/history_types.h" 21 #include "components/history/core/browser/history_types.h"
20 #include "components/sessions/session_id.h" 22 #include "components/sessions/session_id.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
23 #include "sync/api/sync_change.h" 23 #include "sync/api/sync_change.h"
24 #include "sync/api/sync_error_factory.h" 24 #include "sync/api/sync_error_factory.h"
25 #include "sync/api/syncable_service.h" 25 #include "sync/api/syncable_service.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 class Profile; 28 class Profile;
29 29
30 namespace chrome { 30 namespace chrome {
31 struct FaviconRawBitmapResult; 31 struct FaviconRawBitmapResult;
32 } 32 }
33 33
34 namespace browser_sync { 34 namespace browser_sync {
35 35
36 enum IconSize { 36 enum IconSize {
37 SIZE_INVALID, 37 SIZE_INVALID,
38 SIZE_16, 38 SIZE_16,
39 SIZE_32, 39 SIZE_32,
40 SIZE_64, 40 SIZE_64,
41 NUM_SIZES 41 NUM_SIZES
42 }; 42 };
43 43
44 struct SyncedFaviconInfo; 44 struct SyncedFaviconInfo;
45 45
46 // Encapsulates the logic for loading and storing synced favicons. 46 // Encapsulates the logic for loading and storing synced favicons.
47 // TODO(zea): make this a KeyedService. 47 // TODO(zea): make this a KeyedService.
48 class FaviconCache : public syncer::SyncableService, 48 class FaviconCache : public syncer::SyncableService,
49 public content::NotificationObserver { 49 public history::HistoryServiceObserver {
50 public: 50 public:
51 FaviconCache(Profile* profile, int max_sync_favicon_limit); 51 FaviconCache(Profile* profile, int max_sync_favicon_limit);
52 ~FaviconCache() override; 52 ~FaviconCache() override;
53 53
54 // SyncableService implementation. 54 // SyncableService implementation.
55 syncer::SyncMergeResult MergeDataAndStartSyncing( 55 syncer::SyncMergeResult MergeDataAndStartSyncing(
56 syncer::ModelType type, 56 syncer::ModelType type,
57 const syncer::SyncDataList& initial_sync_data, 57 const syncer::SyncDataList& initial_sync_data,
58 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 58 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
59 scoped_ptr<syncer::SyncErrorFactory> error_handler) override; 59 scoped_ptr<syncer::SyncErrorFactory> error_handler) override;
(...skipping 29 matching lines...) Expand all
89 void OnFaviconVisited(const GURL& page_url, const GURL& favicon_url); 89 void OnFaviconVisited(const GURL& page_url, const GURL& favicon_url);
90 90
91 // Consume Session sync favicon data. Will not overwrite existing favicons. 91 // Consume Session sync favicon data. Will not overwrite existing favicons.
92 // If |icon_bytes| is empty, only updates the page->favicon url mapping. 92 // If |icon_bytes| is empty, only updates the page->favicon url mapping.
93 // Safe to call within a transaction. 93 // Safe to call within a transaction.
94 void OnReceivedSyncFavicon(const GURL& page_url, 94 void OnReceivedSyncFavicon(const GURL& page_url,
95 const GURL& icon_url, 95 const GURL& icon_url,
96 const std::string& icon_bytes, 96 const std::string& icon_bytes,
97 int64 visit_time_ms); 97 int64 visit_time_ms);
98 98
99 // NotificationObserver implementation.
100 void Observe(int type,
101 const content::NotificationSource& source,
102 const content::NotificationDetails& details) override;
103
104 private: 99 private:
105 friend class SyncFaviconCacheTest; 100 friend class SyncFaviconCacheTest;
101 FRIEND_TEST_ALL_PREFIXES(SyncFaviconCacheTest, HistoryFullClear);
102 FRIEND_TEST_ALL_PREFIXES(SyncFaviconCacheTest, HistorySubsetClear);
106 103
107 // Functor for ordering SyncedFaviconInfo objects by recency; 104 // Functor for ordering SyncedFaviconInfo objects by recency;
108 struct FaviconRecencyFunctor { 105 struct FaviconRecencyFunctor {
109 bool operator()(const linked_ptr<SyncedFaviconInfo>& lhs, 106 bool operator()(const linked_ptr<SyncedFaviconInfo>& lhs,
110 const linked_ptr<SyncedFaviconInfo>& rhs) const; 107 const linked_ptr<SyncedFaviconInfo>& rhs) const;
111 }; 108 };
112 109
113 110
114 // Map of favicon url to favicon image. 111 // Map of favicon url to favicon image.
115 typedef std::map<GURL, linked_ptr<SyncedFaviconInfo> > FaviconMap; 112 typedef std::map<GURL, linked_ptr<SyncedFaviconInfo> > FaviconMap;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 void DropSyncedFavicon(FaviconMap::iterator favicon_iter); 186 void DropSyncedFavicon(FaviconMap::iterator favicon_iter);
190 187
191 // Only drops the data associated with |type| of |favicon_iter|. 188 // Only drops the data associated with |type| of |favicon_iter|.
192 void DropPartialFavicon(FaviconMap::iterator favicon_iter, 189 void DropPartialFavicon(FaviconMap::iterator favicon_iter,
193 syncer::ModelType type); 190 syncer::ModelType type);
194 191
195 // For testing only. 192 // For testing only.
196 size_t NumFaviconsForTest() const; 193 size_t NumFaviconsForTest() const;
197 size_t NumTasksForTest() const; 194 size_t NumTasksForTest() const;
198 195
196 // history::HistoryServiceObserver:
197 void OnURLsDeleted(HistoryService* history_service,
198 bool all_history,
199 bool expired,
200 const history::URLRows& deleted_rows,
201 const std::set<GURL>& favicon_urls) override;
202
199 // Trask tracker for loading favicons. 203 // Trask tracker for loading favicons.
200 base::CancelableTaskTracker cancelable_task_tracker_; 204 base::CancelableTaskTracker cancelable_task_tracker_;
201 205
202 // Our actual cached favicon data. 206 // Our actual cached favicon data.
203 FaviconMap synced_favicons_; 207 FaviconMap synced_favicons_;
204 208
205 // An LRU ordering of the favicons comprising |synced_favicons_| (oldest to 209 // An LRU ordering of the favicons comprising |synced_favicons_| (oldest to
206 // newest). 210 // newest).
207 RecencySet recent_favicons_; 211 RecencySet recent_favicons_;
208 212
209 // Our set of pending favicon loads, indexed by page url. 213 // Our set of pending favicon loads, indexed by page url.
210 PageTaskMap page_task_map_; 214 PageTaskMap page_task_map_;
211 215
212 // Map of page and associated favicon urls. 216 // Map of page and associated favicon urls.
213 PageFaviconMap page_favicon_map_; 217 PageFaviconMap page_favicon_map_;
214 218
215 Profile* profile_; 219 Profile* profile_;
216 220
217 // TODO(zea): consider creating a favicon handler here for fetching unsynced 221 // TODO(zea): consider creating a favicon handler here for fetching unsynced
218 // favicons from the web. 222 // favicons from the web.
219 223
220 scoped_ptr<syncer::SyncChangeProcessor> favicon_images_sync_processor_; 224 scoped_ptr<syncer::SyncChangeProcessor> favicon_images_sync_processor_;
221 scoped_ptr<syncer::SyncChangeProcessor> favicon_tracking_sync_processor_; 225 scoped_ptr<syncer::SyncChangeProcessor> favicon_tracking_sync_processor_;
222 226
223 // For listening to history deletions.
224 content::NotificationRegistrar notification_registrar_;
225
226 // Maximum number of favicons to sync. 0 means no limit. 227 // Maximum number of favicons to sync. 0 means no limit.
227 const size_t max_sync_favicon_limit_; 228 const size_t max_sync_favicon_limit_;
228 229
230 ScopedObserver<HistoryService, HistoryServiceObserver>
231 history_service_observer_;
232
229 // Weak pointer factory for favicon loads. 233 // Weak pointer factory for favicon loads.
230 base::WeakPtrFactory<FaviconCache> weak_ptr_factory_; 234 base::WeakPtrFactory<FaviconCache> weak_ptr_factory_;
231 235
232 DISALLOW_COPY_AND_ASSIGN(FaviconCache); 236 DISALLOW_COPY_AND_ASSIGN(FaviconCache);
233 }; 237 };
234 238
235 } // namespace browser_sync 239 } // namespace browser_sync
236 240
237 #endif // CHROME_BROWSER_SYNC_GLUE_FAVICON_CACHE_H_ 241 #endif // CHROME_BROWSER_SYNC_GLUE_FAVICON_CACHE_H_
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor.cc ('k') | chrome/browser/sync/glue/favicon_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698