recommended_apps.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1// Copyright 2013 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.
4
5#ifndef CHROME_BROWSER_UI_APP_LIST_RECOMMENDED_APPS_H_
6#define CHROME_BROWSER_UI_APP_LIST_RECOMMENDED_APPS_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/memory/ref_counted.h"
12#include "base/observer_list.h"
13#include "base/prefs/pref_change_registrar.h"
14#include "base/scoped_observer.h"
15#include "extensions/browser/extension_registry_observer.h"
16
17class Profile;
18
19namespace extensions {
20class ExtensionRegistry;
21}
22
23namespace app_list {
24
25class RecommendedAppsObserver;
26
27// A class that maintains a list of recommended apps by watching changes
28// to app state.
29class RecommendedApps : public extensions::ExtensionRegistryObserver {
30 public:
31  typedef std::vector<scoped_refptr<const extensions::Extension> > Apps;
32
33  explicit RecommendedApps(Profile* profile);
34  virtual ~RecommendedApps();
35
36  void AddObserver(RecommendedAppsObserver* observer);
37  void RemoveObserver(RecommendedAppsObserver* observer);
38
39  const Apps& apps() const { return apps_; }
40
41 private:
42  void Update();
43
44  // extensions::ExtensionRegistryObserver overrides:
45  virtual void OnExtensionWillBeInstalled(
46      content::BrowserContext* browser_context,
47      const extensions::Extension* extension,
48      bool is_update,
49      bool from_ephemeral,
50      const std::string& old_name) OVERRIDE;
51  virtual void OnExtensionLoaded(
52      content::BrowserContext* browser_context,
53      const extensions::Extension* extension) OVERRIDE;
54  virtual void OnExtensionUnloaded(
55      content::BrowserContext* browser_context,
56      const extensions::Extension* extension,
57      extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
58  virtual void OnExtensionUninstalled(
59      content::BrowserContext* browser_context,
60      const extensions::Extension* extension,
61      extensions::UninstallReason reason) OVERRIDE;
62
63  Profile* profile_;
64  PrefChangeRegistrar pref_change_registrar_;
65
66  Apps apps_;
67  ObserverList<RecommendedAppsObserver, true> observers_;
68
69  ScopedObserver<extensions::ExtensionRegistry,
70                 extensions::ExtensionRegistryObserver>
71      extension_registry_observer_;
72
73  DISALLOW_COPY_AND_ASSIGN(RecommendedApps);
74};
75
76}  // namespace app_list
77
78#endif  // CHROME_BROWSER_UI_APP_LIST_RECOMMENDED_APPS_H_
79