ExtensionSyncService: listen for relevant changes instead of being explicitly called...
[chromium-blink-merge.git] / chrome / browser / icon_loader.cc
blob9cb478fb89f47c57c838c0c99559ece6573a7d53
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"
8 #include "base/bind.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "content/public/browser/browser_thread.h"
12 using content::BrowserThread;
14 IconLoader::IconLoader(const base::FilePath& file_path,
15 IconSize size,
16 Delegate* delegate)
17 : target_task_runner_(NULL),
18 file_path_(file_path),
19 icon_size_(size),
20 delegate_(delegate) {}
22 IconLoader::~IconLoader() {
25 void IconLoader::Start() {
26 target_task_runner_ = base::ThreadTaskRunnerHandle::Get();
28 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
29 base::Bind(&IconLoader::ReadGroup, this),
30 base::Bind(&IconLoader::OnReadGroup, this));
33 void IconLoader::ReadGroup() {
34 group_ = ReadGroupIDFromFilepath(file_path_);
37 void IconLoader::OnReadGroup() {
38 if (IsIconMutableFromFilepath(file_path_) ||
39 !delegate_->OnGroupLoaded(this, group_)) {
40 BrowserThread::PostTask(ReadIconThreadID(), FROM_HERE,
41 base::Bind(&IconLoader::ReadIcon, this));
45 void IconLoader::NotifyDelegate() {
46 // If the delegate takes ownership of the Image, release it from the scoped
47 // pointer.
48 if (delegate_->OnImageLoaded(this, image_.get(), group_))
49 ignore_result(image_.release()); // Can't ignore return value.