[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / icon_loader_auralinux.cc
1 // Copyright 2013 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 "base/functional/bind.h"
8 #include "base/nix/mime_util_xdg.h"
9 #include "content/public/browser/browser_task_traits.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "ui/linux/linux_ui.h"
12
13 // static
14 IconLoader::IconGroup IconLoader::GroupForFilepath(
15     const base::FilePath& file_path) {
16   return base::nix::GetFileMimeType(file_path);
17 }
18
19 // static
20 scoped_refptr<base::TaskRunner> IconLoader::GetReadIconTaskRunner() {
21   // ReadIcon() calls into ui::LinuxUi and GTK code, so it must be on the UI
22   // thread.
23   return content::GetUIThreadTaskRunner({});
24 }
25
26 void IconLoader::ReadIcon() {
27   int size_pixels = 0;
28   switch (icon_size_) {
29     case IconLoader::SMALL:
30       size_pixels = 16;
31       break;
32     case IconLoader::NORMAL:
33       size_pixels = 32;
34       break;
35     case IconLoader::LARGE:
36       size_pixels = 48;
37       break;
38     default:
39       NOTREACHED();
40   }
41
42   gfx::Image image;
43   ui::LinuxUi* ui = ui::LinuxUi::instance();
44   if (ui) {
45     image = ui->GetIconForContentType(group_, size_pixels, scale_);
46   }
47
48   target_task_runner_->PostTask(
49       FROM_HERE,
50       base::BindOnce(std::move(callback_), std::move(image), group_));
51   delete this;
52 }