blob: a9542745fbd34b98a914d94514daf7a89f6c57a3 [file] [log] [blame]
[email protected]46728b1f2009-05-07 20:42:241// Copyright (c) 2009 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
initial.commit09911bf2008-07-26 23:55:298#include <string>
initial.commit09911bf2008-07-26 23:55:299
[email protected]56d01f62009-03-12 22:41:5410#include "base/basictypes.h"
[email protected]7ced67af2009-04-14 23:25:1611#include "base/file_path.h"
[email protected]46728b1f2009-05-07 20:42:2412#include "base/ref_counted.h"
initial.commit09911bf2008-07-26 23:55:2913
[email protected]0f38ceae2009-05-08 19:01:0214#if defined(OS_WIN)
15// On Windows, we group files by their extension, with several exceptions:
16// .dll, .exe, .ico. See IconManager.h for explanation.
17typedef std::wstring IconGroupID;
18#elif defined(OS_POSIX)
19// On POSIX, we group files by MIME type.
20typedef std::string IconGroupID;
21#endif
22
23class MessageLoop;
initial.commit09911bf2008-07-26 23:55:2924class SkBitmap;
25
26////////////////////////////////////////////////////////////////////////////////
27//
28// A facility to read a file containing an icon asynchronously in the IO
[email protected]46728b1f2009-05-07 20:42:2429// thread. Returns the icon in the form of an SkBitmap.
initial.commit09911bf2008-07-26 23:55:2930//
31////////////////////////////////////////////////////////////////////////////////
[email protected]46728b1f2009-05-07 20:42:2432class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
initial.commit09911bf2008-07-26 23:55:2933 public:
initial.commit09911bf2008-07-26 23:55:2934 enum IconSize {
35 SMALL = 0, // 16x16
36 NORMAL, // 32x32
37 LARGE
38 };
39
40 class Delegate {
41 public:
42 // Invoked when an icon has been read. |source| is the IconLoader. If the
43 // icon has been successfully loaded, result is non-null. This method must
44 // return true if it is taking ownership of the returned bitmap.
[email protected]46728b1f2009-05-07 20:42:2445 virtual bool OnBitmapLoaded(IconLoader* source, SkBitmap* result) = 0;
[email protected]135fd3b62009-12-16 01:07:0846
47 protected:
48 virtual ~Delegate() {}
initial.commit09911bf2008-07-26 23:55:2949 };
50
[email protected]0f38ceae2009-05-08 19:01:0251 IconLoader(const IconGroupID& group, IconSize size, Delegate* delegate);
initial.commit09911bf2008-07-26 23:55:2952
[email protected]46728b1f2009-05-07 20:42:2453 // Start reading the icon on the file thread.
[email protected]0f38ceae2009-05-08 19:01:0254 void Start();
initial.commit09911bf2008-07-26 23:55:2955
56 private:
[email protected]e6e6ba42009-11-07 01:56:1957 friend class base::RefCountedThreadSafe<IconLoader>;
58
59 virtual ~IconLoader();
60
[email protected]0f38ceae2009-05-08 19:01:0261 void ReadIcon();
62
63 void NotifyDelegate();
64
65 // The message loop object of the thread in which we notify the delegate.
66 MessageLoop* target_message_loop_;
67
68 IconGroupID group_;
69
70 IconSize icon_size_;
71
72 SkBitmap* bitmap_;
73
74 Delegate* delegate_;
75
[email protected]937fe5202009-07-16 20:06:4776#if defined(OS_LINUX)
77 // On Linux we use gdk's pixbuf loader, which has to execute on the UI
78 // thread, so we only read the file on the background thread and parse it
79 // on the main thread.
80 void ParseIcon();
81 FilePath filename_;
82 std::string icon_data_;
83#endif
84
[email protected]7ced67af2009-04-14 23:25:1685 DISALLOW_COPY_AND_ASSIGN(IconLoader);
initial.commit09911bf2008-07-26 23:55:2986};
87
[email protected]7ced67af2009-04-14 23:25:1688#endif // CHROME_BROWSER_ICON_LOADER_H_