OLD | NEW |
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 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 content::NotificationObserver { |
50 public: | 50 public: |
51 FaviconCache(Profile* profile, int max_sync_favicon_limit); | 51 FaviconCache(Profile* profile, int max_sync_favicon_limit); |
52 virtual ~FaviconCache(); | 52 ~FaviconCache() override; |
53 | 53 |
54 // SyncableService implementation. | 54 // SyncableService implementation. |
55 virtual 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; |
60 virtual void StopSyncing(syncer::ModelType type) override; | 60 void StopSyncing(syncer::ModelType type) override; |
61 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) | 61 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override; |
62 const override; | 62 syncer::SyncError ProcessSyncChanges( |
63 virtual syncer::SyncError ProcessSyncChanges( | |
64 const tracked_objects::Location& from_here, | 63 const tracked_objects::Location& from_here, |
65 const syncer::SyncChangeList& change_list) override; | 64 const syncer::SyncChangeList& change_list) override; |
66 | 65 |
67 // If a valid favicon for the icon at |favicon_url| is found, fills | 66 // If a valid favicon for the icon at |favicon_url| is found, fills |
68 // |favicon_png| with the png-encoded image and returns true. Else, returns | 67 // |favicon_png| with the png-encoded image and returns true. Else, returns |
69 // false. | 68 // false. |
70 bool GetSyncedFaviconForFaviconURL( | 69 bool GetSyncedFaviconForFaviconURL( |
71 const GURL& favicon_url, | 70 const GURL& favicon_url, |
72 scoped_refptr<base::RefCountedMemory>* favicon_png) const; | 71 scoped_refptr<base::RefCountedMemory>* favicon_png) const; |
73 | 72 |
(...skipping 17 matching lines...) Expand all Loading... |
91 | 90 |
92 // Consume Session sync favicon data. Will not overwrite existing favicons. | 91 // Consume Session sync favicon data. Will not overwrite existing favicons. |
93 // 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. |
94 // Safe to call within a transaction. | 93 // Safe to call within a transaction. |
95 void OnReceivedSyncFavicon(const GURL& page_url, | 94 void OnReceivedSyncFavicon(const GURL& page_url, |
96 const GURL& icon_url, | 95 const GURL& icon_url, |
97 const std::string& icon_bytes, | 96 const std::string& icon_bytes, |
98 int64 visit_time_ms); | 97 int64 visit_time_ms); |
99 | 98 |
100 // NotificationObserver implementation. | 99 // NotificationObserver implementation. |
101 virtual void Observe(int type, | 100 void Observe(int type, |
102 const content::NotificationSource& source, | 101 const content::NotificationSource& source, |
103 const content::NotificationDetails& details) override; | 102 const content::NotificationDetails& details) override; |
104 | 103 |
105 private: | 104 private: |
106 friend class SyncFaviconCacheTest; | 105 friend class SyncFaviconCacheTest; |
107 | 106 |
108 // Functor for ordering SyncedFaviconInfo objects by recency; | 107 // Functor for ordering SyncedFaviconInfo objects by recency; |
109 struct FaviconRecencyFunctor { | 108 struct FaviconRecencyFunctor { |
110 bool operator()(const linked_ptr<SyncedFaviconInfo>& lhs, | 109 bool operator()(const linked_ptr<SyncedFaviconInfo>& lhs, |
111 const linked_ptr<SyncedFaviconInfo>& rhs) const; | 110 const linked_ptr<SyncedFaviconInfo>& rhs) const; |
112 }; | 111 }; |
113 | 112 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 228 |
230 // Weak pointer factory for favicon loads. | 229 // Weak pointer factory for favicon loads. |
231 base::WeakPtrFactory<FaviconCache> weak_ptr_factory_; | 230 base::WeakPtrFactory<FaviconCache> weak_ptr_factory_; |
232 | 231 |
233 DISALLOW_COPY_AND_ASSIGN(FaviconCache); | 232 DISALLOW_COPY_AND_ASSIGN(FaviconCache); |
234 }; | 233 }; |
235 | 234 |
236 } // namespace browser_sync | 235 } // namespace browser_sync |
237 | 236 |
238 #endif // CHROME_BROWSER_SYNC_GLUE_FAVICON_CACHE_H_ | 237 #endif // CHROME_BROWSER_SYNC_GLUE_FAVICON_CACHE_H_ |
OLD | NEW |