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. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_MANAGER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_MANAGER_H_ 7 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" 14 15 namespace content { 16 class BrowserContext; 17 class NotificationDetails; 18 class NotificationSource; 19 } 20 21 namespace extensions { 22 class Extension; 23 class ExtensionRegistry; 24 class ExtensionPrefs; 25 class ExternalInstallError; 26 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(); 33 34 // Removes the global error, if one existed. 35 void RemoveExternalInstallError(); 36 37 // Returns true if there is a global error for an external install. 38 bool HasExternalInstallError() const; 39 40 // Checks if there are any new external extensions to notify the user about. 41 void UpdateExternalExtensionAlert(); 42 43 // Given a (presumably just-installed) extension id, mark that extension as 44 // acknowledged. 45 void AcknowledgeExternalExtension(const std::string& extension_id); 46 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; 50 51 // Returns the current install error, if one exists. 52 const ExternalInstallError* error() { return error_.get(); } 53 54 // Returns a mutable copy of the error for testing purposes. 55 ExternalInstallError* error_for_testing() { return error_.get(); } 56 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; 68 69 // content::NotificationObserver implementation. 70 virtual void Observe(int type, 71 const content::NotificationSource& source, 72 const content::NotificationDetails& details) OVERRIDE; 73 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); 78 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; 82 83 // The associated BrowserContext. 84 content::BrowserContext* browser_context_; 85 86 // Whether or not this is the first run for the profile. 87 bool is_first_run_; 88 89 // The associated ExtensionPrefs. 90 ExtensionPrefs* extension_prefs_; 91 92 // The current ExternalInstallError, if one exists. 93 scoped_ptr<ExternalInstallError> error_; 94 95 content::NotificationRegistrar registrar_; 96 97 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 98 extension_registry_observer_; 99 100 DISALLOW_COPY_AND_ASSIGN(ExternalInstallManager); 101 }; 102 103 } // namespace extensions 104 105 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_INSTALL_MANAGER_H_ 106