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