Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1094)

Side by Side Diff: chrome/browser/ui/webui/large_icon_source.h

Issue 1092873002: [Icons NTP] Refactor large_icon_source to extract the logic shared between desktop and Android to f… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_LARGE_ICON_SOURCE_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
6 #define CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ 6 #define CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
10 9
11 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
12 #include "base/task/cancelable_task_tracker.h" 11 #include "base/task/cancelable_task_tracker.h"
13 #include "components/favicon/core/fallback_icon_service.h" 12 #include "components/favicon/core/fallback_icon_service.h"
14 #include "components/favicon_base/favicon_types.h" 13 #include "components/favicon_base/favicon_types.h"
pkotwicz 2015/04/21 18:19:48 You can remove the above include?
beaudoin 2015/04/21 19:03:23 Done.
15 #include "content/public/browser/url_data_source.h" 14 #include "content/public/browser/url_data_source.h"
16 #include "third_party/skia/include/core/SkColor.h"
17 15
18 namespace favicon { 16 namespace favicon {
19 class FallbackIconService; 17 class FallbackIconService;
20 class FaviconService; 18 class LargeIconService;
21 } 19 }
22 20
23 // LargeIconSource services explicit chrome:// requests for large icons. 21 // LargeIconSource services explicit chrome:// requests for large icons.
24 // 22 //
25 // Format: 23 // Format:
26 // chrome://large-icon/size/url 24 // chrome://large-icon/size/url
27 // 25 //
28 // Parameter: 26 // Parameter:
29 // 'size' Required (including trailing '/') 27 // 'size' Required (including trailing '/')
30 // Positive integer to specify the large icon's size in pixels. 28 // Positive integer to specify the large icon's size in pixels.
31 // 'url' Optional 29 // 'url' Optional
32 // String to specify the page URL of the large icon. 30 // String to specify the page URL of the large icon.
33 // 31 //
34 // Example: chrome://large-icon/48/http://www.google.com/ 32 // Example: chrome://large-icon/48/http://www.google.com/
35 // This requests a 48x48 large icon for http://www.google.com. 33 // This requests a 48x48 large icon for http://www.google.com.
36 class LargeIconSource : public content::URLDataSource { 34 class LargeIconSource : public content::URLDataSource {
37 public: 35 public:
38 // |favicon_service| and |fallback_icon_service| are owned by caller and may 36 // |fallback_icon_service| and |large_icon_service| are owned by caller and
39 // be null. 37 // may be null.
40 LargeIconSource(favicon::FaviconService* favicon_service, 38 LargeIconSource(favicon::FallbackIconService* fallback_icon_service,
41 favicon::FallbackIconService* fallback_icon_service); 39 favicon::LargeIconService* large_icon_service);
42 40
43 ~LargeIconSource() override; 41 ~LargeIconSource() override;
44 42
45 // content::URLDataSource implementation. 43 // content::URLDataSource implementation.
46 std::string GetSource() const override; 44 std::string GetSource() const override;
47 void StartDataRequest( 45 void StartDataRequest(
48 const std::string& path, 46 const std::string& path,
49 int render_process_id, 47 int render_process_id,
50 int render_frame_id, 48 int render_frame_id,
51 const content::URLDataSource::GotDataCallback& callback) override; 49 const content::URLDataSource::GotDataCallback& callback) override;
52 std::string GetMimeType(const std::string&) const override; 50 std::string GetMimeType(const std::string&) const override;
53 bool ShouldReplaceExistingSource() const override; 51 bool ShouldReplaceExistingSource() const override;
54 bool ShouldServiceRequest(const net::URLRequest* request) const override; 52 bool ShouldServiceRequest(const net::URLRequest* request) const override;
55 53
56 protected:
57 struct IconRequest {
58 IconRequest();
59 IconRequest(const content::URLDataSource::GotDataCallback& callback_in,
60 const GURL& path_in,
61 int size_in);
62 ~IconRequest();
63
64 content::URLDataSource::GotDataCallback callback;
65 GURL url;
66 int size;
67 };
68
69 private: 54 private:
70 // Callback for icon data retrieval request. 55 // Callback to retrieve data for large icon.
pkotwicz 2015/04/21 18:19:48 How about: "Called with results of large icon retr
beaudoin 2015/04/21 19:03:23 Done.
71 void OnIconDataAvailable( 56 void OnLargeIconDataAvailable(
72 const IconRequest& request, 57 const content::URLDataSource::GotDataCallback& callback,
73 const favicon_base::FaviconRawBitmapResult& bitmap_result); 58 const GURL& url,
74 59 int size,
75 // Renders and sends a default fallback icon. This is used when there is no 60 const favicon_base::LargeIconResult& bitmap_result);
76 // known text and/or foreground color to use for the generated icon (it
77 // defaults to a light text color on a dark gray background).
78 void SendDefaultFallbackIcon(const IconRequest& request);
79
80 // Renders and sends a fallback icon using the given colors.
81 void SendFallbackIcon(const IconRequest& request,
82 SkColor text_color,
83 SkColor background_color);
84 61
85 // Returns null to trigger "Not Found" response. 62 // Returns null to trigger "Not Found" response.
86 void SendNotFoundResponse( 63 void SendNotFoundResponse(
87 const content::URLDataSource::GotDataCallback& callback); 64 const content::URLDataSource::GotDataCallback& callback);
88 65
89 base::CancelableTaskTracker cancelable_task_tracker_; 66 base::CancelableTaskTracker cancelable_task_tracker_;
90 67
91 favicon::FaviconService* favicon_service_;
92
93 favicon::FallbackIconService* fallback_icon_service_; 68 favicon::FallbackIconService* fallback_icon_service_;
James Hawkins 2015/04/21 17:08:25 I know we document that an object owns a given poi
beaudoin 2015/04/21 18:09:54 Done.
94 69
95 // A pre-populated list of the types of icon files to consider when looking 70 favicon::LargeIconService* large_icon_service_;
96 // for the largest matching icon.
97 // Note: this is simply an optimization over populating an icon type vector
98 // on each request.
99 std::vector<int> large_icon_types_;
100 71
101 DISALLOW_COPY_AND_ASSIGN(LargeIconSource); 72 DISALLOW_COPY_AND_ASSIGN(LargeIconSource);
102 }; 73 };
103 74
104 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_ 75 #endif // CHROME_BROWSER_UI_WEBUI_LARGE_ICON_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698