Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / extensions / external_install_manager.h
blobb491cd3a7517608264cc7529acf3b5f9fc34a167
1 // Copyright 2014 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_EXTERNAL_INSTALL_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_MANAGER_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/scoped_observer.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "extensions/browser/extension_registry_observer.h"
15 namespace content {
16 class BrowserContext;
17 class NotificationDetails;
18 class NotificationSource;
21 namespace extensions {
22 class Extension;
23 class ExtensionRegistry;
24 class ExtensionPrefs;
25 class ExternalInstallError;
27 class ExternalInstallManager : public ExtensionRegistryObserver,
28 public content::NotificationObserver {
29 public:
30 ExternalInstallManager(content::BrowserContext* browser_context,
31 bool is_first_run);
32 virtual ~ExternalInstallManager();
34 // Removes the global error, if one existed.
35 void RemoveExternalInstallError();
37 // Returns true if there is a global error for an external install.
38 bool HasExternalInstallError() const;
40 // Checks if there are any new external extensions to notify the user about.
41 void UpdateExternalExtensionAlert();
43 // Given a (presumably just-installed) extension id, mark that extension as
44 // acknowledged.
45 void AcknowledgeExternalExtension(const std::string& extension_id);
47 // Returns true if there is a global error with a bubble view for an external
48 // install. Used for testing.
49 bool HasExternalInstallBubbleForTesting() const;
51 // Returns the current install error, if one exists.
52 const ExternalInstallError* error() { return error_.get(); }
54 // Returns a mutable copy of the error for testing purposes.
55 ExternalInstallError* error_for_testing() { return error_.get(); }
57 private:
58 // ExtensionRegistryObserver implementation.
59 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
60 const Extension* extension) override;
61 virtual void OnExtensionInstalled(content::BrowserContext* browser_context,
62 const Extension* extension,
63 bool is_update) override;
64 virtual void OnExtensionUninstalled(
65 content::BrowserContext* browser_context,
66 const Extension* extension,
67 extensions::UninstallReason reason) override;
69 // content::NotificationObserver implementation.
70 virtual void Observe(int type,
71 const content::NotificationSource& source,
72 const content::NotificationDetails& details) override;
74 // Adds a global error informing the user that an external extension was
75 // installed. If |is_new_profile| is true, then this error is from the first
76 // time our profile checked for new extensions.
77 void AddExternalInstallError(const Extension* extension, bool is_new_profile);
79 // Returns true if this extension is an external one that has yet to be
80 // marked as acknowledged.
81 bool IsUnacknowledgedExternalExtension(const Extension* extension) const;
83 // The associated BrowserContext.
84 content::BrowserContext* browser_context_;
86 // Whether or not this is the first run for the profile.
87 bool is_first_run_;
89 // The associated ExtensionPrefs.
90 ExtensionPrefs* extension_prefs_;
92 // The current ExternalInstallError, if one exists.
93 scoped_ptr<ExternalInstallError> error_;
95 content::NotificationRegistrar registrar_;
97 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
98 extension_registry_observer_;
100 DISALLOW_COPY_AND_ASSIGN(ExternalInstallManager);
103 } // namespace extensions
105 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_MANAGER_H_