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.
4
5 #include "chrome/browser/icon_loader.h"
6
7 #include "base/basictypes.h"
8 #include "content/browser/browser_thread.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
10
11 #if defined(TOOLKIT_GTK)
12 #include "base/mime_util.h"
13 #endif
14
IconLoader(const IconGroupID & group,IconSize size,Delegate * delegate)15 IconLoader::IconLoader(const IconGroupID& group, IconSize size,
16 Delegate* delegate)
17 : target_message_loop_(NULL),
18 group_(group),
19 icon_size_(size),
20 image_(NULL),
21 delegate_(delegate) {
22 }
23
~IconLoader()24 IconLoader::~IconLoader() {
25 }
26
Start()27 void IconLoader::Start() {
28 target_message_loop_ = base::MessageLoopProxy::CreateForCurrentThread();
29
30 #if defined(TOOLKIT_GTK)
31 // This call must happen on the UI thread before we can start loading icons.
32 mime_util::DetectGtkTheme();
33 #endif
34
35 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
36 NewRunnableMethod(this, &IconLoader::ReadIcon));
37 }
38
NotifyDelegate()39 void IconLoader::NotifyDelegate() {
40 // If the delegate takes ownership of the Image, release it from the scoped
41 // pointer.
42 if (delegate_->OnImageLoaded(this, image_.get()))
43 ignore_result(image_.release()); // Can't ignore return value.
44 }
45