diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-22 21:20:31 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-22 21:20:31 +0000 |
commit | e05d81f7b7bd8867baab724ff7ef674817d5b9d9 (patch) | |
tree | ff72304e975da1db5f9b1cc622b1e3af1220f391 /url | |
parent | 891d9c79bfaf4a9730389a7cd81df0a7d5697bb0 (diff) | |
download | chromium_src-e05d81f7b7bd8867baab724ff7ef674817d5b9d9.zip chromium_src-e05d81f7b7bd8867baab724ff7ef674817d5b9d9.tar.gz chromium_src-e05d81f7b7bd8867baab724ff7ef674817d5b9d9.tar.bz2 |
Make GURL use scoped_ptr for inner_url_
BUG=309975
R=brettw@chromium.org, darin@chromium.org
Review URL: https://codereview.chromium.org/34843004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'url')
-rw-r--r-- | url/gurl.cc | 58 | ||||
-rw-r--r-- | url/gurl.h | 5 |
2 files changed, 32 insertions, 31 deletions
diff --git a/url/gurl.cc b/url/gurl.cc index 7997d22..559b386 100644 --- a/url/gurl.cc +++ b/url/gurl.cc @@ -80,33 +80,34 @@ const std::string& EmptyStringForGURL() { } // namespace -GURL::GURL() : is_valid_(false), inner_url_(NULL) { +GURL::GURL() : is_valid_(false) { } GURL::GURL(const GURL& other) : spec_(other.spec_), is_valid_(other.is_valid_), - parsed_(other.parsed_), - inner_url_(NULL) { + parsed_(other.parsed_) { if (other.inner_url_) - inner_url_ = new GURL(*other.inner_url_); + inner_url_.reset(new GURL(*other.inner_url_)); // Valid filesystem urls should always have an inner_url_. DCHECK(!is_valid_ || !SchemeIsFileSystem() || inner_url_); } -GURL::GURL(const std::string& url_string) : inner_url_(NULL) { +GURL::GURL(const std::string& url_string) { is_valid_ = InitCanonical(url_string, &spec_, &parsed_); if (is_valid_ && SchemeIsFileSystem()) { - inner_url_ = - new GURL(spec_.data(), parsed_.Length(), *parsed_.inner_parsed(), true); + inner_url_.reset( + new GURL(spec_.data(), parsed_.Length(), + *parsed_.inner_parsed(), true)); } } -GURL::GURL(const base::string16& url_string) : inner_url_(NULL) { +GURL::GURL(const base::string16& url_string) { is_valid_ = InitCanonical(url_string, &spec_, &parsed_); if (is_valid_ && SchemeIsFileSystem()) { - inner_url_ = - new GURL(spec_.data(), parsed_.Length(), *parsed_.inner_parsed(), true); + inner_url_.reset( + new GURL(spec_.data(), parsed_.Length(), + *parsed_.inner_parsed(), true)); } } @@ -114,24 +115,23 @@ GURL::GURL(const char* canonical_spec, size_t canonical_spec_len, const url_parse::Parsed& parsed, bool is_valid) : spec_(canonical_spec, canonical_spec_len), is_valid_(is_valid), - parsed_(parsed), - inner_url_(NULL) { + parsed_(parsed) { InitializeFromCanonicalSpec(); } GURL::GURL(std::string canonical_spec, const url_parse::Parsed& parsed, bool is_valid) : is_valid_(is_valid), - parsed_(parsed), - inner_url_(NULL) { + parsed_(parsed) { spec_.swap(canonical_spec); InitializeFromCanonicalSpec(); } void GURL::InitializeFromCanonicalSpec() { if (is_valid_ && SchemeIsFileSystem()) { - inner_url_ = - new GURL(spec_.data(), parsed_.Length(), *parsed_.inner_parsed(), true); + inner_url_.reset( + new GURL(spec_.data(), parsed_.Length(), + *parsed_.inner_parsed(), true)); } #ifndef NDEBUG @@ -165,7 +165,6 @@ void GURL::InitializeFromCanonicalSpec() { } GURL::~GURL() { - delete inner_url_; } GURL& GURL::operator=(const GURL& other) { @@ -175,10 +174,9 @@ GURL& GURL::operator=(const GURL& other) { spec_ = other.spec_; is_valid_ = other.is_valid_; parsed_ = other.parsed_; - delete inner_url_; - inner_url_ = NULL; + inner_url_.reset(NULL); if (other.inner_url_) - inner_url_ = new GURL(*other.inner_url_); + inner_url_.reset(new GURL(*other.inner_url_)); // Valid filesystem urls should always have an inner_url_. DCHECK(!is_valid_ || !SchemeIsFileSystem() || inner_url_); return *this; @@ -225,8 +223,9 @@ GURL GURL::ResolveWithCharsetConverter( output.Complete(); result.is_valid_ = true; if (result.SchemeIsFileSystem()) { - result.inner_url_ = new GURL(result.spec_.data(), result.parsed_.Length(), - *result.parsed_.inner_parsed(), true); + result.inner_url_.reset( + new GURL(result.spec_.data(), result.parsed_.Length(), + *result.parsed_.inner_parsed(), true)); } return result; } @@ -257,8 +256,9 @@ GURL GURL::ResolveWithCharsetConverter( output.Complete(); result.is_valid_ = true; if (result.SchemeIsFileSystem()) { - result.inner_url_ = new GURL(result.spec_.data(), result.parsed_.Length(), - *result.parsed_.inner_parsed(), true); + result.inner_url_.reset( + new GURL(result.spec_.data(), result.parsed_.Length(), + *result.parsed_.inner_parsed(), true)); } return result; } @@ -283,8 +283,8 @@ GURL GURL::ReplaceComponents( output.Complete(); if (result.is_valid_ && result.SchemeIsFileSystem()) { - result.inner_url_ = new GURL(spec_.data(), result.parsed_.Length(), - *result.parsed_.inner_parsed(), true); + result.inner_url_.reset(new GURL(spec_.data(), result.parsed_.Length(), + *result.parsed_.inner_parsed(), true)); } return result; } @@ -309,8 +309,8 @@ GURL GURL::ReplaceComponents( output.Complete(); if (result.is_valid_ && result.SchemeIsFileSystem()) { - result.inner_url_ = new GURL(spec_.data(), result.parsed_.Length(), - *result.parsed_.inner_parsed(), true); + result.inner_url_.reset(new GURL(spec_.data(), result.parsed_.Length(), + *result.parsed_.inner_parsed(), true)); } return result; } @@ -516,7 +516,7 @@ void GURL::Swap(GURL* other) { spec_.swap(other->spec_); std::swap(is_valid_, other->is_valid_); std::swap(parsed_, other->parsed_); - std::swap(inner_url_, other->inner_url_); + inner_url_.swap(other->inner_url_); } std::ostream& operator<<(std::ostream& out, const GURL& url) { @@ -8,6 +8,7 @@ #include <iosfwd> #include <string> +#include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "url/url_canon.h" #include "url/url_canon_stdstring.h" @@ -345,7 +346,7 @@ class URL_EXPORT GURL { // Returns the inner URL of a nested URL [currently only non-null for // filesystem: URLs]. const GURL* inner_url() const { - return inner_url_; + return inner_url_.get(); } private: @@ -370,7 +371,7 @@ class URL_EXPORT GURL { url_parse::Parsed parsed_; // Used for nested schemes [currently only filesystem:]. - GURL* inner_url_; + scoped_ptr<GURL> inner_url_; // TODO bug 684583: Add encoding for query params. }; |