summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/app_icon_loader_impl.h
blob: 4ed16357a24addf5512fd707f34c7160011d3b03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_APP_ICON_LOADER_IMPL_H_
#define CHROME_BROWSER_EXTENSIONS_APP_ICON_LOADER_IMPL_H_

#include <map>
#include <string>

#include "chrome/browser/extensions/app_icon_loader.h"
#include "extensions/browser/extension_icon_image.h"

class Profile;

namespace extensions {
class Extension;

// Default implementation of ash::AppIconLoader that interacts with the
// ExtensionService and ImageLoader to load images.
class AppIconLoaderImpl : public AppIconLoader,
                          public extensions::IconImage::Observer {
 public:
  AppIconLoaderImpl(Profile* profile, int icon_size,
                    AppIconLoader::Delegate* delegate);
  ~AppIconLoaderImpl() override;

  // AppIconLoader overrides:
  void FetchImage(const std::string& id) override;
  void ClearImage(const std::string& id) override;
  void UpdateImage(const std::string& id) override;

  // extensions::IconImage::Observer overrides:
  void OnExtensionIconImageChanged(extensions::IconImage* image) override;

 private:
  typedef std::map<extensions::IconImage*, std::string> ImageToExtensionIDMap;

  // Builds image for given |id| and |icon|.
  void BuildImage(const std::string& id, const gfx::ImageSkia& icon);

  Profile* profile_;

  // The delegate object which receives the icon images. No ownership.
  AppIconLoader::Delegate* delegate_;

  // Maps from IconImage pointer to the extension id.
  ImageToExtensionIDMap map_;

  const int icon_size_;

  DISALLOW_COPY_AND_ASSIGN(AppIconLoaderImpl);
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_APP_ICON_LOADER_IMPL_H_