[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / icon_loader.cc
1 // Copyright 2012 The Chromium Authors
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
7 #include <utility>
8
9 #include "base/functional/bind.h"
10 #include "base/task/single_thread_task_runner.h"
11 #include "base/task/thread_pool.h"
12 #include "build/build_config.h"
13 #include "content/public/browser/browser_thread.h"
14
15 using content::BrowserThread;
16
17 // static
18 void IconLoader::LoadIcon(const base::FilePath& file_path,
19                           IconSize size,
20                           float scale,
21                           IconLoadedCallback callback) {
22   (new IconLoader(file_path, size, scale, std::move(callback)))->Start();
23 }
24
25 IconLoader::IconLoader(const base::FilePath& file_path,
26                        IconSize size,
27                        float scale,
28                        IconLoadedCallback callback)
29     : file_path_(file_path),
30 #if !BUILDFLAG(IS_ANDROID)
31       icon_size_(size),
32 #endif
33       scale_(scale),
34       callback_(std::move(callback)) {
35 }
36
37 IconLoader::~IconLoader() = default;
38
39 #if !BUILDFLAG(IS_CHROMEOS)
40 void IconLoader::Start() {
41   target_task_runner_ = base::SingleThreadTaskRunner::GetCurrentDefault();
42
43   base::ThreadPool::PostTask(
44       FROM_HERE, traits(),
45       base::BindOnce(&IconLoader::ReadGroup, base::Unretained(this)));
46 }
47
48 #if !BUILDFLAG(IS_WIN)
49 void IconLoader::ReadGroup() {
50   group_ = GroupForFilepath(file_path_);
51
52   GetReadIconTaskRunner()->PostTask(
53       FROM_HERE, base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this)));
54 }
55 #endif  // !BUILDFLAG(IS_WIN)
56 #endif  // !BUILDFLAG(IS_CHROMEOS)