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_UI_WEBUI_FAVICON_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "chrome/browser/favicon/favicon_service.h" | 13 #include "chrome/browser/favicon/favicon_service.h" |
14 #include "chrome/common/cancelable_task_tracker.h" | 14 #include "chrome/common/cancelable_task_tracker.h" |
15 #include "content/public/browser/url_data_source_delegate.h" | 15 #include "content/public/browser/url_data_source.h" |
16 #include "ui/gfx/favicon_size.h" | 16 #include "ui/gfx/favicon_size.h" |
17 | 17 |
18 class Profile; | 18 class Profile; |
19 | 19 |
20 // FaviconSource is the gateway between network-level chrome: | 20 // FaviconSource is the gateway between network-level chrome: |
21 // requests for favicons and the history backend that serves these. | 21 // requests for favicons and the history backend that serves these. |
22 class FaviconSource : public content::URLDataSourceDelegate { | 22 class FaviconSource : public content::URLDataSource { |
23 public: | 23 public: |
24 // Defines the type of icon the FaviconSource will provide. | 24 // Defines the type of icon the FaviconSource will provide. |
25 enum IconType { | 25 enum IconType { |
26 FAVICON, | 26 FAVICON, |
27 // Any available icon in the priority of TOUCH_ICON_PRECOMPOSED, TOUCH_ICON, | 27 // Any available icon in the priority of TOUCH_ICON_PRECOMPOSED, TOUCH_ICON, |
28 // FAVICON, and default favicon. | 28 // FAVICON, and default favicon. |
29 ANY | 29 ANY |
30 }; | 30 }; |
31 | 31 |
32 // |type| is the type of icon this FaviconSource will provide. | 32 // |type| is the type of icon this FaviconSource will provide. |
33 FaviconSource(Profile* profile, IconType type); | 33 FaviconSource(Profile* profile, IconType type); |
34 | 34 |
35 // content::URLDataSourceDelegate implementation. | 35 // content::URLDataSource implementation. |
36 virtual std::string GetSource() OVERRIDE; | 36 virtual std::string GetSource() OVERRIDE; |
37 virtual void StartDataRequest(const std::string& path, | 37 virtual void StartDataRequest( |
38 bool is_incognito, | 38 const std::string& path, |
39 int request_id) OVERRIDE; | 39 bool is_incognito, |
| 40 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
40 virtual std::string GetMimeType(const std::string&) const OVERRIDE; | 41 virtual std::string GetMimeType(const std::string&) const OVERRIDE; |
41 virtual bool ShouldReplaceExistingSource() const OVERRIDE; | 42 virtual bool ShouldReplaceExistingSource() const OVERRIDE; |
42 | 43 |
43 protected: | 44 protected: |
44 struct IconRequest { | 45 struct IconRequest { |
45 IconRequest() | 46 IconRequest(); |
46 : request_id(0), | 47 IconRequest(const content::URLDataSource::GotDataCallback& cb, |
47 request_path(""), | |
48 size_in_dip(gfx::kFaviconSize), | |
49 scale_factor(ui::SCALE_FACTOR_NONE) { | |
50 } | |
51 IconRequest(int id, | |
52 const std::string& path, | 48 const std::string& path, |
53 int size, | 49 int size, |
54 ui::ScaleFactor scale) | 50 ui::ScaleFactor scale); |
55 : request_id(id), | 51 ~IconRequest(); |
56 request_path(path), | 52 |
57 size_in_dip(size), | 53 content::URLDataSource::GotDataCallback callback; |
58 scale_factor(scale) { | |
59 } | |
60 int request_id; | |
61 std::string request_path; | 54 std::string request_path; |
62 int size_in_dip; | 55 int size_in_dip; |
63 ui::ScaleFactor scale_factor; | 56 ui::ScaleFactor scale_factor; |
64 }; | 57 }; |
65 | 58 |
66 virtual ~FaviconSource(); | 59 virtual ~FaviconSource(); |
67 | 60 |
68 // Called when the favicon data is missing to perform additional checks to | 61 // Called when the favicon data is missing to perform additional checks to |
69 // locate the resource. | 62 // locate the resource. |
70 // |request| contains information for the failed request. | 63 // |request| contains information for the failed request. |
(...skipping 25 matching lines...) Expand all Loading... |
96 // database doesn't have a favicon for a webpage. Indexed by IconSize values. | 89 // database doesn't have a favicon for a webpage. Indexed by IconSize values. |
97 scoped_refptr<base::RefCountedMemory> default_favicons_[NUM_SIZES]; | 90 scoped_refptr<base::RefCountedMemory> default_favicons_[NUM_SIZES]; |
98 | 91 |
99 // The history::IconTypes of icon that this FaviconSource handles. | 92 // The history::IconTypes of icon that this FaviconSource handles. |
100 int icon_types_; | 93 int icon_types_; |
101 | 94 |
102 DISALLOW_COPY_AND_ASSIGN(FaviconSource); | 95 DISALLOW_COPY_AND_ASSIGN(FaviconSource); |
103 }; | 96 }; |
104 | 97 |
105 #endif // CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ | 98 #endif // CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |
OLD | NEW |