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/icon_loader.h" | 5 #include "chrome/browser/icon_loader.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 default: | 43 default: |
44 NOTREACHED(); | 44 NOTREACHED(); |
45 } | 45 } |
46 | 46 |
47 base::FilePath filename = base::nix::GetMimeIcon(group_, size_pixels); | 47 base::FilePath filename = base::nix::GetMimeIcon(group_, size_pixels); |
48 // We don't support SVG or XPM icons; this just spams the terminal so fail | 48 // We don't support SVG or XPM icons; this just spams the terminal so fail |
49 // quickly and don't try to read the file from disk first. | 49 // quickly and don't try to read the file from disk first. |
50 if (filename.Extension() != ".svg" && | 50 if (filename.Extension() != ".svg" && |
51 filename.Extension() != ".xpm") { | 51 filename.Extension() != ".xpm") { |
52 string icon_data; | 52 string icon_data; |
53 file_util::ReadFileToString(filename, &icon_data); | 53 base::ReadFileToString(filename, &icon_data); |
54 | 54 |
55 SkBitmap bitmap; | 55 SkBitmap bitmap; |
56 bool success = gfx::PNGCodec::Decode( | 56 bool success = gfx::PNGCodec::Decode( |
57 reinterpret_cast<const unsigned char*>(icon_data.data()), | 57 reinterpret_cast<const unsigned char*>(icon_data.data()), |
58 icon_data.length(), | 58 icon_data.length(), |
59 &bitmap); | 59 &bitmap); |
60 if (success && !bitmap.empty()) { | 60 if (success && !bitmap.empty()) { |
61 DCHECK_EQ(size_pixels, bitmap.width()); | 61 DCHECK_EQ(size_pixels, bitmap.width()); |
62 DCHECK_EQ(size_pixels, bitmap.height()); | 62 DCHECK_EQ(size_pixels, bitmap.height()); |
63 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 63 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
64 image_skia.MakeThreadSafe(); | 64 image_skia.MakeThreadSafe(); |
65 image_.reset(new gfx::Image(image_skia)); | 65 image_.reset(new gfx::Image(image_skia)); |
66 } else { | 66 } else { |
67 LOG(WARNING) << "Unsupported file type or load error: " | 67 LOG(WARNING) << "Unsupported file type or load error: " |
68 << filename.value(); | 68 << filename.value(); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 target_message_loop_->PostTask( | 72 target_message_loop_->PostTask( |
73 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); | 73 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this)); |
74 } | 74 } |
OLD | NEW |