[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 | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 10 | #include "base/task/post_task.h" |
| 11 | #include "base/task/task_traits.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 12 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 13 | #include "content/public/browser/browser_thread.h" |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 14 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 15 | using content::BrowserThread; |
| 16 | |
avi | f0a7b5b81 | 2016-12-17 19:01:31 | [diff] [blame] | 17 | // static |
| 18 | IconLoader* IconLoader::Create(const base::FilePath& file_path, |
| 19 | IconSize size, |
| 20 | IconLoadedCallback callback) { |
Avi Drissman | efe4dc8 | 2018-02-23 17:55:39 | [diff] [blame] | 21 | return new IconLoader(file_path, size, 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 | |
avi | f4d431c | 2017-06-22 23:30:53 | [diff] [blame] | 27 | base::PostTaskWithTraits( |
| 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, |
| 34 | IconLoadedCallback callback) |
Daniel Bratell | 71e14370 | 2017-10-11 11:18:26 | [diff] [blame] | 35 | : file_path_(file_path), |
| 36 | #if !defined(OS_ANDROID) |
| 37 | icon_size_(size), |
| 38 | #endif // defined(OS_ANDROID) |
Avi Drissman | efe4dc8 | 2018-02-23 17:55:39 | [diff] [blame] | 39 | callback_(std::move(callback)) { |
Daniel Bratell | 71e14370 | 2017-10-11 11:18:26 | [diff] [blame] | 40 | } |
avi | f0a7b5b81 | 2016-12-17 19:01:31 | [diff] [blame] | 41 | |
| 42 | IconLoader::~IconLoader() {} |
| 43 | |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 44 | void IconLoader::ReadGroup() { |
avi | 381f719f | 2016-12-16 00:05:02 | [diff] [blame] | 45 | group_ = GroupForFilepath(file_path_); |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 46 | |
avi | f4d431c | 2017-06-22 23:30:53 | [diff] [blame] | 47 | GetReadIconTaskRunner()->PostTask( |
| 48 | FROM_HERE, base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this))); |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 49 | } |