OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "extensions/browser/runtime_data.h" | |
6 | |
7 #include "extensions/browser/extension_registry.h" | |
8 #include "extensions/common/extension.h" | |
9 #include "extensions/common/manifest_handlers/background_info.h" | |
10 | |
11 namespace extensions { | |
12 | |
13 RuntimeData::RuntimeData(ExtensionRegistry* registry) : registry_(registry) { | |
14 if (registry_) | |
not at google - send to devlin
2014/01/22 16:17:43
when is there no registry? tests? can we fix that?
James Cook
2014/01/22 17:41:52
See the comment in the header - it was for tests.
| |
15 registry_->AddObserver(this); | |
16 } | |
17 | |
18 RuntimeData::~RuntimeData() { | |
19 if (registry_) | |
20 registry_->RemoveObserver(this); | |
21 } | |
22 | |
23 bool RuntimeData::IsBackgroundPageReady(const Extension* extension) const { | |
24 if (!BackgroundInfo::HasPersistentBackgroundPage(extension)) | |
25 return true; | |
26 return HasFlag(extension, BACKGROUND_PAGE_READY); | |
27 } | |
28 | |
29 void RuntimeData::SetBackgroundPageReady(const Extension* extension, | |
30 bool value) { | |
31 SetFlag(extension, BACKGROUND_PAGE_READY, value); | |
32 } | |
33 | |
34 bool RuntimeData::IsBeingUpgraded(const Extension* extension) const { | |
35 return HasFlag(extension, BEING_UPGRADED); | |
36 } | |
37 | |
38 void RuntimeData::SetBeingUpgraded(const Extension* extension, bool value) { | |
39 SetFlag(extension, BEING_UPGRADED, value); | |
40 } | |
41 | |
42 bool RuntimeData::HasUsedWebRequest(const Extension* extension) const { | |
43 return HasFlag(extension, HAS_USED_WEBREQUEST); | |
44 } | |
45 | |
46 void RuntimeData::SetHasUsedWebRequest(const Extension* extension, bool value) { | |
47 SetFlag(extension, HAS_USED_WEBREQUEST, value); | |
48 } | |
49 | |
50 void RuntimeData::OnExtensionUnloaded(const Extension* extension) { | |
51 extension_flags_.erase(extension->id()); | |
52 } | |
53 | |
54 void RuntimeData::OnExtensionDisabled(const Extension* extension) { | |
55 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) | |
56 SetBackgroundPageReady(extension, false); | |
57 } | |
58 | |
59 bool RuntimeData::HasExtensionForTesting(const Extension* extension) const { | |
60 return extension_flags_.find(extension->id()) != extension_flags_.end(); | |
61 } | |
62 | |
63 void RuntimeData::ClearAll() { | |
64 extension_flags_.clear(); | |
65 } | |
66 | |
67 bool RuntimeData::HasFlag(const Extension* extension, RuntimeFlag flag) const { | |
68 ExtensionFlagsMap::const_iterator it = extension_flags_.find(extension->id()); | |
69 if (it == extension_flags_.end()) | |
70 return false; | |
71 return static_cast<bool>(it->second & flag); | |
72 } | |
73 | |
74 void RuntimeData::SetFlag(const Extension* extension, | |
75 RuntimeFlag flag, | |
76 bool value) { | |
77 if (value) | |
78 extension_flags_[extension->id()] |= flag; | |
79 else | |
80 extension_flags_[extension->id()] &= ~flag; | |
81 } | |
82 | |
83 } // namespace extensions | |
OLD | NEW |