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

Side by Side Diff: chrome/browser/dom_ui/fileicon_source.cc

Issue 20110: Initial checkin of the HTML downloads UI. It's not yet complete (lacking... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/dom_ui/fileicon_source.h"
6
7 #include "base/gfx/png_encoder.h"
8 #include "base/string_util.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/common/time_format.h"
11
12 #include "generated_resources.h"
13
14 // The path used in internal URLs to file icon data.
15 static const char kFileIconPath[] = "fileicon";
16
17 FileIconSource::FileIconSource()
18 : DataSource(kFileIconPath, MessageLoop::current()) {}
19
20 FileIconSource::~FileIconSource() {
21 cancelable_consumer_.CancelAllRequests();
22 }
23
24 void FileIconSource::StartDataRequest(const std::string& path,
25 int request_id) {
26 IconManager* im = g_browser_process->icon_manager();
27
28 // Fast look up.
29 SkBitmap* icon = im->LookupIcon(UTF8ToWide(path), IconLoader::NORMAL);
30
31 if (icon) {
32 std::vector<unsigned char> png_bytes;
33 PNGEncoder::EncodeBGRASkBitmap(*icon, false, &png_bytes);
34
35 scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes(png_bytes);
36 SendResponse(request_id, icon_data);
37 } else {
38 // Icon was not in cache, go fetch it slowly.
39 IconManager::Handle h = im->LoadIcon(UTF8ToWide(path), IconLoader::NORMAL,
40 &cancelable_consumer_,
41 NewCallback(this, &FileIconSource::OnFileIconDataAvailable));
42
43 // Attach the ChromeURLDataManager request ID to the history request.
44 cancelable_consumer_.SetClientData(im, h, request_id);
45 }
46 }
47
48 void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle,
49 SkBitmap* icon) {
50 IconManager* im = g_browser_process->icon_manager();
51 int request_id = cancelable_consumer_.GetClientData(im, handle);
52
53 if (icon) {
54 std::vector<unsigned char> png_bytes;
55 PNGEncoder::EncodeBGRASkBitmap(*icon, false, &png_bytes);
56
57 scoped_refptr<RefCountedBytes> icon_data = new RefCountedBytes(png_bytes);
58 SendResponse(request_id, icon_data);
59 } else {
60 // TODO(glen): send a dummy icon.
61 SendResponse(request_id, NULL);
62 }
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698