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
3 // found in the LICENSE file.
5 #include "chrome/browser/icon_loader.h"
7 #include "base/basictypes.h"
9 #include "content/public/browser/browser_thread.h"
11 using content::BrowserThread
;
13 IconLoader::IconLoader(const base::FilePath
& file_path
,
16 : target_message_loop_(NULL
),
17 file_path_(file_path
),
19 delegate_(delegate
) {}
21 IconLoader::~IconLoader() {
24 void IconLoader::Start() {
25 target_message_loop_
= base::MessageLoopProxy::current();
27 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE
,
28 base::Bind(&IconLoader::ReadGroup
, this),
29 base::Bind(&IconLoader::OnReadGroup
, this));
32 void IconLoader::ReadGroup() {
33 group_
= ReadGroupIDFromFilepath(file_path_
);
36 void IconLoader::OnReadGroup() {
37 if (IsIconMutableFromFilepath(file_path_
) ||
38 !delegate_
->OnGroupLoaded(this, group_
)) {
39 BrowserThread::PostTask(ReadIconThreadID(), FROM_HERE
,
40 base::Bind(&IconLoader::ReadIcon
, this));
44 void IconLoader::NotifyDelegate() {
45 // If the delegate takes ownership of the Image, release it from the scoped
47 if (delegate_
->OnImageLoaded(this, image_
.get(), group_
))
48 ignore_result(image_
.release()); // Can't ignore return value.