2016-10-29 12:35:50 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-01-08 10:21:22 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2016-10-29 12:35:50 +00:00
|
|
|
#include "chrome/browser/icon_loader.h"
|
|
|
|
#include "base/bind.h"
|
2018-01-08 10:21:22 +00:00
|
|
|
#include "base/task_scheduler/post_task.h"
|
|
|
|
#include "base/task_scheduler/task_traits.h"
|
2016-10-29 12:35:50 +00:00
|
|
|
#include "base/threading/thread_task_runner_handle.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
2017-02-16 19:19:19 +00:00
|
|
|
// static
|
|
|
|
IconLoader* IconLoader::Create(const base::FilePath& file_path,
|
|
|
|
IconSize size,
|
|
|
|
IconLoadedCallback callback) {
|
|
|
|
return new IconLoader(file_path, size, callback);
|
|
|
|
}
|
2016-10-29 12:35:50 +00:00
|
|
|
|
|
|
|
void IconLoader::Start() {
|
|
|
|
target_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
2018-01-08 10:21:22 +00:00
|
|
|
|
|
|
|
base::PostTaskWithTraits(
|
|
|
|
FROM_HERE, traits(),
|
|
|
|
base::BindOnce(&IconLoader::ReadGroup, base::Unretained(this)));
|
2016-10-29 12:35:50 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 19:19:19 +00:00
|
|
|
IconLoader::IconLoader(const base::FilePath& file_path,
|
|
|
|
IconSize size,
|
|
|
|
IconLoadedCallback callback)
|
|
|
|
: file_path_(file_path), icon_size_(size), callback_(callback) {}
|
|
|
|
|
|
|
|
IconLoader::~IconLoader() {}
|
|
|
|
|
2016-10-29 12:35:50 +00:00
|
|
|
void IconLoader::ReadGroup() {
|
2017-02-16 19:19:19 +00:00
|
|
|
group_ = GroupForFilepath(file_path_);
|
2018-01-08 10:21:22 +00:00
|
|
|
GetReadIconTaskRunner()->PostTask(
|
|
|
|
FROM_HERE, base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this)));
|
2016-10-29 12:35:50 +00:00
|
|
|
}
|