| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 if (icon) { | 46 if (icon) { |
| 47 scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes); | 47 scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes); |
| 48 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data()); | 48 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data()); |
| 49 | 49 |
| 50 SendResponse(request_id, icon_data); | 50 SendResponse(request_id, icon_data); |
| 51 } else { | 51 } else { |
| 52 // Icon was not in cache, go fetch it slowly. | 52 // Icon was not in cache, go fetch it slowly. |
| 53 IconManager::Handle h = im->LoadIcon(escaped_filepath, | 53 IconManager::Handle h = im->LoadIcon(escaped_filepath, |
| 54 IconLoader::NORMAL, | 54 IconLoader::NORMAL, |
| 55 &cancelable_consumer_, | 55 &cancelable_consumer_, |
| 56 NewCallback(this, &FileIconSource::OnFileIconDataAvailable)); | 56 base::Bind(&FileIconSource::OnFileIconDataAvailable, |
| 57 base::Unretained(this))); |
| 57 | 58 |
| 58 // Attach the ChromeURLDataManager request ID to the history request. | 59 // Attach the ChromeURLDataManager request ID to the history request. |
| 59 cancelable_consumer_.SetClientData(im, h, request_id); | 60 cancelable_consumer_.SetClientData(im, h, request_id); |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 std::string FileIconSource::GetMimeType(const std::string&) const { | 64 std::string FileIconSource::GetMimeType(const std::string&) const { |
| 64 // Rely on image decoder inferring the correct type. | 65 // Rely on image decoder inferring the correct type. |
| 65 return std::string(); | 66 return std::string(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle, | 69 void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle, |
| 69 gfx::Image* icon) { | 70 gfx::Image* icon) { |
| 70 IconManager* im = g_browser_process->icon_manager(); | 71 IconManager* im = g_browser_process->icon_manager(); |
| 71 int request_id = cancelable_consumer_.GetClientData(im, handle); | 72 int request_id = cancelable_consumer_.GetClientData(im, handle); |
| 72 | 73 |
| 73 if (icon) { | 74 if (icon) { |
| 74 scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes); | 75 scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes); |
| 75 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data()); | 76 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data()); |
| 76 | 77 |
| 77 SendResponse(request_id, icon_data); | 78 SendResponse(request_id, icon_data); |
| 78 } else { | 79 } else { |
| 79 // TODO(glen): send a dummy icon. | 80 // TODO(glen): send a dummy icon. |
| 80 SendResponse(request_id, NULL); | 81 SendResponse(request_id, NULL); |
| 81 } | 82 } |
| 82 } | 83 } |
| OLD | NEW |