OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/icon_loader.h" | 5 #include "chrome/browser/icon_loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 | 10 |
11 using content::BrowserThread; | 11 using content::BrowserThread; |
12 | 12 |
13 IconLoader::IconLoader(const base::FilePath& file_path, | 13 // static |
14 IconSize size, | 14 IconLoader* IconLoader::Create(const base::FilePath& file_path, |
15 Delegate* delegate) | 15 IconSize size, |
16 : file_path_(file_path), | 16 IconLoadedCallback callback) { |
17 icon_size_(size), | 17 return new IconLoader(file_path, size, callback); |
18 delegate_(delegate) {} | |
19 | |
20 IconLoader::~IconLoader() { | |
21 } | 18 } |
22 | 19 |
23 void IconLoader::Start() { | 20 void IconLoader::Start() { |
24 target_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 21 target_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
25 | 22 |
26 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 23 BrowserThread::PostTaskAndReply( |
27 base::Bind(&IconLoader::ReadGroup, this), | 24 BrowserThread::FILE, FROM_HERE, |
28 base::Bind(&IconLoader::OnReadGroup, this)); | 25 base::Bind(&IconLoader::ReadGroup, base::Unretained(this)), |
| 26 base::Bind(&IconLoader::OnReadGroup, base::Unretained(this))); |
29 } | 27 } |
30 | 28 |
| 29 IconLoader::IconLoader(const base::FilePath& file_path, |
| 30 IconSize size, |
| 31 IconLoadedCallback callback) |
| 32 : file_path_(file_path), icon_size_(size), callback_(callback) {} |
| 33 |
| 34 IconLoader::~IconLoader() {} |
| 35 |
31 void IconLoader::ReadGroup() { | 36 void IconLoader::ReadGroup() { |
32 group_ = GroupForFilepath(file_path_); | 37 group_ = GroupForFilepath(file_path_); |
33 } | 38 } |
34 | 39 |
35 void IconLoader::OnReadGroup() { | 40 void IconLoader::OnReadGroup() { |
36 BrowserThread::PostTask(ReadIconThreadID(), FROM_HERE, | 41 BrowserThread::PostTask( |
37 base::Bind(&IconLoader::ReadIcon, this)); | 42 ReadIconThreadID(), FROM_HERE, |
| 43 base::Bind(&IconLoader::ReadIcon, base::Unretained(this))); |
38 } | 44 } |
39 | |
40 void IconLoader::NotifyDelegate() { | |
41 delegate_->OnImageLoaded(this, std::move(image_), group_); | |
42 } | |
OLD | NEW |