Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / extensions / install_tracker.h
blob4a3c264c1260e987df66eddabe58327ea641a67e
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 <map>
10 #include "base/observer_list.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/extensions/active_install_data.h"
14 #include "chrome/browser/extensions/install_observer.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "extensions/browser/extension_registry_observer.h"
20 namespace content {
21 class BrowserContext;
24 namespace extensions {
26 class ExtensionPrefs;
27 class ExtensionRegistry;
29 class InstallTracker : public KeyedService,
30 public content::NotificationObserver,
31 public ExtensionRegistryObserver {
32 public:
33 InstallTracker(content::BrowserContext* browser_context,
34 extensions::ExtensionPrefs* prefs);
35 ~InstallTracker() override;
37 static InstallTracker* Get(content::BrowserContext* context);
39 void AddObserver(InstallObserver* observer);
40 void RemoveObserver(InstallObserver* observer);
42 // If an install is currently in progress for |extension_id|, returns details
43 // of the installation. This instance retains ownership of the returned
44 // pointer. Returns NULL if the extension is not currently being installed.
45 const ActiveInstallData* GetActiveInstall(
46 const std::string& extension_id) const;
48 // Registers an install initiated by the user to allow checking of duplicate
49 // installs. Download of the extension has not necessarily started.
50 // RemoveActiveInstall() must be called when install is complete regardless of
51 // success or failure. Consider using ScopedActiveInstall rather than calling
52 // this directly.
53 void AddActiveInstall(const ActiveInstallData& install_data);
55 // Deregisters an active install.
56 void RemoveActiveInstall(const std::string& extension_id);
58 void OnBeginExtensionInstall(
59 const InstallObserver::ExtensionInstallParams& params);
60 void OnBeginExtensionDownload(const std::string& extension_id);
61 void OnDownloadProgress(const std::string& extension_id,
62 int percent_downloaded);
63 void OnBeginCrxInstall(const std::string& extension_id);
64 void OnFinishCrxInstall(const std::string& extension_id, bool success);
65 void OnInstallFailure(const std::string& extension_id);
67 // NOTE(limasdf): For extension [un]load and [un]installed, use
68 // ExtensionRegistryObserver.
70 // Overriddes for KeyedService.
71 void Shutdown() override;
73 private:
74 void OnAppsReordered();
76 // content::NotificationObserver implementation.
77 void Observe(int type,
78 const content::NotificationSource& source,
79 const content::NotificationDetails& details) override;
81 // ExtensionRegistryObserver implementation.
82 void OnExtensionInstalled(content::BrowserContext* browser_context,
83 const Extension* extension,
84 bool is_update) override;
86 // Maps extension id to the details of an active install.
87 typedef std::map<std::string, ActiveInstallData> ActiveInstallsMap;
88 ActiveInstallsMap active_installs_;
90 base::ObserverList<InstallObserver> observers_;
91 content::NotificationRegistrar registrar_;
92 PrefChangeRegistrar pref_change_registrar_;
93 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
94 extension_registry_observer_;
96 DISALLOW_COPY_AND_ASSIGN(InstallTracker);
99 } // namespace extensions
101 #endif // CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_