blob: ff22c7a056c8995ca6952fbac554d5263c05e70e [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]3b63f8f42011-03-28 01:54:1513#include "base/memory/ref_counted.h"
14#include "base/memory/scoped_ptr.h"
[email protected]982735c22010-10-29 13:58:5715#include "base/message_loop_proxy.h"
[email protected]f08e0512011-06-13 18:10:4416#include "ui/gfx/image/image.h"
[email protected]982735c22010-10-29 13:58:5717
[email protected]0f38ceae2009-05-08 19:01:0218#if defined(OS_WIN)
19// On Windows, we group files by their extension, with several exceptions:
20// .dll, .exe, .ico. See IconManager.h for explanation.
21typedef std::wstring IconGroupID;
22#elif defined(OS_POSIX)
23// On POSIX, we group files by MIME type.
24typedef std::string IconGroupID;
25#endif
26
initial.commit09911bf2008-07-26 23:55:2927////////////////////////////////////////////////////////////////////////////////
28//
29// A facility to read a file containing an icon asynchronously in the IO
[email protected]679facce2012-07-25 16:13:1230// thread. Returns the icon in the form of an ImageSkia.
initial.commit09911bf2008-07-26 23:55:2931//
32////////////////////////////////////////////////////////////////////////////////
[email protected]46728b1f2009-05-07 20:42:2433class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
initial.commit09911bf2008-07-26 23:55:2934 public:
initial.commit09911bf2008-07-26 23:55:2935 enum IconSize {
36 SMALL = 0, // 16x16
37 NORMAL, // 32x32
[email protected]955c37b2011-06-08 21:26:3038 LARGE, // Windows: 32x32, Linux: 48x48, Mac: Unsupported
39 ALL, // All sizes available
initial.commit09911bf2008-07-26 23:55:2940 };
41
42 class Delegate {
43 public:
44 // Invoked when an icon has been read. |source| is the IconLoader. If the
45 // icon has been successfully loaded, result is non-null. This method must
[email protected]679facce2012-07-25 16:13:1246 // return true if it is taking ownership of the returned image.
[email protected]66171ab2011-03-03 15:50:0747 virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result) = 0;
[email protected]135fd3b62009-12-16 01:07:0848
49 protected:
50 virtual ~Delegate() {}
initial.commit09911bf2008-07-26 23:55:2951 };
52
[email protected]0f38ceae2009-05-08 19:01:0253 IconLoader(const IconGroupID& group, IconSize size, Delegate* delegate);
initial.commit09911bf2008-07-26 23:55:2954
[email protected]46728b1f2009-05-07 20:42:2455 // Start reading the icon on the file thread.
[email protected]0f38ceae2009-05-08 19:01:0256 void Start();
initial.commit09911bf2008-07-26 23:55:2957
58 private:
[email protected]e6e6ba42009-11-07 01:56:1959 friend class base::RefCountedThreadSafe<IconLoader>;
60
61 virtual ~IconLoader();
62
[email protected]0f38ceae2009-05-08 19:01:0263 void ReadIcon();
64
65 void NotifyDelegate();
66
67 // The message loop object of the thread in which we notify the delegate.
[email protected]982735c22010-10-29 13:58:5768 scoped_refptr<base::MessageLoopProxy> target_message_loop_;
[email protected]0f38ceae2009-05-08 19:01:0269
70 IconGroupID group_;
71
72 IconSize icon_size_;
73
[email protected]66171ab2011-03-03 15:50:0774 scoped_ptr<gfx::Image> image_;
[email protected]0f38ceae2009-05-08 19:01:0275
76 Delegate* delegate_;
77
[email protected]7ced67af2009-04-14 23:25:1678 DISALLOW_COPY_AND_ASSIGN(IconLoader);
initial.commit09911bf2008-07-26 23:55:2979};
80
[email protected]7ced67af2009-04-14 23:25:1681#endif // CHROME_BROWSER_ICON_LOADER_H_