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 { | |
Devlin
2017/06/05 15:38:38
class comments. In particular, it might be nice t
lazyboy
2017/06/05 21:54:01
Done.
| |
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 ~LazyEventDispatchUtil() override; | |
37 | |
38 void AddObserver(Observer* observer); | |
39 void RemoveObserver(Observer* observer); | |
40 | |
41 // ExtensionRegistryObserver: | |
42 void OnExtensionLoaded(content::BrowserContext* browser_context, | |
43 const Extension* extension) override; | |
44 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, | |
45 const Extension* extension, | |
46 bool is_update, | |
47 const std::string& old_name) override; | |
48 void OnExtensionUninstalled(content::BrowserContext* browser_context, | |
49 const Extension* extension, | |
50 UninstallReason reason) override; | |
51 | |
52 private: | |
53 bool ReadPendingOnInstallInfoFromPref(const ExtensionId& extension_id, | |
54 base::Version* previous_version); | |
55 void RemovePendingOnInstallInfoFromPref(const ExtensionId& extension_id); | |
56 void StorePendingOnInstallInfoToPref(const Extension* extension); | |
57 | |
58 content::BrowserContext* browser_context_; | |
59 base::ObserverList<Observer> observers_; | |
60 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | |
61 extension_registry_observer_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(LazyEventDispatchUtil); | |
64 }; | |
65 | |
66 } // namespace extensions | |
67 | |
68 #endif // EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCH_UTIL_H_ | |
OLD | NEW |