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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_
6 #define CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_
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"
23 namespace extensions
{
26 class ExtensionRegistry
;
28 class InstallTracker
: public KeyedService
,
29 public content::NotificationObserver
,
30 public ExtensionRegistryObserver
{
32 InstallTracker(Profile
* profile
,
33 extensions::ExtensionPrefs
* prefs
);
34 virtual ~InstallTracker();
36 static InstallTracker
* Get(content::BrowserContext
* context
);
38 void AddObserver(InstallObserver
* observer
);
39 void RemoveObserver(InstallObserver
* observer
);
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
);
50 // Overriddes for KeyedService.
51 virtual void Shutdown() OVERRIDE
;
54 void OnAppsReordered();
56 // content::NotificationObserver.
57 virtual void Observe(int type
,
58 const content::NotificationSource
& source
,
59 const content::NotificationDetails
& details
) OVERRIDE
;
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
;
69 ObserverList
<InstallObserver
> observers_
;
70 content::NotificationRegistrar registrar_
;
71 PrefChangeRegistrar pref_change_registrar_
;
73 // Listen to extension load, unloaded notifications.
74 ScopedObserver
<ExtensionRegistry
, ExtensionRegistryObserver
>
75 extension_registry_observer_
;
77 DISALLOW_COPY_AND_ASSIGN(InstallTracker
);
80 } // namespace extensions
82 #endif // CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_