diff options
author | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-09 17:34:20 +0000 |
---|---|---|
committer | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-09 17:34:20 +0000 |
commit | 38427a15feef46643bd5d85f56a6885fa2b7a976 (patch) | |
tree | 390eea7de7cfe3759c5fcc2170599ff2142c6a8d /extensions/browser/info_map.cc | |
parent | 56c953af6bb2be5fcc2eac19a0f227ca7ed594e0 (diff) | |
download | chromium_src-38427a15feef46643bd5d85f56a6885fa2b7a976.zip chromium_src-38427a15feef46643bd5d85f56a6885fa2b7a976.tar.gz chromium_src-38427a15feef46643bd5d85f56a6885fa2b7a976.tar.bz2 |
Moved ExtensionInfoMap and ExtensionsQuotaService to extensions/
In the move these classes became extensions::InfoMap and
extensions::QuotaService.
TBR=sky
BUG=162530
Review URL: https://codereview.chromium.org/63933003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser/info_map.cc')
-rw-r--r-- | extensions/browser/info_map.cc | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/extensions/browser/info_map.cc b/extensions/browser/info_map.cc new file mode 100644 index 0000000..a877ec9 --- /dev/null +++ b/extensions/browser/info_map.cc @@ -0,0 +1,181 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "extensions/browser/info_map.h" + +#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_set.h" +#include "content/public/browser/browser_thread.h" +#include "extensions/common/constants.h" +#include "extensions/common/manifest_handlers/incognito_info.h" + +using content::BrowserThread; + +namespace extensions { + +namespace { + +void CheckOnValidThread() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); +} + +} // namespace + +struct InfoMap::ExtraData { + // When the extension was installed. + base::Time install_time; + + // True if the user has allowed this extension to run in incognito mode. + bool incognito_enabled; + + ExtraData(); + ~ExtraData(); +}; + +InfoMap::ExtraData::ExtraData() : incognito_enabled(false) {} + +InfoMap::ExtraData::~ExtraData() {} + +InfoMap::InfoMap() : signin_process_id_(-1) {} + +const ProcessMap& InfoMap::process_map() const { return process_map_; } + +void InfoMap::AddExtension(const Extension* extension, + base::Time install_time, + bool incognito_enabled) { + CheckOnValidThread(); + extensions_.Insert(extension); + disabled_extensions_.Remove(extension->id()); + + extra_data_[extension->id()].install_time = install_time; + extra_data_[extension->id()].incognito_enabled = incognito_enabled; +} + +void InfoMap::RemoveExtension(const std::string& extension_id, + const UnloadedExtensionInfo::Reason reason) { + CheckOnValidThread(); + const Extension* extension = extensions_.GetByID(extension_id); + extra_data_.erase(extension_id); // we don't care about disabled extra data + bool was_uninstalled = (reason != UnloadedExtensionInfo::REASON_DISABLE && + reason != UnloadedExtensionInfo::REASON_TERMINATE); + if (extension) { + if (!was_uninstalled) + disabled_extensions_.Insert(extension); + extensions_.Remove(extension_id); + } else if (was_uninstalled) { + // If the extension was uninstalled, make sure it's removed from the map of + // disabled extensions. + disabled_extensions_.Remove(extension_id); + } else { + // NOTE: This can currently happen if we receive multiple unload + // notifications, e.g. setting incognito-enabled state for a + // disabled extension (e.g., via sync). See + // http://code.google.com/p/chromium/issues/detail?id=50582 . + NOTREACHED() << extension_id; + } +} + +base::Time InfoMap::GetInstallTime(const std::string& extension_id) const { + ExtraDataMap::const_iterator iter = extra_data_.find(extension_id); + if (iter != extra_data_.end()) + return iter->second.install_time; + return base::Time(); +} + +bool InfoMap::IsIncognitoEnabled(const std::string& extension_id) const { + // Keep in sync with duplicate in extension_process_manager.cc. + ExtraDataMap::const_iterator iter = extra_data_.find(extension_id); + if (iter != extra_data_.end()) + return iter->second.incognito_enabled; + return false; +} + +bool InfoMap::CanCrossIncognito(const Extension* extension) const { + // This is duplicated from ExtensionService :(. + return IsIncognitoEnabled(extension->id()) && + !IncognitoInfo::IsSplitMode(extension); +} + +void InfoMap::RegisterExtensionProcess(const std::string& extension_id, + int process_id, + int site_instance_id) { + if (!process_map_.Insert(extension_id, process_id, site_instance_id)) { + NOTREACHED() << "Duplicate extension process registration for: " + << extension_id << "," << process_id << "."; + } +} + +void InfoMap::UnregisterExtensionProcess(const std::string& extension_id, + int process_id, + int site_instance_id) { + if (!process_map_.Remove(extension_id, process_id, site_instance_id)) { + NOTREACHED() << "Unknown extension process registration for: " + << extension_id << "," << process_id << "."; + } +} + +void InfoMap::UnregisterAllExtensionsInProcess(int process_id) { + process_map_.RemoveAllFromProcess(process_id); +} + +void InfoMap::GetExtensionsWithAPIPermissionForSecurityOrigin( + const GURL& origin, + int process_id, + APIPermission::ID permission, + ExtensionSet* extensions) const { + DCHECK(extensions); + + if (origin.SchemeIs(kExtensionScheme)) { + const std::string& id = origin.host(); + const Extension* extension = extensions_.GetByID(id); + if (extension && extension->HasAPIPermission(permission) && + process_map_.Contains(id, process_id)) { + extensions->Insert(extension); + } + return; + } + + ExtensionSet::const_iterator i = extensions_.begin(); + for (; i != extensions_.end(); ++i) { + if ((*i)->web_extent().MatchesSecurityOrigin(origin) && + process_map_.Contains((*i)->id(), process_id) && + (*i)->HasAPIPermission(permission)) { + extensions->Insert(*i); + } + } +} + +bool InfoMap::SecurityOriginHasAPIPermission(const GURL& origin, + int process_id, + APIPermission::ID permission) + const { + ExtensionSet extensions; + GetExtensionsWithAPIPermissionForSecurityOrigin( + origin, process_id, permission, &extensions); + return !extensions.is_empty(); +} + +QuotaService* InfoMap::GetQuotaService() { + CheckOnValidThread(); + if (!quota_service_) + quota_service_.reset(new QuotaService()); + return quota_service_.get(); +} + +void InfoMap::SetSigninProcess(int process_id) { + signin_process_id_ = process_id; +} + +bool InfoMap::IsSigninProcess(int process_id) const { + return process_id == signin_process_id_; +} + +InfoMap::~InfoMap() { + if (quota_service_) { + BrowserThread::DeleteSoon( + BrowserThread::IO, FROM_HERE, quota_service_.release()); + } +} + +} // namespace extensions |