| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_BROWSER_RUNTIME_DATA_H_ | 5 #ifndef EXTENSIONS_BROWSER_RUNTIME_DATA_H_ |
| 6 #define EXTENSIONS_BROWSER_RUNTIME_DATA_H_ | 6 #define EXTENSIONS_BROWSER_RUNTIME_DATA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "extensions/browser/extension_registry_observer.h" | 12 #include "extensions/browser/extension_registry_observer.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 class Extension; | 16 class Extension; |
| 17 class ExtensionRegistry; | 17 class ExtensionRegistry; |
| 18 | 18 |
| 19 // Contains per-extension data that can change during the life of the process, | 19 // Contains per-extension data that can change during the life of the process, |
| 20 // but does not persist across restarts. Shared between incognito and regular | 20 // but does not persist across restarts. Shared between incognito and regular |
| 21 // browser contexts. Lives on the UI thread. Must be destroyed before | 21 // browser contexts. Lives on the UI thread. Must be destroyed before |
| 22 // ExtensionRegistry. | 22 // ExtensionRegistry. |
| 23 class RuntimeData : public ExtensionRegistryObserver { | 23 class RuntimeData : public ExtensionRegistryObserver { |
| 24 public: | 24 public: |
| 25 // Observes |registry| to clean itself up when extensions change state. | 25 // Observes |registry| to clean itself up when extensions change state. |
| 26 // |registry| must not be NULL. | 26 // |registry| must not be NULL. |
| 27 explicit RuntimeData(ExtensionRegistry* registry); | 27 explicit RuntimeData(ExtensionRegistry* registry); |
| 28 virtual ~RuntimeData(); | 28 ~RuntimeData() override; |
| 29 | 29 |
| 30 // Whether the persistent background page, if any, is ready. We don't load | 30 // Whether the persistent background page, if any, is ready. We don't load |
| 31 // other components until then. If there is no background page, or if it is | 31 // other components until then. If there is no background page, or if it is |
| 32 // non-persistent (lazy), we consider it to be ready. | 32 // non-persistent (lazy), we consider it to be ready. |
| 33 bool IsBackgroundPageReady(const Extension* extension) const; | 33 bool IsBackgroundPageReady(const Extension* extension) const; |
| 34 void SetBackgroundPageReady(const Extension* extension, bool value); | 34 void SetBackgroundPageReady(const Extension* extension, bool value); |
| 35 | 35 |
| 36 // Getter and setter for the flag that specifies whether the extension is | 36 // Getter and setter for the flag that specifies whether the extension is |
| 37 // being upgraded. | 37 // being upgraded. |
| 38 bool IsBeingUpgraded(const Extension* extension) const; | 38 bool IsBeingUpgraded(const Extension* extension) const; |
| 39 void SetBeingUpgraded(const Extension* extension, bool value); | 39 void SetBeingUpgraded(const Extension* extension, bool value); |
| 40 | 40 |
| 41 // Getter and setter for the flag that specifies if the extension has used | 41 // Getter and setter for the flag that specifies if the extension has used |
| 42 // the webrequest API. | 42 // the webrequest API. |
| 43 bool HasUsedWebRequest(const Extension* extension) const; | 43 bool HasUsedWebRequest(const Extension* extension) const; |
| 44 void SetHasUsedWebRequest(const Extension* extension, bool value); | 44 void SetHasUsedWebRequest(const Extension* extension, bool value); |
| 45 | 45 |
| 46 // Returns true if the extension is being tracked. Used only for testing. | 46 // Returns true if the extension is being tracked. Used only for testing. |
| 47 bool HasExtensionForTesting(const Extension* extension) const; | 47 bool HasExtensionForTesting(const Extension* extension) const; |
| 48 | 48 |
| 49 // Erase runtime data for all extensions. Used only for testing. Cannot be | 49 // Erase runtime data for all extensions. Used only for testing. Cannot be |
| 50 // named ClearAllForTesting due to false-positive presubmit errors. | 50 // named ClearAllForTesting due to false-positive presubmit errors. |
| 51 void ClearAll(); | 51 void ClearAll(); |
| 52 | 52 |
| 53 // ExtensionRegistryObserver overrides. Public for testing. | 53 // ExtensionRegistryObserver overrides. Public for testing. |
| 54 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, | 54 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 55 const Extension* extension, | 55 const Extension* extension, |
| 56 UnloadedExtensionInfo::Reason reason) | 56 UnloadedExtensionInfo::Reason reason) override; |
| 57 override; | |
| 58 | 57 |
| 59 private: | 58 private: |
| 60 // Bitmasks for runtime states. | 59 // Bitmasks for runtime states. |
| 61 enum RuntimeFlag { | 60 enum RuntimeFlag { |
| 62 // Set if the background page is ready. | 61 // Set if the background page is ready. |
| 63 BACKGROUND_PAGE_READY = 1 << 0, | 62 BACKGROUND_PAGE_READY = 1 << 0, |
| 64 // Set while the extension is being upgraded. | 63 // Set while the extension is being upgraded. |
| 65 BEING_UPGRADED = 1 << 1, | 64 BEING_UPGRADED = 1 << 1, |
| 66 // Set if the extension has used the webRequest API. | 65 // Set if the extension has used the webRequest API. |
| 67 HAS_USED_WEBREQUEST = 1 << 2, | 66 HAS_USED_WEBREQUEST = 1 << 2, |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 // Returns the setting for the flag or false if the extension isn't found. | 69 // Returns the setting for the flag or false if the extension isn't found. |
| 71 bool HasFlag(const Extension* extension, RuntimeFlag flag) const; | 70 bool HasFlag(const Extension* extension, RuntimeFlag flag) const; |
| 72 | 71 |
| 73 // Sets |flag| for |extension| to |value|. Adds |extension| to the list of | 72 // Sets |flag| for |extension| to |value|. Adds |extension| to the list of |
| 74 // extensions if it isn't present. | 73 // extensions if it isn't present. |
| 75 void SetFlag(const Extension* extension, RuntimeFlag flag, bool value); | 74 void SetFlag(const Extension* extension, RuntimeFlag flag, bool value); |
| 76 | 75 |
| 77 // Map from extension ID to the RuntimeFlags bits. | 76 // Map from extension ID to the RuntimeFlags bits. |
| 78 typedef std::map<std::string, int> ExtensionFlagsMap; | 77 typedef std::map<std::string, int> ExtensionFlagsMap; |
| 79 ExtensionFlagsMap extension_flags_; | 78 ExtensionFlagsMap extension_flags_; |
| 80 | 79 |
| 81 ExtensionRegistry* registry_; // Not owned. | 80 ExtensionRegistry* registry_; // Not owned. |
| 82 }; | 81 }; |
| 83 | 82 |
| 84 } // namespace extensions | 83 } // namespace extensions |
| 85 | 84 |
| 86 #endif // EXTENSIONS_BROWSER_RUNTIME_DATA_H_ | 85 #endif // EXTENSIONS_BROWSER_RUNTIME_DATA_H_ |
| OLD | NEW |