blob: 3cee8466d5983d2da0dc9c733ec4d60c282ff309 [file] [log] [blame]
[email protected]45f5b7d2014-01-22 23:47:131// 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
11namespace extensions {
12
13RuntimeData::RuntimeData(ExtensionRegistry* registry) : registry_(registry) {
14 registry_->AddObserver(this);
15}
16
17RuntimeData::~RuntimeData() {
18 registry_->RemoveObserver(this);
19}
20
21bool RuntimeData::IsBackgroundPageReady(const Extension* extension) const {
22 if (!BackgroundInfo::HasPersistentBackgroundPage(extension))
23 return true;
rdevlin.cronin2c16c602014-11-21 01:35:4924 return HasFlag(extension->id(), BACKGROUND_PAGE_READY);
[email protected]45f5b7d2014-01-22 23:47:1325}
26
rdevlin.cronin2c16c602014-11-21 01:35:4927void RuntimeData::SetBackgroundPageReady(const std::string& extension_id,
[email protected]45f5b7d2014-01-22 23:47:1328 bool value) {
rdevlin.cronin2c16c602014-11-21 01:35:4929 SetFlag(extension_id, BACKGROUND_PAGE_READY, value);
[email protected]45f5b7d2014-01-22 23:47:1330}
31
rdevlin.cronin2c16c602014-11-21 01:35:4932bool RuntimeData::IsBeingUpgraded(const std::string& extension_id) const {
33 return HasFlag(extension_id, BEING_UPGRADED);
[email protected]45f5b7d2014-01-22 23:47:1334}
35
rdevlin.cronin2c16c602014-11-21 01:35:4936void RuntimeData::SetBeingUpgraded(const std::string& extension_id,
37 bool value) {
38 SetFlag(extension_id, BEING_UPGRADED, value);
[email protected]45f5b7d2014-01-22 23:47:1339}
40
rdevlin.cronin2c16c602014-11-21 01:35:4941bool RuntimeData::HasUsedWebRequest(const std::string& extension_id) const {
42 return HasFlag(extension_id, HAS_USED_WEBREQUEST);
[email protected]45f5b7d2014-01-22 23:47:1343}
44
rdevlin.cronin2c16c602014-11-21 01:35:4945void RuntimeData::SetHasUsedWebRequest(const std::string& extension_id,
46 bool value) {
47 SetFlag(extension_id, HAS_USED_WEBREQUEST, value);
[email protected]45f5b7d2014-01-22 23:47:1348}
49
rdevlin.cronin2c16c602014-11-21 01:35:4950bool RuntimeData::HasExtensionForTesting(
51 const std::string& extension_id) const {
52 return extension_flags_.find(extension_id) != extension_flags_.end();
[email protected]45f5b7d2014-01-22 23:47:1353}
54
55void RuntimeData::ClearAll() {
56 extension_flags_.clear();
57}
58
[email protected]e51232f32014-04-18 20:05:3659void RuntimeData::OnExtensionUnloaded(content::BrowserContext* browser_context,
60 const Extension* extension,
61 UnloadedExtensionInfo::Reason reason) {
rdevlin.cronin2c16c602014-11-21 01:35:4962 ExtensionFlagsMap::iterator iter = extension_flags_.find(extension->id());
63 if (iter != extension_flags_.end())
64 iter->second = iter->second & kPersistAcrossUnloadMask;
[email protected]45f5b7d2014-01-22 23:47:1365}
66
rdevlin.cronin2c16c602014-11-21 01:35:4967bool RuntimeData::HasFlag(const std::string& extension_id,
68 RuntimeFlag flag) const {
69 ExtensionFlagsMap::const_iterator it = extension_flags_.find(extension_id);
[email protected]45f5b7d2014-01-22 23:47:1370 if (it == extension_flags_.end())
71 return false;
72 return !!(it->second & flag);
73}
74
rdevlin.cronin2c16c602014-11-21 01:35:4975void RuntimeData::SetFlag(const std::string& extension_id,
[email protected]45f5b7d2014-01-22 23:47:1376 RuntimeFlag flag,
77 bool value) {
78 if (value)
rdevlin.cronin2c16c602014-11-21 01:35:4979 extension_flags_[extension_id] |= flag;
[email protected]45f5b7d2014-01-22 23:47:1380 else
rdevlin.cronin2c16c602014-11-21 01:35:4981 extension_flags_[extension_id] &= ~flag;
[email protected]45f5b7d2014-01-22 23:47:1382}
83
84} // namespace extensions