blob: 9bc494f1af0e39e7646f196602b0bdcc731689f6 [file] [log] [blame]
[email protected]679facce2012-07-25 16:13:121// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]0f38ceae2009-05-08 19:01:022// 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
avif4d431c2017-06-22 23:30:537#include <utility>
8
[email protected]a27a2bc2011-11-15 21:25:519#include "base/bind.h"
Gabriel Charette53381852020-03-02 15:27:2010#include "base/task/thread_pool.h"
gabb15e19072016-05-11 20:45:4111#include "base/threading/thread_task_runner_handle.h"
[email protected]c38831a12011-10-28 12:44:4912#include "content/public/browser/browser_thread.h"
[email protected]0f38ceae2009-05-08 19:01:0213
[email protected]631bb742011-11-02 11:29:3914using content::BrowserThread;
15
avif0a7b5b812016-12-17 19:01:3116// static
17IconLoader* IconLoader::Create(const base::FilePath& file_path,
18 IconSize size,
Alexander Zhirovf51bebd2021-04-13 09:52:0419 float scale,
avif0a7b5b812016-12-17 19:01:3120 IconLoadedCallback callback) {
Alexander Zhirovf51bebd2021-04-13 09:52:0421 return new IconLoader(file_path, size, scale, std::move(callback));
[email protected]0f38ceae2009-05-08 19:01:0222}
23
24void IconLoader::Start() {
pranay.kumar4b8db4d2015-04-29 11:12:0425 target_task_runner_ = base::ThreadTaskRunnerHandle::Get();
[email protected]0f38ceae2009-05-08 19:01:0226
Gabriel Charette53381852020-03-02 15:27:2027 base::ThreadPool::PostTask(
avif4d431c2017-06-22 23:30:5328 FROM_HERE, traits(),
29 base::BindOnce(&IconLoader::ReadGroup, base::Unretained(this)));
[email protected]bc0147b2013-04-03 20:50:5930}
31
avif0a7b5b812016-12-17 19:01:3132IconLoader::IconLoader(const base::FilePath& file_path,
33 IconSize size,
Alexander Zhirovf51bebd2021-04-13 09:52:0434 float scale,
avif0a7b5b812016-12-17 19:01:3135 IconLoadedCallback callback)
Daniel Bratell71e143702017-10-11 11:18:2636 : file_path_(file_path),
37#if !defined(OS_ANDROID)
38 icon_size_(size),
39#endif // defined(OS_ANDROID)
Alexander Zhirovf51bebd2021-04-13 09:52:0440 scale_(scale),
Avi Drissmanefe4dc82018-02-23 17:55:3941 callback_(std::move(callback)) {
Daniel Bratell71e143702017-10-11 11:18:2642}
avif0a7b5b812016-12-17 19:01:3143
44IconLoader::~IconLoader() {}
45
Alex Gougha4160b852020-06-23 00:21:2946#if !defined(OS_WIN)
[email protected]bc0147b2013-04-03 20:50:5947void IconLoader::ReadGroup() {
avi381f719f2016-12-16 00:05:0248 group_ = GroupForFilepath(file_path_);
[email protected]bc0147b2013-04-03 20:50:5949
avif4d431c2017-06-22 23:30:5350 GetReadIconTaskRunner()->PostTask(
51 FROM_HERE, base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this)));
[email protected]0f38ceae2009-05-08 19:01:0252}
Alex Gougha4160b852020-06-23 00:21:2953#endif // !defined(OS_WIN)