Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_FAVICON_SERVICE_H__ | 5 #ifndef CHROME_BROWSER_FAVICON_SERVICE_H__ |
| 6 #define CHROME_BROWSER_FAVICON_SERVICE_H__ | 6 #define CHROME_BROWSER_FAVICON_SERVICE_H__ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 // The favicon service provides methods to access favicons. It calls the history | 21 // The favicon service provides methods to access favicons. It calls the history |
| 22 // backend behind the scenes. | 22 // backend behind the scenes. |
| 23 // | 23 // |
| 24 // This service is thread safe. Each request callback is invoked in the | 24 // This service is thread safe. Each request callback is invoked in the |
| 25 // thread that made the request. | 25 // thread that made the request. |
| 26 class FaviconService : public CancelableRequestProvider, | 26 class FaviconService : public CancelableRequestProvider, |
| 27 public base::RefCountedThreadSafe<FaviconService> { | 27 public base::RefCountedThreadSafe<FaviconService> { |
| 28 public: | 28 public: |
| 29 explicit FaviconService(Profile* profile); | 29 explicit FaviconService(Profile* profile); |
| 30 | 30 |
| 31 struct FaviconData { | |
|
sky
2011/03/10 17:54:44
Put this in history_types
michaelbai
2011/03/11 01:11:28
Done.
| |
| 32 FaviconData(); | |
| 33 ~FaviconData(); | |
| 34 | |
| 35 // Indicates whether the icon is known by the history backend. | |
| 36 bool known_icon; | |
| 37 | |
| 38 // The bits of image. | |
| 39 scoped_refptr<RefCountedMemory> image_data; | |
| 40 | |
| 41 // Indicates whether image is expired. | |
| 42 bool expired; | |
| 43 | |
| 44 // The icon's URL. | |
| 45 GURL icon_url; | |
| 46 | |
| 47 // The type of favicon. | |
| 48 history::IconType icon_type; | |
| 49 }; | |
| 50 | |
| 31 // Callback for GetFavicon. If we have previously inquired about the favicon | 51 // Callback for GetFavicon. If we have previously inquired about the favicon |
| 32 // for this URL, |know_favicon| will be true, and the rest of the fields will | 52 // for this URL, |know_favicon| will be true, and the rest of the fields will |
| 33 // be valid (otherwise they will be ignored). | 53 // be valid (otherwise they will be ignored). |
| 34 // | 54 // |
| 35 // On |know_favicon| == true, |data| will either contain the PNG encoded | 55 // On |know_favicon| == true, |data| will either contain the PNG encoded |
| 36 // favicon data, or it will be NULL to indicate that the site does not have | 56 // favicon data, or it will be NULL to indicate that the site does not have |
| 37 // a favicon (in other words, we know the site doesn't have a favicon, as | 57 // a favicon (in other words, we know the site doesn't have a favicon, as |
| 38 // opposed to not knowing anything). |expired| will be set to true if we | 58 // opposed to not knowing anything). |expired| will be set to true if we |
| 39 // refreshed the favicon "too long" ago and should be updated if the page | 59 // refreshed the favicon "too long" ago and should be updated if the page |
| 40 // is visited again. | 60 // is visited again. |
| 41 typedef Callback5<Handle, // handle | 61 typedef Callback2<Handle, // handle |
| 42 bool, // know_favicon | 62 FaviconData>::Type // the type of favicon |
|
sky
2011/03/10 17:54:44
Can this take a const FaviconData& ?
michaelbai
2011/03/11 01:11:28
I think we can't use '&', callback is posted to me
| |
| 43 scoped_refptr<RefCountedMemory>, // data | |
| 44 bool, // expired | |
| 45 GURL>::Type // url of the favicon | |
| 46 FaviconDataCallback; | 63 FaviconDataCallback; |
| 47 | 64 |
| 48 typedef CancelableRequest<FaviconDataCallback> GetFaviconRequest; | 65 typedef CancelableRequest<FaviconDataCallback> GetFaviconRequest; |
| 49 | 66 |
| 50 // Requests the favicon. |consumer| is notified when the bits have been | 67 // Requests the |icon_type| of favicon. |consumer| is notified when the bits |
| 51 // fetched. | 68 // have been fetched. |
| 52 Handle GetFavicon(const GURL& icon_url, | 69 Handle GetFavicon(const GURL& icon_url, |
| 70 history::IconType icon_type, | |
| 53 CancelableRequestConsumerBase* consumer, | 71 CancelableRequestConsumerBase* consumer, |
| 54 FaviconDataCallback* callback); | 72 FaviconDataCallback* callback); |
| 55 | 73 |
| 56 // Fetches the favicon at |icon_url|, sending the results to the given | 74 // Fetches the |icon_type| of favicon at |icon_url|, sending the results to |
| 57 // |callback|. If the favicon has previously been set via SetFavicon(), then | 75 // the given |callback|. If the favicon has previously been set via |
| 58 // the favicon URL for |page_url| and all redirects is set to |icon_url|. If | 76 // SetFavicon(), then the favicon URL for |page_url| and all redirects is set |
| 59 // the favicon has not been set, the database is not updated. | 77 // to |icon_url|. If the favicon has not been set, the database is not |
| 78 // updated. | |
| 60 Handle UpdateFaviconMappingAndFetch(const GURL& page_url, | 79 Handle UpdateFaviconMappingAndFetch(const GURL& page_url, |
| 61 const GURL& icon_url, | 80 const GURL& icon_url, |
| 81 history::IconType icon_type, | |
| 62 CancelableRequestConsumerBase* consumer, | 82 CancelableRequestConsumerBase* consumer, |
| 63 FaviconDataCallback* callback); | 83 FaviconDataCallback* callback); |
| 64 | 84 |
| 65 // Requests a favicon for a web page URL. |consumer| is notified | 85 // Requests any |icon_type| of favicon for a web page URL. |consumer| is |
| 66 // when the bits have been fetched. | 86 // notified when the bits have been fetched. |icon_type| can be any |
| 87 // combination of IconType value, but only one icon will be returned in the | |
| 88 // priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and FAV_ICON. | |
| 67 // | 89 // |
| 68 // Note: this version is intended to be used to retrieve the favicon of a | 90 // Note: this version is intended to be used to retrieve the favicon of a |
| 69 // page that has been browsed in the past. |expired| in the callback is | 91 // page that has been browsed in the past. |expired| in the callback is |
| 70 // always false. | 92 // always false. |
| 71 Handle GetFaviconForURL(const GURL& page_url, | 93 Handle GetFaviconForURL(const GURL& page_url, |
| 94 int icon_types, | |
| 72 CancelableRequestConsumerBase* consumer, | 95 CancelableRequestConsumerBase* consumer, |
| 73 FaviconDataCallback* callback); | 96 FaviconDataCallback* callback); |
| 74 | 97 |
| 75 // Marks the favicon for the page as being out of date. | 98 // Marks the all type of favicon for the page as being out of date. |
|
sky
2011/03/10 17:54:44
marks all icon types for ...
michaelbai
2011/03/11 01:11:28
Done.
| |
| 76 void SetFaviconOutOfDateForPage(const GURL& page_url); | 99 void SetFaviconOutOfDateForPage(const GURL& page_url); |
| 77 | 100 |
| 78 // Allows the importer to set many favicons for many pages at once. The pages | 101 // Allows the importer to set many favicons for many pages at once. The pages |
| 79 // must exist, any favicon sets for unknown pages will be discarded. Existing | 102 // must exist, any favicon sets for unknown pages will be discarded. Existing |
| 80 // favicons will not be overwritten. | 103 // favicons will not be overwritten. |
| 81 void SetImportedFavicons( | 104 void SetImportedFavicons( |
| 82 const std::vector<history::ImportedFavIconUsage>& favicon_usage); | 105 const std::vector<history::ImportedFavIconUsage>& favicon_usage); |
| 83 | 106 |
| 84 // Sets the favicon for a page. | 107 // Sets the favicon for a page. |
| 85 void SetFavicon(const GURL& page_url, | 108 void SetFavicon(const GURL& page_url, |
| 86 const GURL& icon_url, | 109 const GURL& icon_url, |
| 87 const std::vector<unsigned char>& image_data); | 110 const std::vector<unsigned char>& image_data, |
| 111 history::IconType icon_type); | |
| 88 | 112 |
| 89 private: | 113 private: |
| 90 friend class base::RefCountedThreadSafe<FaviconService>; | 114 friend class base::RefCountedThreadSafe<FaviconService>; |
| 91 | 115 |
| 92 ~FaviconService(); | 116 ~FaviconService(); |
| 93 | 117 |
| 94 Profile* profile_; | 118 Profile* profile_; |
| 95 | 119 |
| 96 // Helper to forward an empty result if we cannot get the history service. | 120 // Helper to forward an empty result if we cannot get the history service. |
| 97 void ForwardEmptyResultAsync(GetFaviconRequest* request); | 121 void ForwardEmptyResultAsync(GetFaviconRequest* request); |
| 98 | 122 |
| 99 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 123 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
| 100 }; | 124 }; |
| 101 | 125 |
| 102 #endif // CHROME_BROWSER_FAVICON_SERVICE_H__ | 126 #endif // CHROME_BROWSER_FAVICON_SERVICE_H__ |
| OLD | NEW |