blob: ef602128276df9465020585112b8a6785a44703b [file] [log] [blame]
[email protected]679facce2012-07-25 16:13:121// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]7ced67af2009-04-14 23:25:165#ifndef CHROME_BROWSER_ICON_LOADER_H_
6#define CHROME_BROWSER_ICON_LOADER_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]864b1362010-08-19 03:49:388#include "build/build_config.h"
9
initial.commit09911bf2008-07-26 23:55:2910#include <string>
initial.commit09911bf2008-07-26 23:55:2911
[email protected]56d01f62009-03-12 22:41:5412#include "base/basictypes.h"
[email protected]bc0147b2013-04-03 20:50:5913#include "base/files/file_path.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/ref_counted.h"
15#include "base/memory/scoped_ptr.h"
[email protected]76ae8a62013-05-10 05:34:2216#include "base/message_loop/message_loop_proxy.h"
[email protected]f08e0512011-06-13 18:10:4417#include "ui/gfx/image/image.h"
[email protected]982735c22010-10-29 13:58:5718
[email protected]0f38ceae2009-05-08 19:01:0219#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.
22typedef std::wstring IconGroupID;
23#elif defined(OS_POSIX)
24// On POSIX, we group files by MIME type.
25typedef std::string IconGroupID;
26#endif
27
initial.commit09911bf2008-07-26 23:55:2928////////////////////////////////////////////////////////////////////////////////
29//
30// A facility to read a file containing an icon asynchronously in the IO
[email protected]679facce2012-07-25 16:13:1231// thread. Returns the icon in the form of an ImageSkia.
initial.commit09911bf2008-07-26 23:55:2932//
33////////////////////////////////////////////////////////////////////////////////
[email protected]46728b1f2009-05-07 20:42:2434class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
initial.commit09911bf2008-07-26 23:55:2935 public:
initial.commit09911bf2008-07-26 23:55:2936 enum IconSize {
37 SMALL = 0, // 16x16
38 NORMAL, // 32x32
[email protected]955c37b2011-06-08 21:26:3039 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
40 ALL, // All sizes available
initial.commit09911bf2008-07-26 23:55:2941 };
42
43 class Delegate {
44 public:
[email protected]bc0147b2013-04-03 20:50:5945 // 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;
initial.commit09911bf2008-07-26 23:55:2950 // 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
[email protected]679facce2012-07-25 16:13:1252 // return true if it is taking ownership of the returned image.
[email protected]bc0147b2013-04-03 20:50:5953 virtual bool OnImageLoaded(IconLoader* source,
54 gfx::Image* result,
55 const IconGroupID& group) = 0;
[email protected]135fd3b62009-12-16 01:07:0856
57 protected:
58 virtual ~Delegate() {}
initial.commit09911bf2008-07-26 23:55:2959 };
60
[email protected]bc0147b2013-04-03 20:50:5961 IconLoader(const base::FilePath& file_path,
62 IconSize size,
63 Delegate* delegate);
initial.commit09911bf2008-07-26 23:55:2964
[email protected]46728b1f2009-05-07 20:42:2465 // Start reading the icon on the file thread.
[email protected]0f38ceae2009-05-08 19:01:0266 void Start();
initial.commit09911bf2008-07-26 23:55:2967
68 private:
[email protected]e6e6ba42009-11-07 01:56:1969 friend class base::RefCountedThreadSafe<IconLoader>;
70
71 virtual ~IconLoader();
72
[email protected]bc0147b2013-04-03 20:50:5973 // 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);
76
[email protected]681b4b82013-04-09 23:34:2177 // Some icons (exe's on windows) can change as they're loaded.
78 static bool IsIconMutableFromFilepath(const base::FilePath& path);
79
[email protected]bc0147b2013-04-03 20:50:5980 void ReadGroup();
81 void OnReadGroup();
[email protected]0f38ceae2009-05-08 19:01:0282 void ReadIcon();
83
84 void NotifyDelegate();
85
86 // The message loop object of the thread in which we notify the delegate.
[email protected]982735c22010-10-29 13:58:5787 scoped_refptr<base::MessageLoopProxy> target_message_loop_;
[email protected]0f38ceae2009-05-08 19:01:0288
[email protected]bc0147b2013-04-03 20:50:5989 base::FilePath file_path_;
90
[email protected]0f38ceae2009-05-08 19:01:0291 IconGroupID group_;
92
93 IconSize icon_size_;
94
[email protected]66171ab2011-03-03 15:50:0795 scoped_ptr<gfx::Image> image_;
[email protected]0f38ceae2009-05-08 19:01:0296
97 Delegate* delegate_;
98
[email protected]7ced67af2009-04-14 23:25:1699 DISALLOW_COPY_AND_ASSIGN(IconLoader);
initial.commit09911bf2008-07-26 23:55:29100};
101
[email protected]7ced67af2009-04-14 23:25:16102#endif // CHROME_BROWSER_ICON_LOADER_H_