Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / runtime_data.h
blobc937a99f7f7cbed5f68c2fe2fcc385269401f3c9
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_RUNTIME_DATA_H_
6 #define EXTENSIONS_BROWSER_RUNTIME_DATA_H_
8 #include <map>
9 #include <string>
11 #include "base/compiler_specific.h"
12 #include "extensions/browser/extension_registry_observer.h"
14 namespace extensions {
16 class ExtensionRegistry;
18 // Contains per-extension data that can change during the life of the process,
19 // but does not persist across restarts. Shared between incognito and regular
20 // browser contexts. Lives on the UI thread. Must be destroyed before
21 // ExtensionRegistry.
22 // If we start putting to much into this, we should expose the generic
23 // "[G|S]etRuntimeProperty(const std::string& extension_id, RuntimeFlag flag)"
24 // instead of all these.
25 class RuntimeData : public ExtensionRegistryObserver {
26 public:
27 // Observes |registry| to clean itself up when extensions change state.
28 // |registry| must not be NULL.
29 explicit RuntimeData(ExtensionRegistry* registry);
30 ~RuntimeData() override;
32 // Whether the persistent background page, if any, is ready. We don't load
33 // other components until then. If there is no background page, or if it is
34 // non-persistent (lazy), we consider it to be ready.
35 bool IsBackgroundPageReady(const Extension* extension) const;
36 void SetBackgroundPageReady(const std::string& extension_id, bool value);
38 // Getter and setter for the flag that specifies whether the extension is
39 // being upgraded.
40 // For these purposes, a reload counts as an upgrade.
41 bool IsBeingUpgraded(const std::string& extension_id) const;
42 void SetBeingUpgraded(const std::string& extension_id, bool value);
44 // Getter and setter for the flag that specifies if the extension has used
45 // the webrequest API.
46 bool HasUsedWebRequest(const std::string& extension_id) const;
47 void SetHasUsedWebRequest(const std::string& extension_id, bool value);
49 // Returns true if the extension is being tracked. Used only for testing.
50 bool HasExtensionForTesting(const std::string& extension_id) const;
52 // Erase runtime data for all extensions. Used only for testing. Cannot be
53 // named ClearAllForTesting due to false-positive presubmit errors.
54 void ClearAll();
56 // ExtensionRegistryObserver overrides. Public for testing.
57 void OnExtensionUnloaded(content::BrowserContext* browser_context,
58 const Extension* extension,
59 UnloadedExtensionInfo::Reason reason) override;
61 private:
62 // Bitmasks for runtime states.
63 enum RuntimeFlag {
64 // Set if the background page is ready.
65 BACKGROUND_PAGE_READY = 1 << 0,
66 // Set while the extension is being upgraded.
67 BEING_UPGRADED = 1 << 1,
68 // Set if the extension has used the webRequest API.
69 HAS_USED_WEBREQUEST = 1 << 2,
72 // The mask of any data that should persist across the extension being
73 // unloaded.
74 static const int kPersistAcrossUnloadMask = BEING_UPGRADED;
76 // Returns the setting for the flag or false if the extension isn't found.
77 bool HasFlag(const std::string& extension_id, RuntimeFlag flag) const;
79 // Sets |flag| for |extension| to |value|. Adds |extension| to the list of
80 // extensions if it isn't present.
81 void SetFlag(const std::string& extension_id, RuntimeFlag flag, bool value);
83 // Map from extension ID to the RuntimeFlags bits.
84 typedef std::map<std::string, int> ExtensionFlagsMap;
85 ExtensionFlagsMap extension_flags_;
87 ExtensionRegistry* registry_; // Not owned.
90 } // namespace extensions
92 #endif // EXTENSIONS_BROWSER_RUNTIME_DATA_H_