[email protected] | 679facce | 2012-07-25 16:13:12 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 2 | // 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 | |
avi | f4d431c | 2017-06-22 23:30:53 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | a27a2bc | 2011-11-15 21:25:51 | [diff] [blame] | 9 | #include "base/bind.h" |
Gabriel Charette | 5338185 | 2020-03-02 15:27:20 | [diff] [blame] | 10 | #include "base/task/thread_pool.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 11 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 12 | #include "content/public/browser/browser_thread.h" |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 13 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 14 | using content::BrowserThread; |
| 15 | |
avi | f0a7b5b81 | 2016-12-17 19:01:31 | [diff] [blame] | 16 | // static |
| 17 | IconLoader* IconLoader::Create(const base::FilePath& file_path, |
| 18 | IconSize size, |
Alexander Zhirov | f51bebd | 2021-04-13 09:52:04 | [diff] [blame] | 19 | float scale, |
avi | f0a7b5b81 | 2016-12-17 19:01:31 | [diff] [blame] | 20 | IconLoadedCallback callback) { |
Alexander Zhirov | f51bebd | 2021-04-13 09:52:04 | [diff] [blame] | 21 | return new IconLoader(file_path, size, scale, std::move(callback)); |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void IconLoader::Start() { |
pranay.kumar | 4b8db4d | 2015-04-29 11:12:04 | [diff] [blame] | 25 | target_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 26 | |
Gabriel Charette | 5338185 | 2020-03-02 15:27:20 | [diff] [blame] | 27 | base::ThreadPool::PostTask( |
avi | f4d431c | 2017-06-22 23:30:53 | [diff] [blame] | 28 | FROM_HERE, traits(), |
| 29 | base::BindOnce(&IconLoader::ReadGroup, base::Unretained(this))); |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 30 | } |
| 31 | |
avi | f0a7b5b81 | 2016-12-17 19:01:31 | [diff] [blame] | 32 | IconLoader::IconLoader(const base::FilePath& file_path, |
| 33 | IconSize size, |
Alexander Zhirov | f51bebd | 2021-04-13 09:52:04 | [diff] [blame] | 34 | float scale, |
avi | f0a7b5b81 | 2016-12-17 19:01:31 | [diff] [blame] | 35 | IconLoadedCallback callback) |
Daniel Bratell | 71e14370 | 2017-10-11 11:18:26 | [diff] [blame] | 36 | : file_path_(file_path), |
| 37 | #if !defined(OS_ANDROID) |
| 38 | icon_size_(size), |
| 39 | #endif // defined(OS_ANDROID) |
Alexander Zhirov | f51bebd | 2021-04-13 09:52:04 | [diff] [blame] | 40 | scale_(scale), |
Avi Drissman | efe4dc8 | 2018-02-23 17:55:39 | [diff] [blame] | 41 | callback_(std::move(callback)) { |
Daniel Bratell | 71e14370 | 2017-10-11 11:18:26 | [diff] [blame] | 42 | } |
avi | f0a7b5b81 | 2016-12-17 19:01:31 | [diff] [blame] | 43 | |
| 44 | IconLoader::~IconLoader() {} |
| 45 | |
Alex Gough | a4160b85 | 2020-06-23 00:21:29 | [diff] [blame] | 46 | #if !defined(OS_WIN) |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 47 | void IconLoader::ReadGroup() { |
avi | 381f719f | 2016-12-16 00:05:02 | [diff] [blame] | 48 | group_ = GroupForFilepath(file_path_); |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 49 | |
avi | f4d431c | 2017-06-22 23:30:53 | [diff] [blame] | 50 | GetReadIconTaskRunner()->PostTask( |
| 51 | FROM_HERE, base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this))); |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 52 | } |
Alex Gough | a4160b85 | 2020-06-23 00:21:29 | [diff] [blame] | 53 | #endif // !defined(OS_WIN) |