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 IconLoader::IconLoader(const base::FilePath& file_path, |
14 IconSize size, | 14 IconSize size, |
15 Delegate* delegate) | 15 IconLoadedCallback callback) |
16 : file_path_(file_path), | 16 : file_path_(file_path), icon_size_(size), callback_(std::move(callback)) {} |
17 icon_size_(size), | |
18 delegate_(delegate) {} | |
19 | 17 |
20 IconLoader::~IconLoader() { | 18 IconLoader::~IconLoader() { |
21 } | 19 } |
22 | 20 |
23 void IconLoader::Start() { | 21 void IconLoader::Start() { |
24 target_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 22 target_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
25 | 23 |
26 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 24 BrowserThread::PostTaskAndReply( |
27 base::Bind(&IconLoader::ReadGroup, this), | 25 BrowserThread::FILE, FROM_HERE, |
28 base::Bind(&IconLoader::OnReadGroup, this)); | 26 base::Bind(&IconLoader::ReadGroup, base::Unretained(this)), |
| 27 base::Bind(&IconLoader::OnReadGroup, base::Unretained(this))); |
29 } | 28 } |
30 | 29 |
31 void IconLoader::ReadGroup() { | 30 void IconLoader::ReadGroup() { |
32 group_ = GroupForFilepath(file_path_); | 31 group_ = GroupForFilepath(file_path_); |
33 } | 32 } |
34 | 33 |
35 void IconLoader::OnReadGroup() { | 34 void IconLoader::OnReadGroup() { |
36 BrowserThread::PostTask(ReadIconThreadID(), FROM_HERE, | 35 BrowserThread::PostTask( |
37 base::Bind(&IconLoader::ReadIcon, this)); | 36 ReadIconThreadID(), FROM_HERE, |
| 37 base::Bind(&IconLoader::ReadIcon, base::Unretained(this))); |
38 } | 38 } |
39 | |
40 void IconLoader::NotifyDelegate() { | |
41 delegate_->OnImageLoaded(this, std::move(image_), group_); | |
42 } | |
OLD | NEW |