blob: ff1c5a44378e3c625b7dea0e93b354f6f8961455 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
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]56d01f62009-03-12 22:41:5412
initial.commit09911bf2008-07-26 23:55:2913namespace {
14class IconLoaderProcessor;
15}
16
17class SkBitmap;
18
19////////////////////////////////////////////////////////////////////////////////
20//
21// A facility to read a file containing an icon asynchronously in the IO
22// thread. Clients has the option to get the icon in the form of two HICON
23// handles (one for a small icon size and one for a large icon) or in the form
24// of an SkBitmap.
25//
26// This class currently only supports reading .ico files. Please extend as
27// needed.
28//
29////////////////////////////////////////////////////////////////////////////////
30class IconLoader {
31 public:
initial.commit09911bf2008-07-26 23:55:2932 enum IconSize {
33 SMALL = 0, // 16x16
34 NORMAL, // 32x32
35 LARGE
36 };
37
38 class Delegate {
39 public:
40 // Invoked when an icon has been read. |source| is the IconLoader. If the
41 // icon has been successfully loaded, result is non-null. This method must
42 // return true if it is taking ownership of the returned bitmap.
initial.commit09911bf2008-07-26 23:55:2943 virtual bool OnSkBitmapLoaded(IconLoader* source, SkBitmap* result) = 0;
initial.commit09911bf2008-07-26 23:55:2944 };
45
46 // Create a new IconLoader that loads the icon from the data at contained in
[email protected]7ced67af2009-04-14 23:25:1647 // the file at |path|.
48 static IconLoader* CreateIconLoaderForFile(const FilePath& path,
initial.commit09911bf2008-07-26 23:55:2949 Delegate* delegate);
50
51 // Create a new IconLoader that loads the icon in the resource of the file
52 // at |path|. This is used with .exe/.dll files.
53 // Note that this generates a SkBitmap (and consequently OnSkBitmapLoaded is
54 // invoked on the delegate once the load has completed).
[email protected]7ced67af2009-04-14 23:25:1655 static IconLoader* CreateIconLoaderForFileResource(const FilePath& path,
initial.commit09911bf2008-07-26 23:55:2956 IconSize size,
57 Delegate* delegate);
58
59 ~IconLoader();
60
61 // Start the read operation
62 void Start();
63
64 // Cancel the read operation. The delegate will no longer be contacted. Call
65 // this method if you need to delete the delegate.
66 void Cancel();
67
68 private:
69 friend class IconLoaderProcessor;
70
71 // Use the factory methods CreateIconLoader* instead of using this constructor
[email protected]7ced67af2009-04-14 23:25:1672 IconLoader(const FilePath& path,
initial.commit09911bf2008-07-26 23:55:2973 bool from_resource,
74 IconSize size,
75 Delegate* delegate);
76
77 // Invoked by the processor when the file has been read and an SkBitmap
78 // object was requested.
79 bool OnLoadComplete(SkBitmap* result);
80
initial.commit09911bf2008-07-26 23:55:2981 // The path.
[email protected]7ced67af2009-04-14 23:25:1682 FilePath path_;
initial.commit09911bf2008-07-26 23:55:2983
84 // The delegate.
85 Delegate* delegate_;
86
87 // Whether we are loading the icon from the resource in the file (if false,
88 // the icon is simply loaded from the file content).
89 bool loading_from_resource_;
90
91 // The size of the icon that should be loaded from the file resource.
92 // Not used if loading_from_resource_ is false.
93 IconSize icon_size_;
94
initial.commit09911bf2008-07-26 23:55:2995 // The underlying object performing the read.
96 IconLoaderProcessor* processor_;
97
[email protected]7ced67af2009-04-14 23:25:1698 DISALLOW_COPY_AND_ASSIGN(IconLoader);
initial.commit09911bf2008-07-26 23:55:2999};
100
[email protected]7ced67af2009-04-14 23:25:16101#endif // CHROME_BROWSER_ICON_LOADER_H_