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

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

Issue 11885021: Don't derive from ChromeURLDataManager::DataSource, and instead have these classes implement a dele… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: nits Created 7 years, 11 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/file_path.h" 10 #include "base/file_path.h"
11 #include "base/memory/ref_counted_memory.h" 11 #include "base/memory/ref_counted_memory.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/string_split.h" 13 #include "base/string_split.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
16 #include "chrome/browser/ui/webui/web_ui_util.h" 17 #include "chrome/browser/ui/webui/web_ui_util.h"
17 #include "chrome/common/time_format.h" 18 #include "chrome/common/time_format.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "net/base/escape.h" 21 #include "net/base/escape.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/codec/png_codec.h" 23 #include "ui/gfx/codec/png_codec.h"
23 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
24 #include "ui/gfx/image/image_skia.h" 25 #include "ui/gfx/image/image_skia.h"
25 26
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 iter != parameters.end(); ++iter) { 84 iter != parameters.end(); ++iter) {
84 if (icon_size && iter->first == kIconSize) 85 if (icon_size && iter->first == kIconSize)
85 *icon_size = SizeStringToIconSize(iter->second); 86 *icon_size = SizeStringToIconSize(iter->second);
86 else if (scale_factor && iter->first == kScaleFactor) 87 else if (scale_factor && iter->first == kScaleFactor)
87 web_ui_util::ParseScaleFactor(iter->second, scale_factor); 88 web_ui_util::ParseScaleFactor(iter->second, scale_factor);
88 } 89 }
89 } 90 }
90 91
91 } // namespace 92 } // namespace
92 93
93 FileIconSource::FileIconSource() 94 FileIconSource::FileIconSource() {}
94 : DataSource(kFileIconPath, MessageLoop::current()) {}
95 95
96 FileIconSource::~FileIconSource() {} 96 FileIconSource::~FileIconSource() {}
97 97
98 void FileIconSource::FetchFileIcon(const FilePath& path, 98 void FileIconSource::FetchFileIcon(const FilePath& path,
99 ui::ScaleFactor scale_factor, 99 ui::ScaleFactor scale_factor,
100 IconLoader::IconSize icon_size, 100 IconLoader::IconSize icon_size,
101 int request_id) { 101 int request_id) {
102 IconManager* im = g_browser_process->icon_manager(); 102 IconManager* im = g_browser_process->icon_manager();
103 gfx::Image* icon = im->LookupIcon(path, icon_size); 103 gfx::Image* icon = im->LookupIcon(path, icon_size);
104 104
105 if (icon) { 105 if (icon) {
106 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); 106 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
107 gfx::PNGCodec::EncodeBGRASkBitmap( 107 gfx::PNGCodec::EncodeBGRASkBitmap(
108 icon->ToImageSkia()->GetRepresentation(scale_factor).sk_bitmap(), 108 icon->ToImageSkia()->GetRepresentation(scale_factor).sk_bitmap(),
109 false, &icon_data->data()); 109 false, &icon_data->data());
110 110
111 SendResponse(request_id, icon_data); 111 url_data_source()->SendResponse(request_id, icon_data);
112 } else { 112 } else {
113 // Attach the ChromeURLDataManager request ID to the history request. 113 // Attach the ChromeURLDataManager request ID to the history request.
114 IconRequestDetails details; 114 IconRequestDetails details;
115 details.request_id = request_id; 115 details.request_id = request_id;
116 details.scale_factor = scale_factor; 116 details.scale_factor = scale_factor;
117 117
118 // Icon was not in cache, go fetch it slowly. 118 // Icon was not in cache, go fetch it slowly.
119 im->LoadIcon(path, 119 im->LoadIcon(path,
120 icon_size, 120 icon_size,
121 base::Bind(&FileIconSource::OnFileIconDataAvailable, 121 base::Bind(&FileIconSource::OnFileIconDataAvailable,
122 base::Unretained(this), details), 122 base::Unretained(this), details),
123 &cancelable_task_tracker_); 123 &cancelable_task_tracker_);
124 } 124 }
125 } 125 }
126 126
127 std::string FileIconSource::GetSource() {
128 return kFileIconPath;
129 }
130
127 void FileIconSource::StartDataRequest(const std::string& url_path, 131 void FileIconSource::StartDataRequest(const std::string& url_path,
128 bool is_incognito, 132 bool is_incognito,
129 int request_id) { 133 int request_id) {
130 std::string query; 134 std::string query;
131 FilePath file_path; 135 FilePath file_path;
132 ui::ScaleFactor scale_factor; 136 ui::ScaleFactor scale_factor;
133 IconLoader::IconSize icon_size; 137 IconLoader::IconSize icon_size;
134 GetFilePathAndQuery(url_path, &file_path, &query); 138 GetFilePathAndQuery(url_path, &file_path, &query);
135 ParseQueryParams(query, &scale_factor, &icon_size); 139 ParseQueryParams(query, &scale_factor, &icon_size);
136 FetchFileIcon(file_path, scale_factor, icon_size, request_id); 140 FetchFileIcon(file_path, scale_factor, icon_size, request_id);
137 } 141 }
138 142
139 std::string FileIconSource::GetMimeType(const std::string&) const { 143 std::string FileIconSource::GetMimeType(const std::string&) const {
140 // Rely on image decoder inferring the correct type. 144 // Rely on image decoder inferring the correct type.
141 return std::string(); 145 return std::string();
142 } 146 }
143 147
144 void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details, 148 void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details,
145 gfx::Image* icon) { 149 gfx::Image* icon) {
146 if (icon) { 150 if (icon) {
147 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); 151 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes);
148 gfx::PNGCodec::EncodeBGRASkBitmap( 152 gfx::PNGCodec::EncodeBGRASkBitmap(
149 icon->ToImageSkia()->GetRepresentation(details.scale_factor) 153 icon->ToImageSkia()->GetRepresentation(details.scale_factor)
150 .sk_bitmap(), 154 .sk_bitmap(),
151 false, 155 false,
152 &icon_data->data()); 156 &icon_data->data());
153 157
154 SendResponse(details.request_id, icon_data); 158 url_data_source()->SendResponse(details.request_id, icon_data);
155 } else { 159 } else {
156 // TODO(glen): send a dummy icon. 160 // TODO(glen): send a dummy icon.
157 SendResponse(details.request_id, NULL); 161 url_data_source()->SendResponse(details.request_id, NULL);
158 } 162 }
159 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698