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

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

Issue 7397021: Re-land r93365 - add RefCountedString (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 9 years, 5 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) 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 27 matching lines...) Expand all
38 #elif defined(OS_POSIX) 38 #elif defined(OS_POSIX)
39 // The correct encoding on Linux may not actually be UTF8. 39 // The correct encoding on Linux may not actually be UTF8.
40 FilePath escaped_filepath(escaped_path); 40 FilePath escaped_filepath(escaped_path);
41 #endif 41 #endif
42 42
43 IconManager* im = g_browser_process->icon_manager(); 43 IconManager* im = g_browser_process->icon_manager();
44 gfx::Image* icon = im->LookupIcon(escaped_filepath, IconLoader::NORMAL); 44 gfx::Image* icon = im->LookupIcon(escaped_filepath, IconLoader::NORMAL);
45 45
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 NewCallback(this, &FileIconSource::OnFileIconDataAvailable));
57 57
58 // Attach the ChromeURLDataManager request ID to the history request. 58 // Attach the ChromeURLDataManager request ID to the history request.
59 cancelable_consumer_.SetClientData(im, h, request_id); 59 cancelable_consumer_.SetClientData(im, h, request_id);
60 } 60 }
61 } 61 }
62 62
63 std::string FileIconSource::GetMimeType(const std::string&) const { 63 std::string FileIconSource::GetMimeType(const std::string&) const {
64 // Rely on image decoder inferring the correct type. 64 // Rely on image decoder inferring the correct type.
65 return std::string(); 65 return std::string();
66 } 66 }
67 67
68 void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle, 68 void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle,
69 gfx::Image* icon) { 69 gfx::Image* icon) {
70 IconManager* im = g_browser_process->icon_manager(); 70 IconManager* im = g_browser_process->icon_manager();
71 int request_id = cancelable_consumer_.GetClientData(im, handle); 71 int request_id = cancelable_consumer_.GetClientData(im, handle);
72 72
73 if (icon) { 73 if (icon) {
74 scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes); 74 scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes);
75 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data); 75 gfx::PNGCodec::EncodeBGRASkBitmap(*icon, false, &icon_data->data());
76 76
77 SendResponse(request_id, icon_data); 77 SendResponse(request_id, icon_data);
78 } else { 78 } else {
79 // TODO(glen): send a dummy icon. 79 // TODO(glen): send a dummy icon.
80 SendResponse(request_id, NULL); 80 SendResponse(request_id, NULL);
81 } 81 }
82 } 82 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extension_icon_source.cc ('k') | chrome/browser/ui/webui/gpu_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698