Revert 285173 "Removed InProcessBrowserTest::CleanUpOnMainThread()"
[chromium-blink-merge.git] / chrome / browser / extensions / extension_icon_manager.h
blobd8f1e78985386e9e80391178cf94f48fbb5a03d8
1 // Copyright (c) 2011 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_EXTENSIONS_EXTENSION_ICON_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/memory/weak_ptr.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/gfx/insets.h"
17 namespace content {
18 class BrowserContext;
21 namespace extensions {
22 class Extension;
25 namespace gfx {
26 class Image;
29 class ExtensionIconManager {
30 public:
31 ExtensionIconManager();
32 virtual ~ExtensionIconManager();
34 // Start loading the icon for the given extension.
35 void LoadIcon(content::BrowserContext* context,
36 const extensions::Extension* extension);
38 // This returns a bitmap of width/height kFaviconSize, loaded either from an
39 // entry specified in the extension's 'icon' section of the manifest, or a
40 // default extension icon.
41 const SkBitmap& GetIcon(const std::string& extension_id);
43 // Removes the extension's icon from memory.
44 void RemoveIcon(const std::string& extension_id);
46 void set_monochrome(bool value) { monochrome_ = value; }
47 void set_padding(const gfx::Insets& value) { padding_ = value; }
49 protected:
50 virtual void OnImageLoaded(const std::string& extension_id,
51 const gfx::Image& image);
53 private:
54 // Makes sure we've done one-time initialization of the default extension icon
55 // default_icon_.
56 void EnsureDefaultIcon();
58 // Helper function to return a copy of |src| with the proper scaling and
59 // coloring.
60 SkBitmap ApplyTransforms(const SkBitmap& src);
62 // Maps extension id to an SkBitmap with the icon for that extension.
63 std::map<std::string, SkBitmap> icons_;
65 // Set of extension IDs waiting for icons to load.
66 std::set<std::string> pending_icons_;
68 // The default icon we'll use if an extension doesn't have one.
69 SkBitmap default_icon_;
71 // If true, we will desaturate the icons to make them monochromatic.
72 bool monochrome_;
74 // Specifies the amount of empty padding to place around the icon.
75 gfx::Insets padding_;
77 base::WeakPtrFactory<ExtensionIconManager> weak_ptr_factory_;
79 DISALLOW_COPY_AND_ASSIGN(ExtensionIconManager);
82 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_MANAGER_H_