Update icon loading API implementation

This commit is contained in:
Yury Solovyov 2017-02-16 22:19:19 +03:00
parent 19b686c90b
commit 977abc6458
9 changed files with 176 additions and 243 deletions

View file

@ -3,46 +3,40 @@
// found in the LICENSE file.
#include "chrome/browser/icon_loader.h"
#include "base/bind.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
IconLoader::IconLoader(const base::FilePath& file_path,
IconSize size,
Delegate* delegate)
: target_task_runner_(NULL),
file_path_(file_path),
icon_size_(size),
delegate_(delegate) {}
IconLoader::~IconLoader() {}
// static
IconLoader* IconLoader::Create(const base::FilePath& file_path,
IconSize size,
IconLoadedCallback callback) {
return new IconLoader(file_path, size, callback);
}
void IconLoader::Start() {
target_task_runner_ = base::ThreadTaskRunnerHandle::Get();
BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
base::Bind(&IconLoader::ReadGroup, this),
base::Bind(&IconLoader::OnReadGroup, this));
BrowserThread::PostTaskAndReply(
BrowserThread::FILE, FROM_HERE,
base::Bind(&IconLoader::ReadGroup, base::Unretained(this)),
base::Bind(&IconLoader::OnReadGroup, base::Unretained(this)));
}
IconLoader::IconLoader(const base::FilePath& file_path,
IconSize size,
IconLoadedCallback callback)
: file_path_(file_path), icon_size_(size), callback_(callback) {}
IconLoader::~IconLoader() {}
void IconLoader::ReadGroup() {
group_ = ReadGroupIDFromFilepath(file_path_);
group_ = GroupForFilepath(file_path_);
}
void IconLoader::OnReadGroup() {
if (IsIconMutableFromFilepath(file_path_) ||
!delegate_->OnGroupLoaded(this, group_)) {
BrowserThread::PostTask(ReadIconThreadID(), FROM_HERE,
base::Bind(&IconLoader::ReadIcon, this));
}
}
void IconLoader::NotifyDelegate() {
// If the delegate takes ownership of the Image, release it from the scoped
// pointer.
if (delegate_->OnImageLoaded(this, image_.get(), group_))
ignore_result(image_.release()); // Can't ignore return value.
BrowserThread::PostTask(
ReadIconThreadID(), FROM_HERE,
base::Bind(&IconLoader::ReadIcon, base::Unretained(this)));
}