0e48a45fe33a3bf798aaeff14393ac01f0e81a4a
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.
5 #ifndef CHROME_BROWSER_ICON_LOADER_H_
6 #define CHROME_BROWSER_ICON_LOADER_H_
8 #include "build/build_config.h"
12 #include "base/basictypes.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_loop_proxy.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "ui/gfx/image/image.h"
21 // On Windows, we group files by their extension, with several exceptions:
22 // .dll, .exe, .ico. See IconManager.h for explanation.
23 typedef std::wstring IconGroupID
;
24 #elif defined(OS_POSIX)
25 // On POSIX, we group files by MIME type.
26 typedef std::string IconGroupID
;
29 ////////////////////////////////////////////////////////////////////////////////
31 // A facility to read a file containing an icon asynchronously in the IO
32 // thread. Returns the icon in the form of an ImageSkia.
34 ////////////////////////////////////////////////////////////////////////////////
35 class IconLoader
: public base::RefCountedThreadSafe
<IconLoader
> {
40 LARGE
, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
41 ALL
, // All sizes available
46 // Invoked when an icon group has been read, but before the icon data
47 // is read. If the icon is already cached, this method should call and
48 // return the results of OnImageLoaded with the cached image.
49 virtual bool OnGroupLoaded(IconLoader
* source
,
50 const IconGroupID
& group
) = 0;
51 // Invoked when an icon has been read. |source| is the IconLoader. If the
52 // icon has been successfully loaded, result is non-null. This method must
53 // return true if it is taking ownership of the returned image.
54 virtual bool OnImageLoaded(IconLoader
* source
,
56 const IconGroupID
& group
) = 0;
59 virtual ~Delegate() {}
62 IconLoader(const base::FilePath
& file_path
,
66 // Start reading the icon on the file thread.
70 friend class base::RefCountedThreadSafe
<IconLoader
>;
72 virtual ~IconLoader();
74 // Get the identifying string for the given file. The implementation
75 // is in icon_loader_[platform].cc.
76 static IconGroupID
ReadGroupIDFromFilepath(const base::FilePath
& path
);
78 // Some icons (exe's on windows) can change as they're loaded.
79 static bool IsIconMutableFromFilepath(const base::FilePath
& path
);
81 // The thread ReadIcon() should be called on.
82 static content::BrowserThread::ID
ReadIconThreadID();
88 void NotifyDelegate();
90 // The message loop object of the thread in which we notify the delegate.
91 scoped_refptr
<base::MessageLoopProxy
> target_message_loop_
;
93 base::FilePath file_path_
;
99 scoped_ptr
<gfx::Image
> image_
;
103 DISALLOW_COPY_AND_ASSIGN(IconLoader
);
106 #endif // CHROME_BROWSER_ICON_LOADER_H_