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

Side by Side Diff: chrome/browser/ui/webui/fileicon_source.cc

Issue 291733004: Reduce the use of ui::ScaleFactor in webui/favicon (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/ui/webui/fileicon_source.h" 5 #include "chrome/browser/ui/webui/fileicon_source.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 IconLoader::IconSize SizeStringToIconSize(const std::string& size_string) { 55 IconLoader::IconSize SizeStringToIconSize(const std::string& size_string) {
56 if (size_string == "small") return IconLoader::SMALL; 56 if (size_string == "small") return IconLoader::SMALL;
57 if (size_string == "large") return IconLoader::LARGE; 57 if (size_string == "large") return IconLoader::LARGE;
58 // We default to NORMAL if we don't recognize the size_string. Including 58 // We default to NORMAL if we don't recognize the size_string. Including
59 // size_string=="normal". 59 // size_string=="normal".
60 return IconLoader::NORMAL; 60 return IconLoader::NORMAL;
61 } 61 }
62 62
63 // Simple parser for data on the query. 63 // Simple parser for data on the query.
64 void ParseQueryParams(const std::string& query, 64 void ParseQueryParams(const std::string& query,
65 ui::ScaleFactor* scale_factor, 65 float* scale_factor,
66 IconLoader::IconSize* icon_size) { 66 IconLoader::IconSize* icon_size) {
67 typedef std::pair<std::string, std::string> KVPair; 67 typedef std::pair<std::string, std::string> KVPair;
68 std::vector<KVPair> parameters; 68 std::vector<KVPair> parameters;
69 if (icon_size) 69 if (icon_size)
70 *icon_size = IconLoader::NORMAL; 70 *icon_size = IconLoader::NORMAL;
71 if (scale_factor) 71 if (scale_factor)
72 *scale_factor = ui::SCALE_FACTOR_100P; 72 *scale_factor = 1.0f;
73 base::SplitStringIntoKeyValuePairs(query, '=', '&', &parameters); 73 base::SplitStringIntoKeyValuePairs(query, '=', '&', &parameters);
74 for (std::vector<KVPair>::const_iterator iter = parameters.begin(); 74 for (std::vector<KVPair>::const_iterator iter = parameters.begin();
75 iter != parameters.end(); ++iter) { 75 iter != parameters.end(); ++iter) {
76 if (icon_size && iter->first == kIconSize) 76 if (icon_size && iter->first == kIconSize)
77 *icon_size = SizeStringToIconSize(iter->second); 77 *icon_size = SizeStringToIconSize(iter->second);
78 else if (scale_factor && iter->first == kScaleFactor) 78 else if (scale_factor && iter->first == kScaleFactor)
79 webui::ParseScaleFactor(iter->second, scale_factor); 79 webui::ParseScaleFactor(iter->second, scale_factor);
80 } 80 }
81 } 81 }
82 82
83 } // namespace 83 } // namespace
84 84
85 FileIconSource::IconRequestDetails::IconRequestDetails() { 85 FileIconSource::IconRequestDetails::IconRequestDetails() : scale_factor(1.0f) {
86 } 86 }
87 87
88 FileIconSource::IconRequestDetails::~IconRequestDetails() { 88 FileIconSource::IconRequestDetails::~IconRequestDetails() {
89 } 89 }
90 90
91 FileIconSource::FileIconSource() {} 91 FileIconSource::FileIconSource() {}
92 92
93 FileIconSource::~FileIconSource() {} 93 FileIconSource::~FileIconSource() {}
94 94
95 void FileIconSource::FetchFileIcon( 95 void FileIconSource::FetchFileIcon(
96 const base::FilePath& path, 96 const base::FilePath& path,
97 ui::ScaleFactor scale_factor, 97 float scale_factor,
98 IconLoader::IconSize icon_size, 98 IconLoader::IconSize icon_size,
99 const content::URLDataSource::GotDataCallback& callback) { 99 const content::URLDataSource::GotDataCallback& callback) {
100 IconManager* im = g_browser_process->icon_manager(); 100 IconManager* im = g_browser_process->icon_manager();
101 gfx::Image* icon = im->LookupIconFromFilepath(path, icon_size); 101 gfx::Image* icon = im->LookupIconFromFilepath(path, icon_size);
102 102
103 if (icon) { 103 if (icon) {
104 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); 104 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
105 gfx::PNGCodec::EncodeBGRASkBitmap( 105 gfx::PNGCodec::EncodeBGRASkBitmap(
106 icon->ToImageSkia()->GetRepresentation( 106 icon->ToImageSkia()->GetRepresentation(scale_factor).sk_bitmap(),
107 ui::GetImageScale(scale_factor)).sk_bitmap(), 107 false,
108 false, &icon_data->data()); 108 &icon_data->data());
109 109
110 callback.Run(icon_data.get()); 110 callback.Run(icon_data.get());
111 } else { 111 } else {
112 // Attach the ChromeURLDataManager request ID to the history request. 112 // Attach the ChromeURLDataManager request ID to the history request.
113 IconRequestDetails details; 113 IconRequestDetails details;
114 details.callback = callback; 114 details.callback = callback;
115 details.scale_factor = scale_factor; 115 details.scale_factor = scale_factor;
116 116
117 // Icon was not in cache, go fetch it slowly. 117 // Icon was not in cache, go fetch it slowly.
118 im->LoadIcon(path, 118 im->LoadIcon(path,
119 icon_size, 119 icon_size,
120 base::Bind(&FileIconSource::OnFileIconDataAvailable, 120 base::Bind(&FileIconSource::OnFileIconDataAvailable,
121 base::Unretained(this), details), 121 base::Unretained(this), details),
122 &cancelable_task_tracker_); 122 &cancelable_task_tracker_);
123 } 123 }
124 } 124 }
125 125
126 std::string FileIconSource::GetSource() const { 126 std::string FileIconSource::GetSource() const {
127 return kFileIconPath; 127 return kFileIconPath;
128 } 128 }
129 129
130 void FileIconSource::StartDataRequest( 130 void FileIconSource::StartDataRequest(
131 const std::string& url_path, 131 const std::string& url_path,
132 int render_process_id, 132 int render_process_id,
133 int render_frame_id, 133 int render_frame_id,
134 const content::URLDataSource::GotDataCallback& callback) { 134 const content::URLDataSource::GotDataCallback& callback) {
135 std::string query; 135 std::string query;
136 base::FilePath file_path; 136 base::FilePath file_path;
137 ui::ScaleFactor scale_factor;
138 IconLoader::IconSize icon_size; 137 IconLoader::IconSize icon_size;
138 float scale_factor = 1.0f;
139 GetFilePathAndQuery(url_path, &file_path, &query); 139 GetFilePathAndQuery(url_path, &file_path, &query);
140 ParseQueryParams(query, &scale_factor, &icon_size); 140 ParseQueryParams(query, &scale_factor, &icon_size);
141 FetchFileIcon(file_path, scale_factor, icon_size, callback); 141 FetchFileIcon(file_path, scale_factor, icon_size, callback);
142 } 142 }
143 143
144 std::string FileIconSource::GetMimeType(const std::string&) const { 144 std::string FileIconSource::GetMimeType(const std::string&) const {
145 // Rely on image decoder inferring the correct type. 145 // Rely on image decoder inferring the correct type.
146 return std::string(); 146 return std::string();
147 } 147 }
148 148
149 void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details, 149 void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details,
150 gfx::Image* icon) { 150 gfx::Image* icon) {
151 if (icon) { 151 if (icon) {
152 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); 152 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
153 gfx::PNGCodec::EncodeBGRASkBitmap( 153 gfx::PNGCodec::EncodeBGRASkBitmap(
154 icon->ToImageSkia()->GetRepresentation( 154 icon->ToImageSkia()->GetRepresentation(
155 ui::GetImageScale(details.scale_factor)).sk_bitmap(), 155 details.scale_factor).sk_bitmap(),
156 false, 156 false,
157 &icon_data->data()); 157 &icon_data->data());
158 158
159 details.callback.Run(icon_data.get()); 159 details.callback.Run(icon_data.get());
160 } else { 160 } else {
161 // TODO(glen): send a dummy icon. 161 // TODO(glen): send a dummy icon.
162 details.callback.Run(NULL); 162 details.callback.Run(NULL);
163 } 163 }
164 } 164 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/fileicon_source.h ('k') | chrome/browser/ui/webui/fileicon_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698