summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-01 22:50:29 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-01 22:50:29 +0000
commitc64eb4096d30f3018ccd75d076fb90304f0143b7 (patch)
tree8bd88bcdcb25fb4dabb31935ea38283c3b9f7b0d /chrome/browser/extensions
parent829cb7a1163a73c410d0eb248f1d90116f390429 (diff)
downloadchromium_src-c64eb4096d30f3018ccd75d076fb90304f0143b7.zip
chromium_src-c64eb4096d30f3018ccd75d076fb90304f0143b7.tar.gz
chromium_src-c64eb4096d30f3018ccd75d076fb90304f0143b7.tar.bz2
Part 4/4 of immutable Extension refactor: Kill Extension::StaticData and put
its guts into Extension. BUG=56558 TEST=no functional change Review URL: http://codereview.chromium.org/4200005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64676 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_info_map.cc27
-rw-r--r--chrome/browser/extensions/extension_info_map.h9
-rw-r--r--chrome/browser/extensions/extension_info_map_unittest.cc50
3 files changed, 44 insertions, 42 deletions
diff --git a/chrome/browser/extensions/extension_info_map.cc b/chrome/browser/extensions/extension_info_map.cc
index f9f90aa..313e5737c 100644
--- a/chrome/browser/extensions/extension_info_map.cc
+++ b/chrome/browser/extensions/extension_info_map.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/extensions/extension_info_map.h"
#include "chrome/browser/browser_thread.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/url_constants.h"
namespace {
@@ -21,13 +22,13 @@ ExtensionInfoMap::ExtensionInfoMap() {
ExtensionInfoMap::~ExtensionInfoMap() {
}
-void ExtensionInfoMap::AddExtension(const Extension::StaticData* data) {
+void ExtensionInfoMap::AddExtension(const Extension* extension) {
CheckOnValidThread();
- extension_info_[data->id] = data;
+ extension_info_[extension->id()] = extension;
// Our map has already added a reference. Balance the reference given at the
// call-site.
- data->Release();
+ extension->Release();
}
void ExtensionInfoMap::RemoveExtension(const std::string& id) {
@@ -48,7 +49,7 @@ void ExtensionInfoMap::RemoveExtension(const std::string& id) {
std::string ExtensionInfoMap::GetNameForExtension(const std::string& id) const {
Map::const_iterator iter = extension_info_.find(id);
if (iter != extension_info_.end())
- return iter->second->name;
+ return iter->second->name();
else
return std::string();
}
@@ -56,21 +57,22 @@ std::string ExtensionInfoMap::GetNameForExtension(const std::string& id) const {
FilePath ExtensionInfoMap::GetPathForExtension(const std::string& id) const {
Map::const_iterator iter = extension_info_.find(id);
if (iter != extension_info_.end())
- return iter->second->path;
+ return iter->second->path();
else
return FilePath();
}
bool ExtensionInfoMap::ExtensionHasWebExtent(const std::string& id) const {
Map::const_iterator iter = extension_info_.find(id);
- return iter != extension_info_.end() && !iter->second->extent.is_empty();
+ return iter != extension_info_.end() &&
+ !iter->second->web_extent().is_empty();
}
bool ExtensionInfoMap::ExtensionCanLoadInIncognito(
const std::string& id) const {
Map::const_iterator iter = extension_info_.find(id);
// Only split-mode extensions can load in incognito profiles.
- return iter != extension_info_.end() && iter->second->incognito_split_mode;
+ return iter != extension_info_.end() && iter->second->incognito_split_mode();
}
std::string ExtensionInfoMap::GetDefaultLocaleForExtension(
@@ -78,7 +80,7 @@ std::string ExtensionInfoMap::GetDefaultLocaleForExtension(
Map::const_iterator iter = extension_info_.find(id);
std::string result;
if (iter != extension_info_.end())
- result = iter->second->default_locale;
+ result = iter->second->default_locale();
return result;
}
@@ -88,7 +90,7 @@ ExtensionExtent ExtensionInfoMap::GetEffectiveHostPermissionsForExtension(
Map::const_iterator iter = extension_info_.find(id);
ExtensionExtent result;
if (iter != extension_info_.end())
- result = iter->second->effective_host_permissions;
+ result = iter->second->GetEffectiveHostPermissions();
return result;
}
@@ -106,15 +108,14 @@ bool ExtensionInfoMap::CheckURLAccessToExtensionPermission(
// disallowed, so only one will match.
info = extension_info_.begin();
while (info != extension_info_.end() &&
- !info->second->extent.ContainsURL(url))
+ !info->second->web_extent().ContainsURL(url))
++info;
}
if (info == extension_info_.end())
return false;
- const std::set<std::string>& api_permissions = info->second->api_permissions;
- return api_permissions.count(permission_name) != 0;
+ return info->second->api_permissions().count(permission_name) != 0;
}
bool ExtensionInfoMap::URLIsForExtensionIcon(const GURL& url) const {
@@ -127,5 +128,5 @@ bool ExtensionInfoMap::URLIsForExtensionIcon(const GURL& url) const {
std::string path = url.path();
DCHECK(path.length() > 0 && path[0] == '/');
path = path.substr(1);
- return iter->second->icons.ContainsPath(path);
+ return iter->second->icons().ContainsPath(path);
}
diff --git a/chrome/browser/extensions/extension_info_map.h b/chrome/browser/extensions/extension_info_map.h
index fb03162..7d872ba 100644
--- a/chrome/browser/extensions/extension_info_map.h
+++ b/chrome/browser/extensions/extension_info_map.h
@@ -12,9 +12,11 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/ref_counted.h"
-#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_extent.h"
#include "googleurl/src/gurl.h"
+class Extension;
+
// Contains extension data that needs to be accessed on the IO thread. It can
// be created/destroyed on any thread, but all other methods must be called on
// the IO thread.
@@ -27,7 +29,7 @@ class ExtensionInfoMap : public base::RefCountedThreadSafe<ExtensionInfoMap> {
~ExtensionInfoMap();
// Callback for when new extensions are loaded.
- void AddExtension(const Extension::StaticData* data);
+ void AddExtension(const Extension* extension);
// Callback for when an extension is unloaded.
void RemoveExtension(const std::string& id);
@@ -63,8 +65,7 @@ class ExtensionInfoMap : public base::RefCountedThreadSafe<ExtensionInfoMap> {
private:
// Map of extension info by extension id.
- typedef std::map<std::string, scoped_refptr<const Extension::StaticData> >
- Map;
+ typedef std::map<std::string, scoped_refptr<const Extension> > Map;
Map extension_info_;
};
diff --git a/chrome/browser/extensions/extension_info_map_unittest.cc b/chrome/browser/extensions/extension_info_map_unittest.cc
index e417d23..d4892d1 100644
--- a/chrome/browser/extensions/extension_info_map_unittest.cc
+++ b/chrome/browser/extensions/extension_info_map_unittest.cc
@@ -7,6 +7,7 @@
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/extensions/extension_info_map.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/json_value_serializer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -73,37 +74,36 @@ static scoped_refptr<Extension> LoadManifest(const std::string& dir,
TEST_F(ExtensionInfoMapTest, RefCounting) {
scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
- // New extensions should have a single reference holding onto their static
- // data.
+ // New extensions should have a single reference holding onto them.
scoped_refptr<Extension> extension1(CreateExtension("extension1"));
scoped_refptr<Extension> extension2(CreateExtension("extension2"));
scoped_refptr<Extension> extension3(CreateExtension("extension3"));
- EXPECT_TRUE(extension1->static_data()->HasOneRef());
- EXPECT_TRUE(extension2->static_data()->HasOneRef());
- EXPECT_TRUE(extension3->static_data()->HasOneRef());
+ EXPECT_TRUE(extension1->HasOneRef());
+ EXPECT_TRUE(extension2->HasOneRef());
+ EXPECT_TRUE(extension3->HasOneRef());
// Add a ref to each extension and give it to the info map. The info map
// expects the caller to add a ref for it, but then assumes ownership of that
// reference.
- extension1->static_data()->AddRef();
- info_map->AddExtension(extension1->static_data());
- extension2->static_data()->AddRef();
- info_map->AddExtension(extension2->static_data());
- extension3->static_data()->AddRef();
- info_map->AddExtension(extension3->static_data());
-
- // Delete extension1, and the info map should have the only ref.
- const Extension::StaticData* data1 = extension1->static_data();
+ extension1->AddRef();
+ info_map->AddExtension(extension1);
+ extension2->AddRef();
+ info_map->AddExtension(extension2);
+ extension3->AddRef();
+ info_map->AddExtension(extension3);
+
+ // Release extension1, and the info map should have the only ref.
+ const Extension* weak_extension1 = extension1;
extension1 = NULL;
- EXPECT_TRUE(data1->HasOneRef());
+ EXPECT_TRUE(weak_extension1->HasOneRef());
// Remove extension2, and the extension2 object should have the only ref.
info_map->RemoveExtension(extension2->id());
- EXPECT_TRUE(extension2->static_data()->HasOneRef());
+ EXPECT_TRUE(extension2->HasOneRef());
// Delete the info map, and the extension3 object should have the only ref.
info_map = NULL;
- EXPECT_TRUE(extension3->static_data()->HasOneRef());
+ EXPECT_TRUE(extension3->HasOneRef());
}
// Tests that we can query a few extension properties from the ExtensionInfoMap.
@@ -113,10 +113,10 @@ TEST_F(ExtensionInfoMapTest, Properties) {
scoped_refptr<Extension> extension1(CreateExtension("extension1"));
scoped_refptr<Extension> extension2(CreateExtension("extension2"));
- extension1->static_data()->AddRef();
- info_map->AddExtension(extension1->static_data());
- extension2->static_data()->AddRef();
- info_map->AddExtension(extension2->static_data());
+ extension1->AddRef();
+ info_map->AddExtension(extension1);
+ extension2->AddRef();
+ info_map->AddExtension(extension2);
EXPECT_EQ(extension1->name(),
info_map->GetNameForExtension(extension1->id()));
@@ -142,10 +142,10 @@ TEST_F(ExtensionInfoMapTest, CheckPermissions) {
ASSERT_TRUE(app->is_app());
ASSERT_TRUE(app->web_extent().ContainsURL(app_url));
- app->static_data()->AddRef();
- info_map->AddExtension(app->static_data());
- extension->static_data()->AddRef();
- info_map->AddExtension(extension->static_data());
+ app->AddRef();
+ info_map->AddExtension(app);
+ extension->AddRef();
+ info_map->AddExtension(extension);
// The app should have the notifications permission, either from a
// chrome-extension URL or from its web extent.