OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_HISTORY_CORE_BROWSER_THUMBNAIL_DATABASE_H_ | 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_THUMBNAIL_DATABASE_H_ |
6 #define COMPONENTS_HISTORY_CORE_BROWSER_THUMBNAIL_DATABASE_H_ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_THUMBNAIL_DATABASE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "components/history/core/browser/history_types.h" | 13 #include "components/history/core/browser/history_types.h" |
14 #include "sql/connection.h" | 14 #include "sql/connection.h" |
15 #include "sql/init_status.h" | 15 #include "sql/init_status.h" |
16 #include "sql/meta_table.h" | 16 #include "sql/meta_table.h" |
17 #include "sql/statement.h" | 17 #include "sql/statement.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class FilePath; | 20 class FilePath; |
21 class RefCountedMemory; | 21 class RefCountedMemory; |
22 class Time; | 22 class Time; |
23 } | 23 } |
24 | 24 |
25 namespace history { | 25 namespace history { |
26 | 26 |
27 class HistoryBackendClient; | 27 class HistoryBackendClient; |
28 | 28 |
| 29 // The minimum number of days after which last_requested field gets updated. |
| 30 // All earlier updates are ignored. |
| 31 static const int kFaviconUpdateLastRequestedAfterDays = 14; |
| 32 |
29 // This database interface is owned by the history backend and runs on the | 33 // This database interface is owned by the history backend and runs on the |
30 // history thread. It is a totally separate component from history partially | 34 // history thread. It is a totally separate component from history partially |
31 // because we may want to move it to its own thread in the future. The | 35 // because we may want to move it to its own thread in the future. The |
32 // operations we will do on this database will be slow, but we can tolerate | 36 // operations we will do on this database will be slow, but we can tolerate |
33 // higher latency (it's OK for thumbnails to come in slower than the rest | 37 // higher latency (it's OK for thumbnails to come in slower than the rest |
34 // of the data). Moving this to a separate thread would not block potentially | 38 // of the data). Moving this to a separate thread would not block potentially |
35 // higher priority history operations. | 39 // higher priority history operations. |
36 class ThumbnailDatabase { | 40 class ThumbnailDatabase { |
37 public: | 41 public: |
38 explicit ThumbnailDatabase(HistoryBackendClient* backend_client); | 42 explicit ThumbnailDatabase(HistoryBackendClient* backend_client); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 std::vector<FaviconBitmap>* favicon_bitmaps); | 84 std::vector<FaviconBitmap>* favicon_bitmaps); |
81 | 85 |
82 // Gets the last updated time, bitmap data, and pixel size of the favicon | 86 // Gets the last updated time, bitmap data, and pixel size of the favicon |
83 // bitmap at |bitmap_id|. Returns true if successful. | 87 // bitmap at |bitmap_id|. Returns true if successful. |
84 bool GetFaviconBitmap(FaviconBitmapID bitmap_id, | 88 bool GetFaviconBitmap(FaviconBitmapID bitmap_id, |
85 base::Time* last_updated, | 89 base::Time* last_updated, |
86 base::Time* last_requested, | 90 base::Time* last_requested, |
87 scoped_refptr<base::RefCountedMemory>* png_icon_data, | 91 scoped_refptr<base::RefCountedMemory>* png_icon_data, |
88 gfx::Size* pixel_size); | 92 gfx::Size* pixel_size); |
89 | 93 |
90 // Adds a bitmap component at |pixel_size| for the favicon with |icon_id|. | 94 // Adds a bitmap component of |type| at |pixel_size| for the favicon with |
91 // Only favicons representing a .ico file should have multiple favicon bitmaps | 95 // |icon_id|. Only favicons representing a .ico file should have multiple |
92 // per favicon. | 96 // favicon bitmaps per favicon. |
93 // |icon_data| is the png encoded data. | 97 // |icon_data| is the png encoded data. |
94 // The |time| indicates the access time, and is used to detect when the | 98 // The |type| indicates how the lifetime of this icon should be managed. |
95 // favicon should be refreshed. | 99 // The |time| is used for lifetime management of the bitmap (should be Now()). |
96 // |pixel_size| is the pixel dimensions of |icon_data|. | 100 // |pixel_size| is the pixel dimensions of |icon_data|. |
97 // Returns the id of the added bitmap or 0 if unsuccessful. | 101 // Returns the id of the added bitmap or 0 if unsuccessful. |
98 FaviconBitmapID AddFaviconBitmap( | 102 FaviconBitmapID AddFaviconBitmap( |
99 favicon_base::FaviconID icon_id, | 103 favicon_base::FaviconID icon_id, |
100 const scoped_refptr<base::RefCountedMemory>& icon_data, | 104 const scoped_refptr<base::RefCountedMemory>& icon_data, |
| 105 FaviconBitmapType type, |
101 base::Time time, | 106 base::Time time, |
102 const gfx::Size& pixel_size); | 107 const gfx::Size& pixel_size); |
103 | 108 |
104 // Sets the bitmap data and the last updated time for the favicon bitmap at | 109 // Sets the bitmap data and the last updated time for the favicon bitmap at |
105 // |bitmap_id|. | 110 // |bitmap_id|. Should not be called for bitmaps of type ON_DEMAND as they |
| 111 // should never get updated (the call silently changes the type to ON_VISIT). |
106 // Returns true if successful. | 112 // Returns true if successful. |
107 bool SetFaviconBitmap(FaviconBitmapID bitmap_id, | 113 bool SetFaviconBitmap(FaviconBitmapID bitmap_id, |
108 scoped_refptr<base::RefCountedMemory> bitmap_data, | 114 scoped_refptr<base::RefCountedMemory> bitmap_data, |
109 base::Time time); | 115 base::Time time); |
110 | 116 |
111 // Sets the last updated time for the favicon bitmap at |bitmap_id|. | 117 // Sets the last_updated time for the favicon bitmap at |bitmap_id|. Should |
112 // Returns true if successful. | 118 // not be called for bitmaps of type ON_DEMAND as last_updated time is only |
| 119 // tracked for ON_VISIT bitmaps (the call silently changes the type to |
| 120 // ON_VISIT). Returns true if successful. |
113 bool SetFaviconBitmapLastUpdateTime(FaviconBitmapID bitmap_id, | 121 bool SetFaviconBitmapLastUpdateTime(FaviconBitmapID bitmap_id, |
114 base::Time time); | 122 base::Time time); |
115 | 123 |
116 // Sets the last requested time for the favicon bitmap at |bitmap_id|. | |
117 // Returns true if successful. | |
118 bool SetFaviconBitmapLastRequestedTime(FaviconBitmapID bitmap_id, | |
119 base::Time time); | |
120 | |
121 // Deletes the favicon bitmap with |bitmap_id|. | 124 // Deletes the favicon bitmap with |bitmap_id|. |
122 // Returns true if successful. | 125 // Returns true if successful. |
123 bool DeleteFaviconBitmap(FaviconBitmapID bitmap_id); | 126 bool DeleteFaviconBitmap(FaviconBitmapID bitmap_id); |
124 | 127 |
125 // Favicons ------------------------------------------------------------------ | 128 // Favicons ------------------------------------------------------------------ |
126 | 129 |
127 // Sets the the favicon as out of date. This will set |last_updated| for all | 130 // Sets the the favicon as out of date. This will set |last_updated| for all |
128 // of the bitmaps for |icon_id| to be out of date. | 131 // of the bitmaps for |icon_id| to be out of date. |
129 bool SetFaviconOutOfDate(favicon_base::FaviconID icon_id); | 132 bool SetFaviconOutOfDate(favicon_base::FaviconID icon_id); |
130 | 133 |
| 134 // Mark all bitmaps of type ON_DEMAND at |icon_url| as requested at |time|. |
| 135 // This postpones their automatic eviction from the database. Not all calls |
| 136 // end up in a write into the DB: |
| 137 // - it is no-op if the bitmaps are not of type ON_DEMAND; |
| 138 // - the updates of the "last requested time" have limited frequency for each |
| 139 // particular bitmap (e.g. once per week). This limits the overhead of |
| 140 // cache management for on-demand favicons. |
| 141 // Returns true if successful. |
| 142 bool TouchOnDemandFavicon(const GURL& icon_url, base::Time time); |
| 143 |
131 // Returns the id of the entry in the favicon database with the specified url | 144 // Returns the id of the entry in the favicon database with the specified url |
132 // and icon type. | 145 // and icon type. |
133 // Returns 0 if no entry exists for the specified url. | 146 // Returns 0 if no entry exists for the specified url. |
134 favicon_base::FaviconID GetFaviconIDForFaviconURL( | 147 favicon_base::FaviconID GetFaviconIDForFaviconURL( |
135 const GURL& icon_url, | 148 const GURL& icon_url, |
136 favicon_base::IconType icon_type); | 149 favicon_base::IconType icon_type); |
137 | 150 |
138 // Gets the icon_url, icon_type and sizes for the specified |icon_id|. | 151 // Gets the icon_url, icon_type and sizes for the specified |icon_id|. |
139 bool GetFaviconHeader(favicon_base::FaviconID icon_id, | 152 bool GetFaviconHeader(favicon_base::FaviconID icon_id, |
140 GURL* icon_url, | 153 GURL* icon_url, |
141 favicon_base::IconType* icon_type); | 154 favicon_base::IconType* icon_type); |
142 | 155 |
143 // Adds favicon with |icon_url|, |icon_type| and |favicon_sizes| to the | 156 // Adds favicon with |icon_url|, |icon_type| and |favicon_sizes| to the |
144 // favicon db, returning its id. | 157 // favicon db, returning its id. |
145 favicon_base::FaviconID AddFavicon(const GURL& icon_url, | 158 favicon_base::FaviconID AddFavicon(const GURL& icon_url, |
146 favicon_base::IconType icon_type); | 159 favicon_base::IconType icon_type); |
147 | 160 |
148 // Adds a favicon with a single bitmap. This call is equivalent to calling | 161 // Adds a favicon with a single bitmap. This call is equivalent to calling |
149 // AddFavicon and AddFaviconBitmap. | 162 // AddFavicon and AddFaviconBitmap of type |type|. |
150 favicon_base::FaviconID AddFavicon( | 163 favicon_base::FaviconID AddFavicon( |
151 const GURL& icon_url, | 164 const GURL& icon_url, |
152 favicon_base::IconType icon_type, | 165 favicon_base::IconType icon_type, |
153 const scoped_refptr<base::RefCountedMemory>& icon_data, | 166 const scoped_refptr<base::RefCountedMemory>& icon_data, |
| 167 FaviconBitmapType type, |
154 base::Time time, | 168 base::Time time, |
155 const gfx::Size& pixel_size); | 169 const gfx::Size& pixel_size); |
156 | 170 |
157 // Delete the favicon with the provided id. Returns false on failure | 171 // Delete the favicon with the provided id. Returns false on failure |
158 bool DeleteFavicon(favicon_base::FaviconID id); | 172 bool DeleteFavicon(favicon_base::FaviconID id); |
159 | 173 |
160 // Icon Mapping -------------------------------------------------------------- | 174 // Icon Mapping -------------------------------------------------------------- |
161 // | 175 // |
162 // Returns true if there is a matched icon mapping for the given page and | 176 // Returns true if there is a matched icon mapping for the given page and |
163 // icon type. | 177 // icon type. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 277 |
264 sql::Connection db_; | 278 sql::Connection db_; |
265 sql::MetaTable meta_table_; | 279 sql::MetaTable meta_table_; |
266 | 280 |
267 HistoryBackendClient* backend_client_; | 281 HistoryBackendClient* backend_client_; |
268 }; | 282 }; |
269 | 283 |
270 } // namespace history | 284 } // namespace history |
271 | 285 |
272 #endif // COMPONENTS_HISTORY_CORE_BROWSER_THUMBNAIL_DATABASE_H_ | 286 #endif // COMPONENTS_HISTORY_CORE_BROWSER_THUMBNAIL_DATABASE_H_ |
OLD | NEW |