diff options
author | mlerman <mlerman@chromium.org> | 2015-04-10 15:16:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-10 22:16:48 +0000 |
commit | 473f21ef56a6fa05bfe0afc79fe5893d3ae804b4 (patch) | |
tree | 7099a69c5259e431c013c8d0bc6b5e84fe638e3a /extensions/common/features | |
parent | f7bcefca8f834a41dc9b110c76276defe911bf8c (diff) | |
download | chromium_src-473f21ef56a6fa05bfe0afc79fe5893d3ae804b4.zip chromium_src-473f21ef56a6fa05bfe0afc79fe5893d3ae804b4.tar.gz chromium_src-473f21ef56a6fa05bfe0afc79fe5893d3ae804b4.tar.bz2 |
Revert of Cache --whitelisted-extension-id in SimpleFeature. (patchset #13 id:240001 of https://codereview.chromium.org/1047943002/)
Reason for revert:
https://code.google.com/p/chromium/issues/detail?id=476061
Causing consistent errors on a variety of memory bots in both InitValueManifestTest.InitFromValueInvalid and LauncherPageManifestTest.ValidLauncherPage tests.
Original issue's description:
> Cache --whitelisted-extension-id in SimpleFeature.
>
> During startup, CommandLine::HasSwitch(kWhitelistedExtensionID) is
> called ~1000 times by SimpleFeature. It is the most common switch
> lookup, the second being kAppsGalleryUpdateUrl at ~300 times.
>
> Caching this avoids allocating and copying the string each time.
>
> BUG=471976
>
> Committed: https://crrev.com/16ca320592ce7ef6cd36500da6e670cc645781cd
> Cr-Commit-Position: refs/heads/master@{#324583}
TBR=tapted@chromium.org,kalman@chromium.org,mfoltz@chromium.org,jackhou@chromium.org
BUG=471976
Review URL: https://codereview.chromium.org/1076393002
Cr-Commit-Position: refs/heads/master@{#324695}
Diffstat (limited to 'extensions/common/features')
-rw-r--r-- | extensions/common/features/simple_feature.cc | 47 | ||||
-rw-r--r-- | extensions/common/features/simple_feature.h | 12 |
2 files changed, 14 insertions, 45 deletions
diff --git a/extensions/common/features/simple_feature.cc b/extensions/common/features/simple_feature.cc index 3322fac..34258d4 100644 --- a/extensions/common/features/simple_feature.cc +++ b/extensions/common/features/simple_feature.cc @@ -11,7 +11,6 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/debug/alias.h" -#include "base/macros.h" #include "base/sha1.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" @@ -28,10 +27,6 @@ namespace extensions { namespace { -// A singleton copy of the --whitelisted-extension-id so that we don't need to -// copy it from the CommandLine each time. -std::string* g_whitelisted_extension_id = NULL; - Feature::Availability IsAvailableToManifestForBind( const std::string& extension_id, Manifest::Type type, @@ -224,33 +219,8 @@ bool IsCommandLineSwitchEnabled(const std::string& switch_name) { return false; } -bool IsWhitelistedForTest(const std::string& extension_id) { - // TODO(jackhou): Delete the commandline whitelisting mechanism. - // Since it is only used it tests, ideally it should not be set via the - // commandline. At the moment the commandline is used as a mechanism to pass - // the id to the renderer process. - if (!g_whitelisted_extension_id) { - g_whitelisted_extension_id = new std::string( - base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kWhitelistedExtensionID)); - } - return !g_whitelisted_extension_id->empty() && - *g_whitelisted_extension_id == extension_id; -} - } // namespace -SimpleFeature::ScopedWhitelistForTest::ScopedWhitelistForTest( - const std::string& id) - : previous_id_(g_whitelisted_extension_id) { - g_whitelisted_extension_id = new std::string(id); -} - -SimpleFeature::ScopedWhitelistForTest::~ScopedWhitelistForTest() { - delete g_whitelisted_extension_id; - g_whitelisted_extension_id = previous_id_; -} - struct SimpleFeature::Mappings { Mappings() { extension_types["extension"] = Manifest::TYPE_EXTENSION; @@ -390,9 +360,20 @@ Feature::Availability SimpleFeature::IsAvailableToManifest( if (component_extensions_auto_granted_ && location == Manifest::COMPONENT) return CreateAvailability(IS_AVAILABLE, type); - if (!whitelist_.empty() && !IsIdInWhitelist(extension_id) && - !IsWhitelistedForTest(extension_id)) { - return CreateAvailability(NOT_FOUND_IN_WHITELIST, type); + if (!whitelist_.empty()) { + if (!IsIdInWhitelist(extension_id)) { + // TODO(aa): This is gross. There should be a better way to test the + // whitelist. + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (!command_line->HasSwitch(switches::kWhitelistedExtensionID)) + return CreateAvailability(NOT_FOUND_IN_WHITELIST, type); + + std::string whitelist_switch_value = + base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kWhitelistedExtensionID); + if (extension_id != whitelist_switch_value) + return CreateAvailability(NOT_FOUND_IN_WHITELIST, type); + } } if (!MatchesManifestLocation(location)) diff --git a/extensions/common/features/simple_feature.h b/extensions/common/features/simple_feature.h index 5ec95cf..9d8c539 100644 --- a/extensions/common/features/simple_feature.h +++ b/extensions/common/features/simple_feature.h @@ -29,18 +29,6 @@ class SimpleFeatureTest; class SimpleFeature : public Feature { public: - // Used by tests to override the cached --whitelisted-extension-id. - class ScopedWhitelistForTest { - public: - explicit ScopedWhitelistForTest(const std::string& id); - ~ScopedWhitelistForTest(); - - private: - std::string* previous_id_; - - DISALLOW_COPY_AND_ASSIGN(ScopedWhitelistForTest); - }; - SimpleFeature(); ~SimpleFeature() override; |