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 "ui/gfx/image/image.h"
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
;
28 ////////////////////////////////////////////////////////////////////////////////
30 // A facility to read a file containing an icon asynchronously in the IO
31 // thread. Returns the icon in the form of an ImageSkia.
33 ////////////////////////////////////////////////////////////////////////////////
34 class IconLoader
: public base::RefCountedThreadSafe
<IconLoader
> {
39 LARGE
, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
40 ALL
, // All sizes available
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
51 // icon has been successfully loaded, result is non-null. This method must
52 // return true if it is taking ownership of the returned image.
53 virtual bool OnImageLoaded(IconLoader
* source
,
55 const IconGroupID
& group
) = 0;
58 virtual ~Delegate() {}
61 IconLoader(const base::FilePath
& file_path
,
65 // Start reading the icon on the file thread.
69 friend class base::RefCountedThreadSafe
<IconLoader
>;
71 virtual ~IconLoader();
73 // Get the identifying string for the given file. The implementation
74 // is in icon_loader_[platform].cc.
75 static IconGroupID
ReadGroupIDFromFilepath(const base::FilePath
& path
);
77 // Some icons (exe's on windows) can change as they're loaded.
78 static bool IsIconMutableFromFilepath(const base::FilePath
& path
);
84 void NotifyDelegate();
86 // The message loop object of the thread in which we notify the delegate.
87 scoped_refptr
<base::MessageLoopProxy
> target_message_loop_
;
89 base::FilePath file_path_
;
95 scoped_ptr
<gfx::Image
> image_
;
99 DISALLOW_COPY_AND_ASSIGN(IconLoader
);
102 #endif // CHROME_BROWSER_ICON_LOADER_H_