Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / extensions / browser / runtime_data.cc
blob3cee8466d5983d2da0dc9c733ec4d60c282ff309
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 #include "extensions/browser/runtime_data.h"
7 #include "extensions/browser/extension_registry.h"
8 #include "extensions/common/extension.h"
9 #include "extensions/common/manifest_handlers/background_info.h"
11 namespace extensions {
13 RuntimeData::RuntimeData(ExtensionRegistry* registry) : registry_(registry) {
14 registry_->AddObserver(this);
17 RuntimeData::~RuntimeData() {
18 registry_->RemoveObserver(this);
21 bool RuntimeData::IsBackgroundPageReady(const Extension* extension) const {
22 if (!BackgroundInfo::HasPersistentBackgroundPage(extension))
23 return true;
24 return HasFlag(extension->id(), BACKGROUND_PAGE_READY);
27 void RuntimeData::SetBackgroundPageReady(const std::string& extension_id,
28 bool value) {
29 SetFlag(extension_id, BACKGROUND_PAGE_READY, value);
32 bool RuntimeData::IsBeingUpgraded(const std::string& extension_id) const {
33 return HasFlag(extension_id, BEING_UPGRADED);
36 void RuntimeData::SetBeingUpgraded(const std::string& extension_id,
37 bool value) {
38 SetFlag(extension_id, BEING_UPGRADED, value);
41 bool RuntimeData::HasUsedWebRequest(const std::string& extension_id) const {
42 return HasFlag(extension_id, HAS_USED_WEBREQUEST);
45 void RuntimeData::SetHasUsedWebRequest(const std::string& extension_id,
46 bool value) {
47 SetFlag(extension_id, HAS_USED_WEBREQUEST, value);
50 bool RuntimeData::HasExtensionForTesting(
51 const std::string& extension_id) const {
52 return extension_flags_.find(extension_id) != extension_flags_.end();
55 void RuntimeData::ClearAll() {
56 extension_flags_.clear();
59 void RuntimeData::OnExtensionUnloaded(content::BrowserContext* browser_context,
60 const Extension* extension,
61 UnloadedExtensionInfo::Reason reason) {
62 ExtensionFlagsMap::iterator iter = extension_flags_.find(extension->id());
63 if (iter != extension_flags_.end())
64 iter->second = iter->second & kPersistAcrossUnloadMask;
67 bool RuntimeData::HasFlag(const std::string& extension_id,
68 RuntimeFlag flag) const {
69 ExtensionFlagsMap::const_iterator it = extension_flags_.find(extension_id);
70 if (it == extension_flags_.end())
71 return false;
72 return !!(it->second & flag);
75 void RuntimeData::SetFlag(const std::string& extension_id,
76 RuntimeFlag flag,
77 bool value) {
78 if (value)
79 extension_flags_[extension_id] |= flag;
80 else
81 extension_flags_[extension_id] &= ~flag;
84 } // namespace extensions