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 class LazyEventDispatchUtil : public ExtensionRegistryObserver { |
| 20 public: |
| 21 // Helps observer with events for lazy event dispatching. |
| 22 class Observer { |
| 23 public: |
| 24 // Called when an extension is loaded after installation, for one of the |
| 25 // following scenarios: |
| 26 // 1. New extension is installed. |
| 27 // 2. An extension is updated and loaded. |
| 28 // 3. An extension is enabled after it was disabled during an update. |
| 29 virtual void OnExtensionInstalledAndLoaded( |
| 30 content::BrowserContext* browser_context, |
| 31 const Extension* extension, |
| 32 const base::Version& old_version); |
| 33 }; |
| 34 |
| 35 explicit LazyEventDispatchUtil(content::BrowserContext* browser_context, |
| 36 ExtensionRegistry* extension_registry); |
| 37 ~LazyEventDispatchUtil() override; |
| 38 |
| 39 void AddObserver(Observer* observer); |
| 40 void RemoveObserver(Observer* observer); |
| 41 |
| 42 // ExtensionRegistryObserver:: |
| 43 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 44 const Extension* extension) override; |
| 45 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
| 46 const Extension* extension, |
| 47 bool is_update, |
| 48 const std::string& old_name) override; |
| 49 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 50 const Extension* extension, |
| 51 UninstallReason reason) override; |
| 52 |
| 53 private: |
| 54 bool ReadPendingOnInstallInfoFromPref(const ExtensionId& extension_id, |
| 55 base::Version* previous_version); |
| 56 void RemovePendingOnInstallInfoFromPref(const ExtensionId& extension_id); |
| 57 void StorePendingOnInstallInfoToPref(const Extension* extension); |
| 58 |
| 59 content::BrowserContext* browser_context_; |
| 60 base::ObserverList<Observer> observers_; |
| 61 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 62 extension_registry_observer_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(LazyEventDispatchUtil); |
| 65 }; |
| 66 |
| 67 } // namespace extensions |
| 68 |
| 69 #endif // EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCH_UTIL_H_ |
OLD | NEW |