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_API_DECLARATIVE_NET_REQUEST_RULES_MONITOR_H_ |
| 6 #define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_RULES_MONITOR_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/scoped_observer.h" |
| 10 #include "extensions/browser/extension_registry_observer.h" |
| 11 |
| 12 namespace content { |
| 13 class BrowserContext; |
| 14 } |
| 15 |
| 16 namespace base { |
| 17 class SequencedTaskRunner; |
| 18 } |
| 19 |
| 20 namespace extensions { |
| 21 class InfoMap; |
| 22 |
| 23 namespace declarative_net_request { |
| 24 |
| 25 // Lives on the UI thread. TODO take care of incognito. |
| 26 // Owned by ExtensionSystem. |
| 27 class RulesMonitor : public ExtensionRegistryObserver { |
| 28 public: |
| 29 // TODO if needed change to Profile. |
| 30 explicit RulesMonitor(content::BrowserContext* browser_context, |
| 31 base::SequencedTaskRunner* task_runner, |
| 32 InfoMap* info_map); |
| 33 ~RulesMonitor() override; |
| 34 |
| 35 private: |
| 36 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 37 const Extension* extension) override; |
| 38 |
| 39 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 40 const Extension* extension, |
| 41 UnloadedExtensionReason reason) override; |
| 42 |
| 43 // TODO listen to OnExtensionUninstalled to clear persisted ruleset for |
| 44 // unpacked extensions? Won't be needed for packed extensions since the |
| 45 // extension directory will be deleted. |
| 46 |
| 47 // TODO do we need to store browser context? |
| 48 content::BrowserContext* browser_context_; |
| 49 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 50 registry_observer_; |
| 51 |
| 52 // Weak. Owned by ExtensionService. The events above are propogated through |
| 53 // the ExtensionService, which means this weak reference is safe to use. |
| 54 base::SequencedTaskRunner* file_task_runner_; |
| 55 |
| 56 // Weak. Owned by ExtensionSystem, which also owns us. We use it in the |
| 57 // OnExtension* events, which means the ExtensionService hasn't been shut down |
| 58 // which means the ExtensionSystem hasn't been shutdown. Hence this is safe to |
| 59 // use. |
| 60 InfoMap* info_map_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(RulesMonitor); |
| 63 }; |
| 64 |
| 65 } // namespace declarative_net_request |
| 66 } // namespace extensions |
| 67 |
| 68 #endif // EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_RULES_MONITOR_H_ |
OLD | NEW |