Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: extensions/common/features/simple_feature.cc

Issue 1047943002: Cache --whitelisted-extension-id in SimpleFeature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/common/features/simple_feature.cc
diff --git a/extensions/common/features/simple_feature.cc b/extensions/common/features/simple_feature.cc
index 6a5bece485df46b7ccc9db8ef21c5d62a521ba93..15fd4776664169a5b2f9ed7b60ac6e71ffdce303 100644
--- a/extensions/common/features/simple_feature.cc
+++ b/extensions/common/features/simple_feature.cc
@@ -11,6 +11,7 @@
#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"
@@ -222,6 +223,17 @@ bool IsCommandLineSwitchEnabled(const std::string& switch_name) {
return false;
}
+bool IsWhitelistedByCommandLine(const std::string& extension_id) {
+ // A singleton copy of the --whitelisted-extension-id so that we don't need to
+ // copy it from the CommandLine each time.
+ CR_DEFINE_STATIC_LOCAL(
+ std::string, whitelisted_extension_id,
+ (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
not at google - send to devlin 2015/03/31 17:16:05 why are the parens around the base::CommandLine...
jackhou1 2015/03/31 21:53:41 The macro is just: #define CR_DEFINE_STATIC_LOCAL(
not at google - send to devlin 2015/03/31 22:10:04 Well, that's silly. Macros are supposed to put par
jackhou1 2015/03/31 22:19:18 Yeah probably, looks like it was originally copied
+ switches::kWhitelistedExtensionID)));
+ return !whitelisted_extension_id.empty() &&
+ whitelisted_extension_id == extension_id;
+}
+
} // namespace
struct SimpleFeature::Mappings {
@@ -363,20 +375,9 @@ Feature::Availability SimpleFeature::IsAvailableToManifest(
if (component_extensions_auto_granted_ && location == Manifest::COMPONENT)
return CreateAvailability(IS_AVAILABLE, 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 (!whitelist_.empty() && !IsIdInWhitelist(extension_id) &&
+ !IsWhitelistedByCommandLine(extension_id)) {
+ return CreateAvailability(NOT_FOUND_IN_WHITELIST, type);
}
if (!MatchesManifestLocation(location))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698