8342ec934a8622fdd51c90345137bcea83af8161
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / install_tracker.h
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_EXTENSIONS_INSTALL_TRACKER_H_
6 #define CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_
7
8 #include "base/observer_list.h"
9 #include "base/prefs/pref_change_registrar.h"
10 #include "base/scoped_observer.h"
11 #include "chrome/browser/extensions/install_observer.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "extensions/browser/extension_registry_observer.h"
16
17 class Profile;
18
19 namespace content {
20 class BrowserContext;
21 }
22
23 namespace extensions {
24
25 class ExtensionPrefs;
26 class ExtensionRegistry;
27
28 class InstallTracker : public KeyedService,
29                        public content::NotificationObserver,
30                        public ExtensionRegistryObserver {
31  public:
32   InstallTracker(Profile* profile,
33                  extensions::ExtensionPrefs* prefs);
34   virtual ~InstallTracker();
35
36   static InstallTracker* Get(content::BrowserContext* context);
37
38   void AddObserver(InstallObserver* observer);
39   void RemoveObserver(InstallObserver* observer);
40
41   void OnBeginExtensionInstall(
42       const InstallObserver::ExtensionInstallParams& params);
43   void OnBeginExtensionDownload(const std::string& extension_id);
44   void OnDownloadProgress(const std::string& extension_id,
45                           int percent_downloaded);
46   void OnBeginCrxInstall(const std::string& extension_id);
47   void OnFinishCrxInstall(const std::string& extension_id, bool success);
48   void OnInstallFailure(const std::string& extension_id);
49
50   // Overriddes for KeyedService.
51   virtual void Shutdown() OVERRIDE;
52
53  private:
54   void OnAppsReordered();
55
56   // content::NotificationObserver.
57   virtual void Observe(int type,
58                        const content::NotificationSource& source,
59                        const content::NotificationDetails& details) OVERRIDE;
60
61   // ExtensionRegistryObserver implementation.
62   virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
63                                  const Extension* extension) OVERRIDE;
64   virtual void OnExtensionUnloaded(
65       content::BrowserContext* browser_context,
66       const Extension* extension,
67       UnloadedExtensionInfo::Reason reason) OVERRIDE;
68
69   ObserverList<InstallObserver> observers_;
70   content::NotificationRegistrar registrar_;
71   PrefChangeRegistrar pref_change_registrar_;
72
73   // Listen to extension load, unloaded notifications.
74   ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
75       extension_registry_observer_;
76
77   DISALLOW_COPY_AND_ASSIGN(InstallTracker);
78 };
79
80 }  // namespace extensions
81
82 #endif  // CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_