Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: chrome/browser/icon_loader.h

Issue 2440273002: Clean up the IconLoader. (Closed)
Patch Set: nits Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/icon_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CHROME_BROWSER_ICON_LOADER_H_ 5 #ifndef CHROME_BROWSER_ICON_LOADER_H_
6 #define CHROME_BROWSER_ICON_LOADER_H_ 6 #define CHROME_BROWSER_ICON_LOADER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "ui/gfx/image/image.h" 17 #include "ui/gfx/image/image.h"
18 18
19 #if defined(OS_WIN)
20 // On Windows, we group files by their extension, with several exceptions:
21 // .dll, .exe, .ico. See IconManager.h for explanation.
22 typedef std::wstring IconGroupID;
23 #elif defined(OS_POSIX)
24 // On POSIX, we group files by MIME type.
25 typedef std::string IconGroupID;
26 #endif
27
28 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
29 // 20 //
30 // A facility to read a file containing an icon asynchronously in the IO 21 // A facility to read a file containing an icon asynchronously in the IO
31 // thread. Returns the icon in the form of an ImageSkia. 22 // thread. Returns the icon in the form of an ImageSkia.
32 // 23 //
33 //////////////////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////////////////
34 class IconLoader : public base::RefCountedThreadSafe<IconLoader> { 25 class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
35 public: 26 public:
27 // An IconGroup is a class of files that all share the same icon. For all
28 // platforms but Windows, and for most files on Windows, it is the file type
29 // (e.g. all .mp3 files share an icon, all .html files share an icon). On
30 // Windows, for certain file types (.exe, .dll, etc), each file of that type
31 // is assumed to have a unique icon. In that case, each of those files is a
32 // group to itself.
33 using IconGroup = base::FilePath::StringType;
34
36 enum IconSize { 35 enum IconSize {
37 SMALL = 0, // 16x16 36 SMALL = 0, // 16x16
38 NORMAL, // 32x32 37 NORMAL, // 32x32
39 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported 38 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
40 ALL, // All sizes available 39 ALL, // All sizes available
41 }; 40 };
42 41
43 class Delegate { 42 class Delegate {
44 public: 43 public:
45 // Invoked when an icon group has been read, but before the icon data
46 // is read. If the icon is already cached, this method should call and
47 // return the results of OnImageLoaded with the cached image.
48 virtual bool OnGroupLoaded(IconLoader* source,
49 const IconGroupID& group) = 0;
50 // Invoked when an icon has been read. |source| is the IconLoader. If the 44 // Invoked when an icon has been read. |source| is the IconLoader. If the
51 // icon has been successfully loaded, result is non-null. This method must 45 // icon has been successfully loaded, |result| is non-null. |group| is the
52 // return true if it is taking ownership of the returned image. 46 // determined group from the original requested path.
53 virtual bool OnImageLoaded(IconLoader* source, 47 virtual void OnImageLoaded(IconLoader* source,
54 gfx::Image* result, 48 std::unique_ptr<gfx::Image> result,
55 const IconGroupID& group) = 0; 49 const IconGroup& group) = 0;
56 50
57 protected: 51 protected:
58 virtual ~Delegate() {} 52 virtual ~Delegate() {}
59 }; 53 };
60 54
61 IconLoader(const base::FilePath& file_path, 55 IconLoader(const base::FilePath& file_path,
62 IconSize size, 56 IconSize size,
63 Delegate* delegate); 57 Delegate* delegate);
64 58
65 // Start reading the icon on the file thread. 59 // Start reading the icon on the file thread.
66 void Start(); 60 void Start();
67 61
68 private: 62 private:
69 friend class base::RefCountedThreadSafe<IconLoader>; 63 friend class base::RefCountedThreadSafe<IconLoader>;
70 64
71 virtual ~IconLoader(); 65 virtual ~IconLoader();
72 66
73 // Get the identifying string for the given file. The implementation 67 // Given a file path, get the group for the given file.
74 // is in icon_loader_[platform].cc. 68 static IconGroup GroupForFilepath(const base::FilePath& file_path);
75 static IconGroupID ReadGroupIDFromFilepath(const base::FilePath& path);
76
77 // Some icons (exe's on windows) can change as they're loaded.
78 static bool IsIconMutableFromFilepath(const base::FilePath& path);
79 69
80 // The thread ReadIcon() should be called on. 70 // The thread ReadIcon() should be called on.
81 static content::BrowserThread::ID ReadIconThreadID(); 71 static content::BrowserThread::ID ReadIconThreadID();
82 72
83 void ReadGroup(); 73 void ReadGroup();
84 void OnReadGroup(); 74 void OnReadGroup();
85 void ReadIcon(); 75 void ReadIcon();
86 76
87 void NotifyDelegate(); 77 void NotifyDelegate();
88 78
89 // The task runner object of the thread in which we notify the delegate. 79 // The task runner object of the thread in which we notify the delegate.
90 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_; 80 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_;
91 81
92 base::FilePath file_path_; 82 base::FilePath file_path_;
93 83
94 IconGroupID group_; 84 IconGroup group_;
95 85
96 IconSize icon_size_; 86 IconSize icon_size_;
97 87
98 std::unique_ptr<gfx::Image> image_; 88 std::unique_ptr<gfx::Image> image_;
99 89
100 Delegate* delegate_; 90 Delegate* delegate_;
101 91
102 DISALLOW_COPY_AND_ASSIGN(IconLoader); 92 DISALLOW_COPY_AND_ASSIGN(IconLoader);
103 }; 93 };
104 94
105 #endif // CHROME_BROWSER_ICON_LOADER_H_ 95 #endif // CHROME_BROWSER_ICON_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/icon_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698