| 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 #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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 const base::FilePath& path, | 96 const base::FilePath& path, |
| 97 ui::ScaleFactor scale_factor, | 97 ui::ScaleFactor 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(scale_factor).sk_bitmap(), | 106 icon->ToImageSkia()->GetRepresentation( |
| 107 ui::GetScaleFactorScale(scale_factor)).sk_bitmap(), |
| 107 false, &icon_data->data()); | 108 false, &icon_data->data()); |
| 108 | 109 |
| 109 callback.Run(icon_data.get()); | 110 callback.Run(icon_data.get()); |
| 110 } else { | 111 } else { |
| 111 // Attach the ChromeURLDataManager request ID to the history request. | 112 // Attach the ChromeURLDataManager request ID to the history request. |
| 112 IconRequestDetails details; | 113 IconRequestDetails details; |
| 113 details.callback = callback; | 114 details.callback = callback; |
| 114 details.scale_factor = scale_factor; | 115 details.scale_factor = scale_factor; |
| 115 | 116 |
| 116 // Icon was not in cache, go fetch it slowly. | 117 // Icon was not in cache, go fetch it slowly. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 143 std::string FileIconSource::GetMimeType(const std::string&) const { | 144 std::string FileIconSource::GetMimeType(const std::string&) const { |
| 144 // Rely on image decoder inferring the correct type. | 145 // Rely on image decoder inferring the correct type. |
| 145 return std::string(); | 146 return std::string(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details, | 149 void FileIconSource::OnFileIconDataAvailable(const IconRequestDetails& details, |
| 149 gfx::Image* icon) { | 150 gfx::Image* icon) { |
| 150 if (icon) { | 151 if (icon) { |
| 151 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); | 152 scoped_refptr<base::RefCountedBytes> icon_data(new base::RefCountedBytes); |
| 152 gfx::PNGCodec::EncodeBGRASkBitmap( | 153 gfx::PNGCodec::EncodeBGRASkBitmap( |
| 153 icon->ToImageSkia()->GetRepresentation(details.scale_factor) | 154 icon->ToImageSkia()->GetRepresentation( |
| 154 .sk_bitmap(), | 155 ui::GetScaleFactorScale(details.scale_factor)).sk_bitmap(), |
| 155 false, | 156 false, |
| 156 &icon_data->data()); | 157 &icon_data->data()); |
| 157 | 158 |
| 158 details.callback.Run(icon_data.get()); | 159 details.callback.Run(icon_data.get()); |
| 159 } else { | 160 } else { |
| 160 // TODO(glen): send a dummy icon. | 161 // TODO(glen): send a dummy icon. |
| 161 details.callback.Run(NULL); | 162 details.callback.Run(NULL); |
| 162 } | 163 } |
| 163 } | 164 } |
| OLD | NEW |