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