blob: b273963ae8815a8f5204b19317558db3046de844 [file] [log] [blame]
[email protected]ef9d2742013-02-26 12:48:351// 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
[email protected]773272b2014-07-18 05:48:358#include <map>
9
avia2f4804a2015-12-24 23:11:1310#include "base/macros.h"
[email protected]ef9d2742013-02-26 12:48:3511#include "base/observer_list.h"
[email protected]773272b2014-07-18 05:48:3512#include "base/scoped_observer.h"
13#include "chrome/browser/extensions/active_install_data.h"
[email protected]ef9d2742013-02-26 12:48:3514#include "chrome/browser/extensions/install_observer.h"
[email protected]b33f0b112014-03-13 17:05:3015#include "components/keyed_service/core/keyed_service.h"
brettwb1fc1b82016-02-02 00:19:0816#include "components/prefs/pref_change_registrar.h"
[email protected]67e0a262013-03-15 13:14:4917#include "content/public/browser/notification_observer.h"
18#include "content/public/browser/notification_registrar.h"
Evan Stade75872a62019-09-06 21:17:3819#include "extensions/browser/extension_registry.h"
[email protected]773272b2014-07-18 05:48:3520#include "extensions/browser/extension_registry_observer.h"
[email protected]67e0a262013-03-15 13:14:4921
[email protected]90878c52014-04-04 18:21:0222namespace content {
23class BrowserContext;
24}
25
[email protected]ef9d2742013-02-26 12:48:3526namespace extensions {
27
[email protected]67e0a262013-03-15 13:14:4928class ExtensionPrefs;
29
[email protected]b33f0b112014-03-13 17:05:3030class InstallTracker : public KeyedService,
[email protected]773272b2014-07-18 05:48:3531 public content::NotificationObserver,
32 public ExtensionRegistryObserver {
[email protected]ef9d2742013-02-26 12:48:3533 public:
[email protected]6d6579a2014-07-30 14:24:1334 InstallTracker(content::BrowserContext* browser_context,
[email protected]67e0a262013-03-15 13:14:4935 extensions::ExtensionPrefs* prefs);
dchengae36a4a2014-10-21 12:36:3636 ~InstallTracker() override;
[email protected]ef9d2742013-02-26 12:48:3537
[email protected]90878c52014-04-04 18:21:0238 static InstallTracker* Get(content::BrowserContext* context);
39
[email protected]ef9d2742013-02-26 12:48:3540 void AddObserver(InstallObserver* observer);
41 void RemoveObserver(InstallObserver* observer);
42
[email protected]773272b2014-07-18 05:48:3543 // If an install is currently in progress for |extension_id|, returns details
44 // of the installation. This instance retains ownership of the returned
45 // pointer. Returns NULL if the extension is not currently being installed.
46 const ActiveInstallData* GetActiveInstall(
47 const std::string& extension_id) const;
48
49 // Registers an install initiated by the user to allow checking of duplicate
50 // installs. Download of the extension has not necessarily started.
51 // RemoveActiveInstall() must be called when install is complete regardless of
52 // success or failure. Consider using ScopedActiveInstall rather than calling
53 // this directly.
54 void AddActiveInstall(const ActiveInstallData& install_data);
55
56 // Deregisters an active install.
57 void RemoveActiveInstall(const std::string& extension_id);
58
[email protected]ef9d2742013-02-26 12:48:3559 void OnBeginExtensionInstall(
[email protected]fa517d02013-11-18 09:33:0960 const InstallObserver::ExtensionInstallParams& params);
[email protected]c80fe5f2014-03-26 04:36:3061 void OnBeginExtensionDownload(const std::string& extension_id);
[email protected]ef9d2742013-02-26 12:48:3562 void OnDownloadProgress(const std::string& extension_id,
63 int percent_downloaded);
[email protected]c80fe5f2014-03-26 04:36:3064 void OnBeginCrxInstall(const std::string& extension_id);
[email protected]73cd487c2014-04-16 05:22:5065 void OnFinishCrxInstall(const std::string& extension_id, bool success);
[email protected]ef9d2742013-02-26 12:48:3566 void OnInstallFailure(const std::string& extension_id);
67
[email protected]b8e45df2014-06-11 19:32:3668 // NOTE(limasdf): For extension [un]load and [un]installed, use
69 // ExtensionRegistryObserver.
70
[email protected]96ac5962014-04-22 19:49:5871 // Overriddes for KeyedService.
dchengae36a4a2014-10-21 12:36:3672 void Shutdown() override;
[email protected]523352c922013-02-28 01:38:5273
[email protected]ef9d2742013-02-26 12:48:3574 private:
[email protected]67e0a262013-03-15 13:14:4975 void OnAppsReordered();
76
[email protected]17f07822014-05-22 08:45:1577 // content::NotificationObserver implementation.
dchengae36a4a2014-10-21 12:36:3678 void Observe(int type,
79 const content::NotificationSource& source,
80 const content::NotificationDetails& details) override;
[email protected]96ac5962014-04-22 19:49:5881
[email protected]773272b2014-07-18 05:48:3582 // ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:3683 void OnExtensionInstalled(content::BrowserContext* browser_context,
84 const Extension* extension,
85 bool is_update) override;
[email protected]773272b2014-07-18 05:48:3586
87 // Maps extension id to the details of an active install.
88 typedef std::map<std::string, ActiveInstallData> ActiveInstallsMap;
89 ActiveInstallsMap active_installs_;
90
Trent Apteda250ec3ab2018-08-19 08:52:1991 base::ObserverList<InstallObserver>::Unchecked observers_;
[email protected]67e0a262013-03-15 13:14:4992 content::NotificationRegistrar registrar_;
93 PrefChangeRegistrar pref_change_registrar_;
[email protected]773272b2014-07-18 05:48:3594 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
Evan Stade75872a62019-09-06 21:17:3895 extension_registry_observer_{this};
[email protected]ef9d2742013-02-26 12:48:3596
[email protected]ef9d2742013-02-26 12:48:3597 DISALLOW_COPY_AND_ASSIGN(InstallTracker);
98};
99
100} // namespace extensions
101
102#endif // CHROME_BROWSER_EXTENSIONS_INSTALL_TRACKER_H_