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 registry_->AddObserver(this); |
| 15 } |
| 16 |
| 17 RuntimeData::~RuntimeData() { |
| 18 registry_->RemoveObserver(this); |
| 19 } |
| 20 |
| 21 bool RuntimeData::IsBackgroundPageReady(const Extension* extension) const { |
| 22 if (!BackgroundInfo::HasPersistentBackgroundPage(extension)) |
| 23 return true; |
| 24 return HasFlag(extension, BACKGROUND_PAGE_READY); |
| 25 } |
| 26 |
| 27 void RuntimeData::SetBackgroundPageReady(const Extension* extension, |
| 28 bool value) { |
| 29 SetFlag(extension, BACKGROUND_PAGE_READY, value); |
| 30 } |
| 31 |
| 32 bool RuntimeData::IsBeingUpgraded(const Extension* extension) const { |
| 33 return HasFlag(extension, BEING_UPGRADED); |
| 34 } |
| 35 |
| 36 void RuntimeData::SetBeingUpgraded(const Extension* extension, bool value) { |
| 37 SetFlag(extension, BEING_UPGRADED, value); |
| 38 } |
| 39 |
| 40 bool RuntimeData::HasUsedWebRequest(const Extension* extension) const { |
| 41 return HasFlag(extension, HAS_USED_WEBREQUEST); |
| 42 } |
| 43 |
| 44 void RuntimeData::SetHasUsedWebRequest(const Extension* extension, bool value) { |
| 45 SetFlag(extension, HAS_USED_WEBREQUEST, value); |
| 46 } |
| 47 |
| 48 bool RuntimeData::HasExtensionForTesting(const Extension* extension) const { |
| 49 return extension_flags_.find(extension->id()) != extension_flags_.end(); |
| 50 } |
| 51 |
| 52 void RuntimeData::ClearAll() { |
| 53 extension_flags_.clear(); |
| 54 } |
| 55 |
| 56 void RuntimeData::OnExtensionUnloaded(const Extension* extension) { |
| 57 extension_flags_.erase(extension->id()); |
| 58 } |
| 59 |
| 60 bool RuntimeData::HasFlag(const Extension* extension, RuntimeFlag flag) const { |
| 61 ExtensionFlagsMap::const_iterator it = extension_flags_.find(extension->id()); |
| 62 if (it == extension_flags_.end()) |
| 63 return false; |
| 64 return !!(it->second & flag); |
| 65 } |
| 66 |
| 67 void RuntimeData::SetFlag(const Extension* extension, |
| 68 RuntimeFlag flag, |
| 69 bool value) { |
| 70 if (value) |
| 71 extension_flags_[extension->id()] |= flag; |
| 72 else |
| 73 extension_flags_[extension->id()] &= ~flag; |
| 74 } |
| 75 |
| 76 } // namespace extensions |
OLD | NEW |