chromeos: bluetooth: tie Proxy lifetime to object, not observer
[chromium-blink-merge.git] / chrome / browser / icon_loader_linux.cc
blob32529c4889dcc41ea206e36d08539d3facc7ddaa
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
3 // found in the LICENSE file.
5 #include "chrome/browser/icon_loader.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/file_util.h"
11 #include "base/logging.h"
12 #include "base/message_loop.h"
13 #include "base/nix/mime_util_xdg.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "webkit/glue/image_decoder.h"
17 using std::string;
19 void IconLoader::ReadIcon() {
20 int size_pixels = 0;
21 switch (icon_size_) {
22 case IconLoader::SMALL:
23 size_pixels = 16;
24 break;
25 case IconLoader::NORMAL:
26 size_pixels = 32;
27 break;
28 case IconLoader::LARGE:
29 size_pixels = 48;
30 break;
31 default:
32 NOTREACHED();
35 FilePath filename = base::nix::GetMimeIcon(group_, size_pixels);
36 string icon_data;
37 file_util::ReadFileToString(filename, &icon_data);
39 webkit_glue::ImageDecoder decoder;
40 scoped_ptr<SkBitmap> bitmap(new SkBitmap());
41 *bitmap = decoder.Decode(
42 reinterpret_cast<const unsigned char*>(icon_data.data()),
43 icon_data.length());
44 if (!bitmap->empty()) {
45 DCHECK_EQ(size_pixels, bitmap->width());
46 DCHECK_EQ(size_pixels, bitmap->height());
47 image_.reset(new gfx::Image(bitmap.release()));
48 } else {
49 LOG(WARNING) << "Unsupported file type or load error: " << filename.value();
52 target_message_loop_->PostTask(
53 FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this));