| 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 CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
| 6 #define CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 6 #define CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/browser/cancelable_request.h" | 12 #include "chrome/browser/cancelable_request.h" |
| 13 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
| 14 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 15 #include "chrome/common/ref_counted_util.h" | 14 #include "chrome/common/ref_counted_util.h" |
| 16 | 15 |
| 17 class GURL; | 16 class GURL; |
| 18 class HistoryService; | |
| 19 class Profile; | 17 class Profile; |
| 20 | 18 |
| 21 // The favicon service provides methods to access favicons. It calls the history | 19 // The favicon service provides methods to access favicons. It calls the history |
| 22 // backend behind the scenes. | 20 // backend behind the scenes. |
| 23 // | 21 // |
| 24 // This service is thread safe. Each request callback is invoked in the | 22 // This service is thread safe. Each request callback is invoked in the |
| 25 // thread that made the request. | 23 // thread that made the request. |
| 26 class FaviconService : public CancelableRequestProvider, | 24 class FaviconService : public CancelableRequestProvider { |
| 27 public ProfileKeyedService { | |
| 28 public: | 25 public: |
| 29 explicit FaviconService(HistoryService* history_service); | 26 explicit FaviconService(Profile* profile); |
| 30 | 27 |
| 31 virtual ~FaviconService(); | 28 virtual ~FaviconService(); |
| 32 | 29 |
| 33 // Callback for GetFavicon. If we have previously inquired about the favicon | 30 // Callback for GetFavicon. If we have previously inquired about the favicon |
| 34 // for this URL, |know_favicon| will be true, and the rest of the fields will | 31 // for this URL, |know_favicon| will be true, and the rest of the fields will |
| 35 // be valid (otherwise they will be ignored). | 32 // be valid (otherwise they will be ignored). |
| 36 // | 33 // |
| 37 // On |know_favicon| == true, |data| will either contain the PNG encoded | 34 // On |know_favicon| == true, |data| will either contain the PNG encoded |
| 38 // favicon data, or it will be NULL to indicate that the site does not have | 35 // favicon data, or it will be NULL to indicate that the site does not have |
| 39 // a favicon (in other words, we know the site doesn't have a favicon, as | 36 // a favicon (in other words, we know the site doesn't have a favicon, as |
| (...skipping 27 matching lines...) Expand all Loading... |
| 67 const FaviconDataCallback& callback); | 64 const FaviconDataCallback& callback); |
| 68 | 65 |
| 69 // Requests any |icon_types| of favicon for a web page URL. |consumer| is | 66 // Requests any |icon_types| of favicon for a web page URL. |consumer| is |
| 70 // notified when the bits have been fetched. |icon_types| can be any | 67 // notified when the bits have been fetched. |icon_types| can be any |
| 71 // combination of IconType value, but only one icon will be returned in the | 68 // combination of IconType value, but only one icon will be returned in the |
| 72 // priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and FAVICON. | 69 // priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and FAVICON. |
| 73 // | 70 // |
| 74 // Note: this version is intended to be used to retrieve the favicon of a | 71 // Note: this version is intended to be used to retrieve the favicon of a |
| 75 // page that has been browsed in the past. |expired| in the callback is | 72 // page that has been browsed in the past. |expired| in the callback is |
| 76 // always false. | 73 // always false. |
| 77 Handle GetFaviconForURL(Profile* profile, | 74 Handle GetFaviconForURL(const GURL& page_url, |
| 78 const GURL& page_url, | |
| 79 int icon_types, | 75 int icon_types, |
| 80 CancelableRequestConsumerBase* consumer, | 76 CancelableRequestConsumerBase* consumer, |
| 81 const FaviconDataCallback& callback); | 77 const FaviconDataCallback& callback); |
| 82 | 78 |
| 83 // Requests the favicon for |favicon_id|. The |consumer| is notified when the | 79 // Requests the favicon for |favicon_id|. The |consumer| is notified when the |
| 84 // bits have been fetched. | 80 // bits have been fetched. |
| 85 Handle GetFaviconForID(history::FaviconID favicon_id, | 81 Handle GetFaviconForID(history::FaviconID favicon_id, |
| 86 CancelableRequestConsumerBase* consumer, | 82 CancelableRequestConsumerBase* consumer, |
| 87 const FaviconDataCallback& callback); | 83 const FaviconDataCallback& callback); |
| 88 | 84 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 102 void SetImportedFavicons( | 98 void SetImportedFavicons( |
| 103 const std::vector<history::ImportedFaviconUsage>& favicon_usage); | 99 const std::vector<history::ImportedFaviconUsage>& favicon_usage); |
| 104 | 100 |
| 105 // Sets the favicon for a page. | 101 // Sets the favicon for a page. |
| 106 void SetFavicon(const GURL& page_url, | 102 void SetFavicon(const GURL& page_url, |
| 107 const GURL& icon_url, | 103 const GURL& icon_url, |
| 108 const std::vector<unsigned char>& image_data, | 104 const std::vector<unsigned char>& image_data, |
| 109 history::IconType icon_type); | 105 history::IconType icon_type); |
| 110 | 106 |
| 111 private: | 107 private: |
| 112 HistoryService* history_service_; | 108 Profile* profile_; |
| 113 | 109 |
| 114 // Helper to forward an empty result if we cannot get the history service. | 110 // Helper to forward an empty result if we cannot get the history service. |
| 115 void ForwardEmptyResultAsync(GetFaviconRequest* request); | 111 void ForwardEmptyResultAsync(GetFaviconRequest* request); |
| 116 | 112 |
| 117 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 113 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
| 118 }; | 114 }; |
| 119 | 115 |
| 120 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 116 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
| OLD | NEW |