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 #ifndef COMPONENTS_SYNC_SESSIONS_FAVICON_CACHE_H_ | 5 #ifndef COMPONENTS_SYNC_SESSIONS_FAVICON_CACHE_H_ |
6 #define COMPONENTS_SYNC_SESSIONS_FAVICON_CACHE_H_ | 6 #define COMPONENTS_SYNC_SESSIONS_FAVICON_CACHE_H_ |
7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
8 #include <map> | 11 #include <map> |
9 #include <set> | 12 #include <set> |
10 #include <string> | 13 #include <string> |
11 #include <vector> | 14 #include <vector> |
12 | 15 |
13 #include "base/basictypes.h" | |
14 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
15 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" |
16 #include "base/memory/linked_ptr.h" | 19 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
18 #include "base/memory/ref_counted_memory.h" | 21 #include "base/memory/ref_counted_memory.h" |
19 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
20 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
21 #include "base/scoped_observer.h" | 24 #include "base/scoped_observer.h" |
22 #include "base/task/cancelable_task_tracker.h" | 25 #include "base/task/cancelable_task_tracker.h" |
23 #include "components/history/core/browser/history_service_observer.h" | 26 #include "components/history/core/browser/history_service_observer.h" |
24 #include "components/history/core/browser/history_types.h" | 27 #include "components/history/core/browser/history_types.h" |
25 #include "components/sessions/core/session_id.h" | 28 #include "components/sessions/core/session_id.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // If no favicon exists associated with |favicon_url|, triggers a load | 101 // If no favicon exists associated with |favicon_url|, triggers a load |
99 // for the favicon associated with |page_url|. | 102 // for the favicon associated with |page_url|. |
100 void OnFaviconVisited(const GURL& page_url, const GURL& favicon_url); | 103 void OnFaviconVisited(const GURL& page_url, const GURL& favicon_url); |
101 | 104 |
102 // Consume Session sync favicon data. Will not overwrite existing favicons. | 105 // Consume Session sync favicon data. Will not overwrite existing favicons. |
103 // If |icon_bytes| is empty, only updates the page->favicon url mapping. | 106 // If |icon_bytes| is empty, only updates the page->favicon url mapping. |
104 // Safe to call within a transaction. | 107 // Safe to call within a transaction. |
105 void OnReceivedSyncFavicon(const GURL& page_url, | 108 void OnReceivedSyncFavicon(const GURL& page_url, |
106 const GURL& icon_url, | 109 const GURL& icon_url, |
107 const std::string& icon_bytes, | 110 const std::string& icon_bytes, |
108 int64 visit_time_ms); | 111 int64_t visit_time_ms); |
109 | 112 |
110 private: | 113 private: |
111 friend class SyncFaviconCacheTest; | 114 friend class SyncFaviconCacheTest; |
112 FRIEND_TEST_ALL_PREFIXES(SyncFaviconCacheTest, HistoryFullClear); | 115 FRIEND_TEST_ALL_PREFIXES(SyncFaviconCacheTest, HistoryFullClear); |
113 FRIEND_TEST_ALL_PREFIXES(SyncFaviconCacheTest, HistorySubsetClear); | 116 FRIEND_TEST_ALL_PREFIXES(SyncFaviconCacheTest, HistorySubsetClear); |
114 | 117 |
115 // Functor for ordering SyncedFaviconInfo objects by recency; | 118 // Functor for ordering SyncedFaviconInfo objects by recency; |
116 struct FaviconRecencyFunctor { | 119 struct FaviconRecencyFunctor { |
117 bool operator()(const linked_ptr<SyncedFaviconInfo>& lhs, | 120 bool operator()(const linked_ptr<SyncedFaviconInfo>& lhs, |
118 const linked_ptr<SyncedFaviconInfo>& rhs) const; | 121 const linked_ptr<SyncedFaviconInfo>& rhs) const; |
119 }; | 122 }; |
120 | 123 |
121 | 124 |
122 // Map of favicon url to favicon image. | 125 // Map of favicon url to favicon image. |
123 typedef std::map<GURL, linked_ptr<SyncedFaviconInfo> > FaviconMap; | 126 typedef std::map<GURL, linked_ptr<SyncedFaviconInfo> > FaviconMap; |
124 typedef std::set<linked_ptr<SyncedFaviconInfo>, | 127 typedef std::set<linked_ptr<SyncedFaviconInfo>, |
125 FaviconRecencyFunctor> RecencySet; | 128 FaviconRecencyFunctor> RecencySet; |
126 // Map of page url to task id (for favicon loading). | 129 // Map of page url to task id (for favicon loading). |
127 typedef std::map<GURL, base::CancelableTaskTracker::TaskId> PageTaskMap; | 130 typedef std::map<GURL, base::CancelableTaskTracker::TaskId> PageTaskMap; |
128 // Map of page url to favicon url. | 131 // Map of page url to favicon url. |
129 typedef std::map<GURL, GURL> PageFaviconMap; | 132 typedef std::map<GURL, GURL> PageFaviconMap; |
130 | 133 |
131 // Helper method to perform OnReceivedSyncFavicon work without worrying about | 134 // Helper method to perform OnReceivedSyncFavicon work without worrying about |
132 // whether caller holds a sync transaction. | 135 // whether caller holds a sync transaction. |
133 void OnReceivedSyncFaviconImpl(const GURL& icon_url, | 136 void OnReceivedSyncFaviconImpl(const GURL& icon_url, |
134 const std::string& icon_bytes, | 137 const std::string& icon_bytes, |
135 int64 visit_time_ms); | 138 int64_t visit_time_ms); |
136 | 139 |
137 // Callback method to store a tab's favicon into its sync node once it becomes | 140 // Callback method to store a tab's favicon into its sync node once it becomes |
138 // available. Does nothing if no favicon data was available. | 141 // available. Does nothing if no favicon data was available. |
139 void OnFaviconDataAvailable( | 142 void OnFaviconDataAvailable( |
140 const GURL& page_url, | 143 const GURL& page_url, |
141 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_result); | 144 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_result); |
142 | 145 |
143 // Helper method to update the sync state of the favicon at |icon_url|. If | 146 // Helper method to update the sync state of the favicon at |icon_url|. If |
144 // either |image_change_type| or |tracking_change_type| is ACTION_INVALID, | 147 // either |image_change_type| or |tracking_change_type| is ACTION_INVALID, |
145 // the corresponding datatype won't be updated. | 148 // the corresponding datatype won't be updated. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 246 |
244 // Weak pointer factory for favicon loads. | 247 // Weak pointer factory for favicon loads. |
245 base::WeakPtrFactory<FaviconCache> weak_ptr_factory_; | 248 base::WeakPtrFactory<FaviconCache> weak_ptr_factory_; |
246 | 249 |
247 DISALLOW_COPY_AND_ASSIGN(FaviconCache); | 250 DISALLOW_COPY_AND_ASSIGN(FaviconCache); |
248 }; | 251 }; |
249 | 252 |
250 } // namespace browser_sync | 253 } // namespace browser_sync |
251 | 254 |
252 #endif // COMPONENTS_SYNC_SESSIONS_FAVICON_CACHE_H_ | 255 #endif // COMPONENTS_SYNC_SESSIONS_FAVICON_CACHE_H_ |
OLD | NEW |