OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCH_UTIL_H_ |
| 6 #define EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCH_UTIL_H_ |
| 7 |
| 8 #include "base/observer_list.h" |
| 9 #include "base/scoped_observer.h" |
| 10 #include "extensions/browser/extension_registry_observer.h" |
| 11 #include "extensions/browser/uninstall_reason.h" |
| 12 |
| 13 namespace base { |
| 14 class Version; |
| 15 } |
| 16 |
| 17 namespace extensions { |
| 18 |
| 19 // Utility class to observe extension installation and loading related events |
| 20 // from lazy contexts. |
| 21 // |
| 22 // This class observes ExtensionRegistry and uses ExtensionPrefs to detect |
| 23 // whether an extension is loaded after (first time) installation or after an |
| 24 // update. |
| 25 class LazyEventDispatchUtil : public ExtensionRegistryObserver { |
| 26 public: |
| 27 // Helps observer with events for lazy event dispatching. |
| 28 class Observer { |
| 29 public: |
| 30 // Called when an extension is loaded after installation, for one of the |
| 31 // following scenarios: |
| 32 // 1. New extension is installed. |
| 33 // 2. An extension is updated and loaded. |
| 34 // 3. An extension is enabled after it was disabled during an update. |
| 35 virtual void OnExtensionInstalledAndLoaded( |
| 36 content::BrowserContext* browser_context, |
| 37 const Extension* extension, |
| 38 const base::Version& old_version) {} |
| 39 }; |
| 40 |
| 41 explicit LazyEventDispatchUtil(content::BrowserContext* browser_context); |
| 42 ~LazyEventDispatchUtil() override; |
| 43 |
| 44 void AddObserver(Observer* observer); |
| 45 void RemoveObserver(Observer* observer); |
| 46 |
| 47 // ExtensionRegistryObserver: |
| 48 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 49 const Extension* extension) override; |
| 50 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
| 51 const Extension* extension, |
| 52 bool is_update, |
| 53 const std::string& old_name) override; |
| 54 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 55 const Extension* extension, |
| 56 UninstallReason reason) override; |
| 57 |
| 58 private: |
| 59 bool ReadPendingOnInstallInfoFromPref(const ExtensionId& extension_id, |
| 60 base::Version* previous_version); |
| 61 void RemovePendingOnInstallInfoFromPref(const ExtensionId& extension_id); |
| 62 void StorePendingOnInstallInfoToPref(const Extension* extension); |
| 63 |
| 64 content::BrowserContext* browser_context_; |
| 65 base::ObserverList<Observer> observers_; |
| 66 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 67 extension_registry_observer_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(LazyEventDispatchUtil); |
| 70 }; |
| 71 |
| 72 } // namespace extensions |
| 73 |
| 74 #endif // EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCH_UTIL_H_ |
OLD | NEW |