summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-25 23:56:21 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-25 23:56:21 +0000
commitf6ebf0766ca2e0a39d0831dfda8e8fd755c8b722 (patch)
tree127c9821f7fa38c0d2af9e426cc50bfcd15abbf4 /chrome/common
parent9bd6dea63d941d24cec3197f44361e49a396d759 (diff)
downloadchromium_src-f6ebf0766ca2e0a39d0831dfda8e8fd755c8b722.zip
chromium_src-f6ebf0766ca2e0a39d0831dfda8e8fd755c8b722.tar.gz
chromium_src-f6ebf0766ca2e0a39d0831dfda8e8fd755c8b722.tar.bz2
Fix a memory leak in ExtensionExtentUnittest by fixing a bad
API design choice. BUG=47539,47545 Review URL: http://codereview.chromium.org/2870027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50912 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/extensions/extension_extent_unittest.cc6
-rw-r--r--chrome/common/extensions/url_pattern.cc19
-rw-r--r--chrome/common/extensions/url_pattern.h8
3 files changed, 17 insertions, 16 deletions
diff --git a/chrome/common/extensions/extension_extent_unittest.cc b/chrome/common/extensions/extension_extent_unittest.cc
index 41f2d15..509d83c 100644
--- a/chrome/common/extensions/extension_extent_unittest.cc
+++ b/chrome/common/extensions/extension_extent_unittest.cc
@@ -16,7 +16,7 @@ TEST(ExtensionExtentTest, Empty) {
TEST(ExtensionExtentTest, One) {
ExtensionExtent extent;
- extent.AddPattern(*URLPattern::CreateFromString("http://www.google.com/*"));
+ extent.AddPattern(URLPattern("http://www.google.com/*"));
EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/")));
EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey")));
@@ -26,8 +26,8 @@ TEST(ExtensionExtentTest, One) {
TEST(ExtensionExtentTest, Two) {
ExtensionExtent extent;
- extent.AddPattern(*URLPattern::CreateFromString("http://www.google.com/*"));
- extent.AddPattern(*URLPattern::CreateFromString("http://www.yahoo.com/*"));
+ extent.AddPattern(URLPattern("http://www.google.com/*"));
+ extent.AddPattern(URLPattern("http://www.yahoo.com/*"));
EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey")));
EXPECT_TRUE(extent.ContainsURL(GURL("http://www.yahoo.com/monkey")));
diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc
index 1aae528..41a5f6e 100644
--- a/chrome/common/extensions/url_pattern.cc
+++ b/chrome/common/extensions/url_pattern.cc
@@ -4,7 +4,6 @@
#include "chrome/common/extensions/url_pattern.h"
-#include "base/scoped_ptr.h"
#include "base/string_piece.h"
#include "base/string_util.h"
#include "chrome/common/url_constants.h"
@@ -22,15 +21,6 @@ static const char* kValidSchemes[] = {
static const char kPathSeparator[] = "/";
// static
-URLPattern* URLPattern::CreateFromString(const std::string& pattern_string) {
- scoped_ptr<URLPattern> pattern(new URLPattern);
- if (pattern->Parse(pattern_string))
- return pattern.release();
- else
- return NULL;
-}
-
-// static
bool URLPattern::IsValidScheme(const std::string& scheme) {
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
if (scheme == kValidSchemes[i])
@@ -40,6 +30,15 @@ bool URLPattern::IsValidScheme(const std::string& scheme) {
return false;
}
+URLPattern::URLPattern()
+ : match_subdomains_(false) {}
+
+URLPattern::URLPattern(const std::string& pattern)
+ : match_subdomains_(false) {
+ if (!Parse(pattern))
+ NOTREACHED() << "URLPattern is invalid: " << pattern;
+}
+
bool URLPattern::Parse(const std::string& pattern) {
size_t scheme_end_pos = pattern.find(chrome::kStandardSchemeSeparator);
if (scheme_end_pos == std::string::npos)
diff --git a/chrome/common/extensions/url_pattern.h b/chrome/common/extensions/url_pattern.h
index e25faaf..30f2c0f 100644
--- a/chrome/common/extensions/url_pattern.h
+++ b/chrome/common/extensions/url_pattern.h
@@ -73,10 +73,12 @@ class URLPattern {
// otherwise.
static bool IsValidScheme(const std::string& scheme);
- // Convenience to create a pattern from a string.
- static URLPattern* CreateFromString(const std::string& pattern);
+ URLPattern();
- URLPattern() : match_subdomains_(false) {}
+ // Convenience to construct a URLPattern from a string. The string is expected
+ // to be a valid pattern. If the string is not known ahead of time, use
+ // Parse() instead, which returns success or failure.
+ explicit URLPattern(const std::string& pattern);
// Initializes this instance by parsing the provided string. On failure, the
// instance will have some intermediate values and is in an invalid state.