[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" |
avi | f4d431c | 2017-06-22 23:30:53 | [diff] [blame^] | 10 | #include "base/task_scheduler/post_task.h" |
| 11 | #include "base/task_scheduler/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) { |
| 21 | return new IconLoader(file_path, size, 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) |
| 35 | : file_path_(file_path), icon_size_(size), callback_(callback) {} |
| 36 | |
| 37 | IconLoader::~IconLoader() {} |
| 38 | |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 39 | void IconLoader::ReadGroup() { |
avi | 381f719f | 2016-12-16 00:05:02 | [diff] [blame] | 40 | group_ = GroupForFilepath(file_path_); |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 41 | |
avi | f4d431c | 2017-06-22 23:30:53 | [diff] [blame^] | 42 | GetReadIconTaskRunner()->PostTask( |
| 43 | FROM_HERE, base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this))); |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 44 | } |