[M120][Tizen][Onscreen] Fix build errors for TV profile
[platform/framework/web/chromium-efl.git] / chrome / browser / icon_loader.h
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 #ifndef CHROME_BROWSER_ICON_LOADER_H_
6 #define CHROME_BROWSER_ICON_LOADER_H_
7
8 #include "base/files/file_path.h"
9 #include "base/functional/callback.h"
10 #include "base/task/single_thread_task_runner.h"
11 #include "base/task/task_traits.h"
12 #include "build/build_config.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "ui/gfx/image/image.h"
15
16 ////////////////////////////////////////////////////////////////////////////////
17 //
18 // A facility to read a file containing an icon asynchronously in the IO
19 // thread. Returns the icon in the form of an ImageSkia.
20 //
21 ////////////////////////////////////////////////////////////////////////////////
22 class IconLoader {
23  public:
24   // An IconGroup is a class of files that all share the same icon.
25 #if BUILDFLAG(IS_MAC)
26   // On the Mac, it's the UTType's identifier. (Apps do have unique icons, just
27   // like in Windows, below, but `IconLoader` is never used to get their icons,
28   // so that case isn't handled.)
29   using IconGroup = std::string;
30 #else
31   // On all other platforms except Windows, and for most files on Windows, it is
32   // the file type (e.g. all .mp3 files share an icon, all .html files share an
33   // icon). On Windows, for certain file types (.exe, .dll, etc), each file of
34   // that type is assumed to have a unique icon. In that case, each of those
35   // files is a group to itself.
36   using IconGroup = base::FilePath::StringType;
37 #endif
38
39   enum IconSize {
40     SMALL = 0,  // 16x16
41     NORMAL,     // 32x32
42     LARGE,      // Windows: 32x32, Linux: 48x48, Mac: Unsupported
43     ALL,        // All sizes available
44   };
45
46   // The callback invoked when an icon has been read. The parameters are:
47   // - The icon that was loaded (IsEmpty() will be true on failure to load).
48   // - The determined group from the original requested path.
49   using IconLoadedCallback =
50       base::OnceCallback<void(gfx::Image, const IconGroup&)>;
51
52   // Starts the process of reading the icon. When the reading of the icon is
53   // complete, the IconLoadedCallback callback will be fulfilled, and the
54   // IconLoader will delete itself.
55   static void LoadIcon(const base::FilePath& file_path,
56                        IconSize size,
57                        float scale,
58                        IconLoadedCallback callback);
59
60   IconLoader(const IconLoader&) = delete;
61   IconLoader& operator=(const IconLoader&) = delete;
62
63  private:
64   IconLoader(const base::FilePath& file_path,
65              IconSize size,
66              float scale,
67              IconLoadedCallback callback);
68
69   ~IconLoader();
70
71   void Start();
72
73   // Given a file path, get the group for the given file.
74   static IconGroup GroupForFilepath(const base::FilePath& file_path);
75
76   // The TaskRunner that ReadIcon() must be called on.
77   static scoped_refptr<base::TaskRunner> GetReadIconTaskRunner();
78
79 #if !BUILDFLAG(IS_CHROMEOS)
80   void ReadGroup();
81   void ReadIcon();
82 #endif
83 #if BUILDFLAG(IS_WIN)
84   // Reads an icon in a sandboxed service. Use this when the file itself must
85   // be parsed.
86   void ReadIconInSandbox();
87 #endif
88
89   // The traits of the tasks posted to base::ThreadPool by this class. These
90   // operations may block, because they are fetching icons from the disk, yet
91   // the result will be seen by the user so they should be prioritized
92   // accordingly. They should not however block shutdown if long running.
93   static constexpr base::TaskTraits traits() {
94     return {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
95             base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN};
96   }
97
98   // The task runner object of the thread in which we notify the delegate.
99   scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_;
100
101   base::FilePath file_path_;
102
103   IconGroup group_;
104
105 #if !BUILDFLAG(IS_ANDROID)
106   IconSize icon_size_;
107 #endif  // !BUILDFLAG(IS_ANDROID)
108   const float scale_;
109   IconLoadedCallback callback_;
110 };
111
112 #endif  // CHROME_BROWSER_ICON_LOADER_H_