summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-07 14:17:14 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-07 14:17:14 +0000
commit36c8e5f7523eb31c11fce92246cdaca4e7af4f36 (patch)
tree117a4786075700fb0b86b843304964c694adf533 /net/http
parent7ec0cb21f022b28c20e6e44e5f38f9ed6bc13a16 (diff)
downloadchromium_src-36c8e5f7523eb31c11fce92246cdaca4e7af4f36.zip
chromium_src-36c8e5f7523eb31c11fce92246cdaca4e7af4f36.tar.gz
chromium_src-36c8e5f7523eb31c11fce92246cdaca4e7af4f36.tar.bz2
HttpAuthHandler's are no longer refcounted.
Since HttpAuthHandler objects are no longer contained inside of the HttpAuthCache, the lifetime of the handlers is more clearly defined. TEST=net_unittests (including some changes) BUG=42222 Review URL: http://codereview.chromium.org/2635004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_auth.cc10
-rw-r--r--net/http/http_auth.h3
-rw-r--r--net/http/http_auth_cache_unittest.cc44
-rw-r--r--net/http/http_auth_handler.h9
-rw-r--r--net/http/http_auth_handler_basic.cc4
-rw-r--r--net/http/http_auth_handler_basic.h2
-rw-r--r--net/http/http_auth_handler_basic_unittest.cc4
-rw-r--r--net/http/http_auth_handler_digest.cc4
-rw-r--r--net/http/http_auth_handler_digest.h2
-rw-r--r--net/http/http_auth_handler_digest_unittest.cc45
-rw-r--r--net/http/http_auth_handler_factory.cc10
-rw-r--r--net/http/http_auth_handler_factory.h8
-rw-r--r--net/http/http_auth_handler_factory_unittest.cc18
-rw-r--r--net/http/http_auth_handler_negotiate.h6
-rw-r--r--net/http/http_auth_handler_negotiate_posix.cc2
-rw-r--r--net/http/http_auth_handler_negotiate_unittest.cc18
-rw-r--r--net/http/http_auth_handler_negotiate_win.cc4
-rw-r--r--net/http/http_auth_handler_ntlm.h2
-rw-r--r--net/http/http_auth_handler_ntlm_portable.cc4
-rw-r--r--net/http/http_auth_handler_ntlm_win.cc4
-rw-r--r--net/http/http_auth_unittest.cc16
-rw-r--r--net/http/http_network_transaction.cc17
-rw-r--r--net/http/http_network_transaction.h2
-rw-r--r--net/http/http_network_transaction_unittest.cc38
24 files changed, 146 insertions, 130 deletions
diff --git a/net/http/http_auth.cc b/net/http/http_auth.cc
index e63afcd..09214e4 100644
--- a/net/http/http_auth.cc
+++ b/net/http/http_auth.cc
@@ -25,12 +25,12 @@ void HttpAuth::ChooseBestChallenge(
Target target,
const GURL& origin,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
DCHECK(http_auth_handler_factory);
// A connection-based authentication scheme must continue to use the
// existing handler object in |*handler|.
- if (*handler && (*handler)->is_connection_based()) {
+ if (handler->get() && (*handler)->is_connection_based()) {
const std::string header_name = GetChallengeHeaderName(target);
std::string challenge;
void* iter = NULL;
@@ -43,12 +43,12 @@ void HttpAuth::ChooseBestChallenge(
}
// Choose the challenge whose authentication handler gives the maximum score.
- scoped_refptr<HttpAuthHandler> best;
+ scoped_ptr<HttpAuthHandler> best;
const std::string header_name = GetChallengeHeaderName(target);
std::string cur_challenge;
void* iter = NULL;
while (headers->EnumerateHeader(&iter, header_name, &cur_challenge)) {
- scoped_refptr<HttpAuthHandler> cur;
+ scoped_ptr<HttpAuthHandler> cur;
int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
cur_challenge, target, origin, net_log, &cur);
if (rv != OK) {
@@ -56,7 +56,7 @@ void HttpAuth::ChooseBestChallenge(
<< ErrorToString(rv) << " Challenge: " << cur_challenge;
continue;
}
- if (cur && (!best || best->score() < cur->score()))
+ if (cur.get() && (!best.get() || best->score() < cur->score()))
best.swap(cur);
}
handler->swap(best);
diff --git a/net/http/http_auth.h b/net/http/http_auth.h
index dd1d2df..b56a1d9 100644
--- a/net/http/http_auth.h
+++ b/net/http/http_auth.h
@@ -5,6 +5,7 @@
#ifndef NET_HTTP_HTTP_AUTH_H_
#define NET_HTTP_HTTP_AUTH_H_
+#include "base/scoped_ptr.h"
#include "net/http/http_util.h"
template <class T> class scoped_refptr;
@@ -95,7 +96,7 @@ class HttpAuth {
Target target,
const GURL& origin,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler);
+ scoped_ptr<HttpAuthHandler>* handler);
// ChallengeTokenizer breaks up a challenge string into the the auth scheme
// and parameter list, according to RFC 2617 Sec 1.2:
diff --git a/net/http/http_auth_cache_unittest.cc b/net/http/http_auth_cache_unittest.cc
index 46d3f93..ced4e0a 100644
--- a/net/http/http_auth_cache_unittest.cc
+++ b/net/http/http_auth_cache_unittest.cc
@@ -60,26 +60,26 @@ TEST(HttpAuthCacheTest, Basic) {
// Add cache entries for 3 realms: "Realm1", "Realm2", "Realm3"
- scoped_refptr<HttpAuthHandler> realm1_handler =
- new MockAuthHandler("basic", "Realm1", HttpAuth::AUTH_SERVER);
+ scoped_ptr<HttpAuthHandler> realm1_handler(
+ new MockAuthHandler("basic", "Realm1", HttpAuth::AUTH_SERVER));
cache.Add(origin, realm1_handler->realm(), realm1_handler->scheme(),
"Basic realm=Realm1", L"realm1-user", L"realm1-password",
"/foo/bar/index.html");
- scoped_refptr<HttpAuthHandler> realm2_handler =
- new MockAuthHandler("basic", "Realm2", HttpAuth::AUTH_SERVER);
+ scoped_ptr<HttpAuthHandler> realm2_handler(
+ new MockAuthHandler("basic", "Realm2", HttpAuth::AUTH_SERVER));
cache.Add(origin, realm2_handler->realm(), realm2_handler->scheme(),
"Basic realm=Realm2", L"realm2-user", L"realm2-password",
"/foo2/index.html");
- scoped_refptr<HttpAuthHandler> realm3_basic_handler =
- new MockAuthHandler("basic", "Realm3", HttpAuth::AUTH_PROXY);
+ scoped_ptr<HttpAuthHandler> realm3_basic_handler(
+ new MockAuthHandler("basic", "Realm3", HttpAuth::AUTH_PROXY));
cache.Add(origin, realm3_basic_handler->realm(),
realm3_basic_handler->scheme(), "Basic realm=Realm3",
L"realm3-basic-user", L"realm3-basic-password", "");
- scoped_refptr<HttpAuthHandler> realm3_digest_handler =
- new MockAuthHandler("digest", "Realm3", HttpAuth::AUTH_PROXY);
+ scoped_ptr<HttpAuthHandler> realm3_digest_handler(
+ new MockAuthHandler("digest", "Realm3", HttpAuth::AUTH_PROXY));
cache.Add(origin, realm3_digest_handler->realm(),
realm3_digest_handler->scheme(), "Digest realm=Realm3",
L"realm3-digest-user", L"realm3-digest-password",
@@ -217,8 +217,8 @@ TEST(HttpAuthCacheTest, AddToExistingEntry) {
GURL origin("http://www.foobar.com:70");
const std::string auth_challenge = "Basic realm=MyRealm";
- scoped_refptr<HttpAuthHandler> handler =
- new MockAuthHandler("basic", "MyRealm", HttpAuth::AUTH_SERVER);
+ scoped_ptr<HttpAuthHandler> handler(
+ new MockAuthHandler("basic", "MyRealm", HttpAuth::AUTH_SERVER));
HttpAuthCache::Entry* orig_entry = cache.Add(
origin, handler->realm(), handler->scheme(), auth_challenge,
@@ -242,17 +242,17 @@ TEST(HttpAuthCacheTest, AddToExistingEntry) {
TEST(HttpAuthCacheTest, Remove) {
GURL origin("http://foobar2.com");
- scoped_refptr<HttpAuthHandler> realm1_handler =
- new MockAuthHandler("basic", "Realm1", HttpAuth::AUTH_SERVER);
+ scoped_ptr<HttpAuthHandler> realm1_handler(
+ new MockAuthHandler("basic", "Realm1", HttpAuth::AUTH_SERVER));
- scoped_refptr<HttpAuthHandler> realm2_handler =
- new MockAuthHandler("basic", "Realm2", HttpAuth::AUTH_SERVER);
+ scoped_ptr<HttpAuthHandler> realm2_handler(
+ new MockAuthHandler("basic", "Realm2", HttpAuth::AUTH_SERVER));
- scoped_refptr<HttpAuthHandler> realm3_basic_handler =
- new MockAuthHandler("basic", "Realm3", HttpAuth::AUTH_SERVER);
+ scoped_ptr<HttpAuthHandler> realm3_basic_handler(
+ new MockAuthHandler("basic", "Realm3", HttpAuth::AUTH_SERVER));
- scoped_refptr<HttpAuthHandler> realm3_digest_handler =
- new MockAuthHandler("digest", "Realm3", HttpAuth::AUTH_SERVER);
+ scoped_ptr<HttpAuthHandler> realm3_digest_handler(
+ new MockAuthHandler("digest", "Realm3", HttpAuth::AUTH_SERVER));
HttpAuthCache cache;
cache.Add(origin, realm1_handler->realm(), realm1_handler->scheme(),
@@ -322,12 +322,8 @@ class HttpAuthCacheEvictionTest : public testing::Test {
}
void AddPathToRealm(int realm_i, int path_i) {
- scoped_refptr<HttpAuthHandler> handler = new MockAuthHandler(
- "basic",
- GenerateRealm(realm_i), HttpAuth::AUTH_SERVER);
- std::string path = GeneratePath(realm_i, path_i);
- cache_.Add(origin_, handler->realm(), handler->scheme(),
- handler->challenge(), L"username", L"password", path);
+ cache_.Add(origin_, GenerateRealm(realm_i), "basic", "",
+ L"username", L"password", GeneratePath(realm_i, path_i));
}
void CheckRealmExistence(int realm_i, bool exists) {
diff --git a/net/http/http_auth_handler.h b/net/http/http_auth_handler.h
index 8c01d41..4aa8852 100644
--- a/net/http/http_auth_handler.h
+++ b/net/http/http_auth_handler.h
@@ -7,7 +7,6 @@
#include <string>
-#include "base/ref_counted.h"
#include "net/base/completion_callback.h"
#include "net/base/net_log.h"
#include "net/http/http_auth.h"
@@ -21,8 +20,10 @@ struct HttpRequestInfo;
// HttpAuthHandler is the interface for the authentication schemes
// (basic, digest, NTLM, Negotiate).
// HttpAuthHandler objects are typically created by an HttpAuthHandlerFactory.
-class HttpAuthHandler : public base::RefCounted<HttpAuthHandler> {
+class HttpAuthHandler {
public:
+ virtual ~HttpAuthHandler() {}
+
// Initializes the handler using a challenge issued by a server.
// |challenge| must be non-NULL and have already tokenized the
// authentication scheme, but none of the tokens occuring after the
@@ -130,10 +131,6 @@ class HttpAuthHandler : public base::RefCounted<HttpAuthHandler> {
IS_CONNECTION_BASED = 1 << 1,
};
- friend class base::RefCounted<HttpAuthHandler>;
-
- virtual ~HttpAuthHandler() { }
-
// Initializes the handler using a challenge issued by a server.
// |challenge| must be non-NULL and have already tokenized the
// authentication scheme, but none of the tokens occuring after the
diff --git a/net/http/http_auth_handler_basic.cc b/net/http/http_auth_handler_basic.cc
index 98bd02a..21bfc44 100644
--- a/net/http/http_auth_handler_basic.cc
+++ b/net/http/http_auth_handler_basic.cc
@@ -80,10 +80,10 @@ int HttpAuthHandlerBasic::Factory::CreateAuthHandler(
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
// TODO(cbentzel): Move towards model of parsing in the factory
// method and only constructing when valid.
- scoped_refptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic());
+ scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic());
if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
return ERR_INVALID_RESPONSE;
handler->swap(tmp_handler);
diff --git a/net/http/http_auth_handler_basic.h b/net/http/http_auth_handler_basic.h
index 61816a3..26003aa 100644
--- a/net/http/http_auth_handler_basic.h
+++ b/net/http/http_auth_handler_basic.h
@@ -24,7 +24,7 @@ class HttpAuthHandlerBasic : public HttpAuthHandler {
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler);
+ scoped_ptr<HttpAuthHandler>* handler);
};
virtual int GenerateAuthToken(const std::wstring& username,
diff --git a/net/http/http_auth_handler_basic_unittest.cc b/net/http/http_auth_handler_basic_unittest.cc
index 6e4599b..16652d4 100644
--- a/net/http/http_auth_handler_basic_unittest.cc
+++ b/net/http/http_auth_handler_basic_unittest.cc
@@ -28,7 +28,7 @@ TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) {
HttpAuthHandlerBasic::Factory factory;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
std::string challenge = "Basic realm=\"Atlantis\"";
- scoped_refptr<HttpAuthHandler> basic = new HttpAuthHandlerBasic;
+ scoped_ptr<HttpAuthHandler> basic;
EXPECT_EQ(OK, factory.CreateAuthHandlerFromString(
challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic));
std::string credentials;
@@ -67,7 +67,7 @@ TEST(HttpAuthHandlerBasicTest, InitFromChallenge) {
GURL origin("http://www.example.com");
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
std::string challenge = tests[i].challenge;
- scoped_refptr<HttpAuthHandler> basic = new HttpAuthHandlerBasic;
+ scoped_ptr<HttpAuthHandler> basic;
int rv = factory.CreateAuthHandlerFromString(
challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic);
EXPECT_EQ(tests[i].expected_rv, rv);
diff --git a/net/http/http_auth_handler_digest.cc b/net/http/http_auth_handler_digest.cc
index 86fab11..b15d01b 100644
--- a/net/http/http_auth_handler_digest.cc
+++ b/net/http/http_auth_handler_digest.cc
@@ -307,10 +307,10 @@ int HttpAuthHandlerDigest::Factory::CreateAuthHandler(
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
// TODO(cbentzel): Move towards model of parsing in the factory
// method and only constructing when valid.
- scoped_refptr<HttpAuthHandler> tmp_handler(
+ scoped_ptr<HttpAuthHandler> tmp_handler(
new HttpAuthHandlerDigest(digest_nonce_count));
if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
return ERR_INVALID_RESPONSE;
diff --git a/net/http/http_auth_handler_digest.h b/net/http/http_auth_handler_digest.h
index dc29a0b..bebbd8a 100644
--- a/net/http/http_auth_handler_digest.h
+++ b/net/http/http_auth_handler_digest.h
@@ -27,7 +27,7 @@ class HttpAuthHandlerDigest : public HttpAuthHandler {
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler);
+ scoped_ptr<HttpAuthHandler>* handler);
};
virtual int GenerateAuthToken(const std::wstring& username,
diff --git a/net/http/http_auth_handler_digest_unittest.cc b/net/http/http_auth_handler_digest_unittest.cc
index 304656ff..b1782f6 100644
--- a/net/http/http_auth_handler_digest_unittest.cc
+++ b/net/http/http_auth_handler_digest_unittest.cc
@@ -5,6 +5,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "base/basictypes.h"
+#include "net/base/net_errors.h"
#include "net/http/http_auth_handler_digest.h"
namespace net {
@@ -100,14 +101,25 @@ TEST(HttpAuthHandlerDigestTest, ParseChallenge) {
}
};
+ GURL origin("http://www.example.com");
+ scoped_ptr<HttpAuthHandlerDigest::Factory> factory(
+ new HttpAuthHandlerDigest::Factory());
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- std::string challenge(tests[i].challenge);
-
- scoped_refptr<HttpAuthHandlerDigest> digest = new HttpAuthHandlerDigest(1);
- HttpAuth::ChallengeTokenizer tok(challenge.begin(), challenge.end());
- bool ok = digest->ParseChallenge(&tok);
-
- EXPECT_EQ(tests[i].parsed_success, ok);
+ scoped_ptr<HttpAuthHandler> handler;
+ int rv = factory->CreateAuthHandlerFromString(tests[i].challenge,
+ HttpAuth::AUTH_SERVER,
+ origin,
+ BoundNetLog(),
+ &handler);
+ if (tests[i].parsed_success) {
+ EXPECT_EQ(OK, rv);
+ } else {
+ EXPECT_NE(OK, rv);
+ continue;
+ }
+ ASSERT_TRUE(handler != NULL);
+ HttpAuthHandlerDigest* digest =
+ static_cast<HttpAuthHandlerDigest*>(handler.get());
EXPECT_STREQ(tests[i].parsed_realm, digest->realm_.c_str());
EXPECT_STREQ(tests[i].parsed_nonce, digest->nonce_.c_str());
EXPECT_STREQ(tests[i].parsed_domain, digest->domain_.c_str());
@@ -250,13 +262,20 @@ TEST(HttpAuthHandlerDigestTest, AssembleCredentials) {
}
};
GURL origin("http://www.example.com");
+ scoped_ptr<HttpAuthHandlerDigest::Factory> factory(
+ new HttpAuthHandlerDigest::Factory());
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- scoped_refptr<HttpAuthHandlerDigest> digest = new HttpAuthHandlerDigest(1);
- std::string challenge = tests[i].challenge;
- HttpAuth::ChallengeTokenizer tok(challenge.begin(), challenge.end());
- EXPECT_TRUE(digest->InitFromChallenge(&tok, HttpAuth::AUTH_SERVER, origin,
- BoundNetLog()));
-
+ scoped_ptr<HttpAuthHandler> handler;
+ int rv = factory->CreateAuthHandlerFromString(tests[i].challenge,
+ HttpAuth::AUTH_SERVER,
+ origin,
+ BoundNetLog(),
+ &handler);
+ EXPECT_EQ(OK, rv);
+ ASSERT_TRUE(handler != NULL);
+
+ HttpAuthHandlerDigest* digest =
+ static_cast<HttpAuthHandlerDigest*>(handler.get());
std::string creds = digest->AssembleCredentials(tests[i].req_method,
tests[i].req_path,
tests[i].username,
diff --git a/net/http/http_auth_handler_factory.cc b/net/http/http_auth_handler_factory.cc
index e6d697f..c2d011b 100644
--- a/net/http/http_auth_handler_factory.cc
+++ b/net/http/http_auth_handler_factory.cc
@@ -20,7 +20,7 @@ int HttpAuthHandlerFactory::CreateAuthHandlerFromString(
HttpAuth::Target target,
const GURL& origin,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
HttpAuth::ChallengeTokenizer props(challenge.begin(), challenge.end());
return CreateAuthHandler(&props, target, origin, CREATE_CHALLENGE, 1,
net_log, handler);
@@ -32,7 +32,7 @@ int HttpAuthHandlerFactory::CreatePreemptiveAuthHandlerFromString(
const GURL& origin,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
HttpAuth::ChallengeTokenizer props(challenge.begin(), challenge.end());
return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE,
digest_nonce_count, net_log, handler);
@@ -90,15 +90,15 @@ int HttpAuthHandlerRegistryFactory::CreateAuthHandler(
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
if (!challenge->valid()) {
- *handler = NULL;
+ handler->reset();
return ERR_INVALID_RESPONSE;
}
std::string lower_scheme = StringToLowerASCII(challenge->scheme());
FactoryMap::iterator it = factory_map_.find(lower_scheme);
if (it == factory_map_.end()) {
- *handler = NULL;
+ handler->reset();
return ERR_UNSUPPORTED_AUTH_SCHEME;
}
DCHECK(it->second);
diff --git a/net/http/http_auth_handler_factory.h b/net/http/http_auth_handler_factory.h
index 42a9ac4..5f12e20 100644
--- a/net/http/http_auth_handler_factory.h
+++ b/net/http/http_auth_handler_factory.h
@@ -74,7 +74,7 @@ class HttpAuthHandlerFactory {
CreateReason create_reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) = 0;
+ scoped_ptr<HttpAuthHandler>* handler) = 0;
// Creates an HTTP authentication handler based on the authentication
// challenge string |challenge|.
@@ -85,7 +85,7 @@ class HttpAuthHandlerFactory {
HttpAuth::Target target,
const GURL& origin,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler);
+ scoped_ptr<HttpAuthHandler>* handler);
// Creates an HTTP authentication handler based on the authentication
// challenge string |challenge|.
@@ -98,7 +98,7 @@ class HttpAuthHandlerFactory {
const GURL& origin,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler);
+ scoped_ptr<HttpAuthHandler>* handler);
// Creates a standard HttpAuthHandlerRegistryFactory. The caller is
// responsible for deleting the factory.
@@ -149,7 +149,7 @@ class HttpAuthHandlerRegistryFactory : public HttpAuthHandlerFactory {
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler);
+ scoped_ptr<HttpAuthHandler>* handler);
private:
typedef std::map<std::string, HttpAuthHandlerFactory*> FactoryMap;
diff --git a/net/http/http_auth_handler_factory_unittest.cc b/net/http/http_auth_handler_factory_unittest.cc
index 2c2432f..bece442 100644
--- a/net/http/http_auth_handler_factory_unittest.cc
+++ b/net/http/http_auth_handler_factory_unittest.cc
@@ -22,8 +22,8 @@ class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory {
CreateReason reason,
int nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
- *handler = NULL;
+ scoped_ptr<HttpAuthHandler>* handler) {
+ handler->reset();
return return_code_;
}
@@ -46,7 +46,7 @@ TEST(HttpAuthHandlerFactoryTest, RegistryFactory) {
MockHttpAuthHandlerFactory* mock_factory_digest_replace =
new MockHttpAuthHandlerFactory(kDigestReturnCodeReplace);
- scoped_refptr<HttpAuthHandler> handler;
+ scoped_ptr<HttpAuthHandler> handler;
// No schemes should be supported in the beginning.
EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME,
@@ -96,7 +96,7 @@ TEST(HttpAuthHandlerFactoryTest, DefaultFactory) {
GURL server_origin("http://www.example.com");
GURL proxy_origin("http://cache.example.com:3128");
{
- scoped_refptr<HttpAuthHandler> handler;
+ scoped_ptr<HttpAuthHandler> handler;
int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
"Basic realm=\"FooBar\"",
HttpAuth::AUTH_SERVER,
@@ -112,7 +112,7 @@ TEST(HttpAuthHandlerFactoryTest, DefaultFactory) {
EXPECT_FALSE(handler->is_connection_based());
}
{
- scoped_refptr<HttpAuthHandler> handler;
+ scoped_ptr<HttpAuthHandler> handler;
int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
"UNSUPPORTED realm=\"FooBar\"",
HttpAuth::AUTH_SERVER,
@@ -123,7 +123,7 @@ TEST(HttpAuthHandlerFactoryTest, DefaultFactory) {
EXPECT_TRUE(handler.get() == NULL);
}
{
- scoped_refptr<HttpAuthHandler> handler;
+ scoped_ptr<HttpAuthHandler> handler;
int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
"Digest realm=\"FooBar\", nonce=\"xyz\"",
HttpAuth::AUTH_PROXY,
@@ -139,7 +139,7 @@ TEST(HttpAuthHandlerFactoryTest, DefaultFactory) {
EXPECT_FALSE(handler->is_connection_based());
}
{
- scoped_refptr<HttpAuthHandler> handler;
+ scoped_ptr<HttpAuthHandler> handler;
int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
"NTLM",
HttpAuth::AUTH_SERVER,
@@ -156,7 +156,7 @@ TEST(HttpAuthHandlerFactoryTest, DefaultFactory) {
}
#if defined(OS_WIN)
{
- scoped_refptr<HttpAuthHandler> handler;
+ scoped_ptr<HttpAuthHandler> handler;
int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
"Negotiate",
HttpAuth::AUTH_SERVER,
@@ -173,7 +173,7 @@ TEST(HttpAuthHandlerFactoryTest, DefaultFactory) {
}
#else // !defined(OS_WIN)
{
- scoped_refptr<HttpAuthHandler> handler;
+ scoped_ptr<HttpAuthHandler> handler;
int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
"Negotiate",
HttpAuth::AUTH_SERVER,
diff --git a/net/http/http_auth_handler_negotiate.h b/net/http/http_auth_handler_negotiate.h
index 6f2dab8..c7fdd67 100644
--- a/net/http/http_auth_handler_negotiate.h
+++ b/net/http/http_auth_handler_negotiate.h
@@ -56,7 +56,7 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler {
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler);
+ scoped_ptr<HttpAuthHandler>* handler);
#if defined(OS_WIN)
// Set the SSPILibrary to use. Typically the only callers which need to
@@ -88,6 +88,8 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler {
explicit HttpAuthHandlerNegotiate(URLSecurityManager* url_security_manager);
#endif
+ virtual ~HttpAuthHandlerNegotiate();
+
virtual bool NeedsIdentity();
virtual bool IsFinalRound();
@@ -119,8 +121,6 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler {
virtual bool Init(HttpAuth::ChallengeTokenizer* challenge);
private:
- ~HttpAuthHandlerNegotiate();
-
#if defined(OS_WIN)
void OnResolveCanonicalName(int result);
HttpAuthSSPI auth_sspi_;
diff --git a/net/http/http_auth_handler_negotiate_posix.cc b/net/http/http_auth_handler_negotiate_posix.cc
index 3870e8f..556307d 100644
--- a/net/http/http_auth_handler_negotiate_posix.cc
+++ b/net/http/http_auth_handler_negotiate_posix.cc
@@ -90,7 +90,7 @@ int HttpAuthHandlerNegotiate::Factory::CreateAuthHandler(
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
return ERR_UNSUPPORTED_AUTH_SCHEME;
}
diff --git a/net/http/http_auth_handler_negotiate_unittest.cc b/net/http/http_auth_handler_negotiate_unittest.cc
index ca54b47..910b5ef 100644
--- a/net/http/http_auth_handler_negotiate_unittest.cc
+++ b/net/http/http_auth_handler_negotiate_unittest.cc
@@ -22,10 +22,10 @@ namespace {
void CreateHandler(bool disable_cname_lookup, bool include_port,
const std::string& url_string,
SSPILibrary* sspi_library,
- scoped_refptr<HttpAuthHandlerNegotiate>* handler) {
- *handler = new HttpAuthHandlerNegotiate(sspi_library, 50, NULL,
- disable_cname_lookup,
- include_port);
+ scoped_ptr<HttpAuthHandlerNegotiate>* handler) {
+ handler->reset(new HttpAuthHandlerNegotiate(sspi_library, 50, NULL,
+ disable_cname_lookup,
+ include_port));
std::string challenge = "Negotiate";
HttpAuth::ChallengeTokenizer props(challenge.begin(), challenge.end());
GURL gurl(url_string);
@@ -37,7 +37,7 @@ void CreateHandler(bool disable_cname_lookup, bool include_port,
TEST(HttpAuthHandlerNegotiateTest, DisableCname) {
MockSSPILibrary mock_library;
- scoped_refptr<HttpAuthHandlerNegotiate> auth_handler;
+ scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
CreateHandler(true, false, "http://alias:500", &mock_library, &auth_handler);
EXPECT_FALSE(auth_handler->NeedsCanonicalName());
EXPECT_EQ(L"HTTP/alias", auth_handler->spn());
@@ -45,7 +45,7 @@ TEST(HttpAuthHandlerNegotiateTest, DisableCname) {
TEST(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) {
MockSSPILibrary mock_library;
- scoped_refptr<HttpAuthHandlerNegotiate> auth_handler;
+ scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
CreateHandler(true, true, "http://alias:80", &mock_library, &auth_handler);
EXPECT_FALSE(auth_handler->NeedsCanonicalName());
EXPECT_EQ(L"HTTP/alias", auth_handler->spn());
@@ -53,7 +53,7 @@ TEST(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) {
TEST(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) {
MockSSPILibrary mock_library;
- scoped_refptr<HttpAuthHandlerNegotiate> auth_handler;
+ scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
CreateHandler(true, true, "http://alias:500", &mock_library, &auth_handler);
EXPECT_FALSE(auth_handler->NeedsCanonicalName());
EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn());
@@ -61,7 +61,7 @@ TEST(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) {
TEST(HttpAuthHandlerNegotiateTest, CnameSync) {
MockSSPILibrary mock_library;
- scoped_refptr<HttpAuthHandlerNegotiate> auth_handler;
+ scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
CreateHandler(false, false, "http://alias:500", &mock_library, &auth_handler);
EXPECT_TRUE(auth_handler->NeedsCanonicalName());
MockHostResolver* mock_resolver = new MockHostResolver();
@@ -76,7 +76,7 @@ TEST(HttpAuthHandlerNegotiateTest, CnameSync) {
TEST(HttpAuthHandlerNegotiateTest, CnameAsync) {
MockSSPILibrary mock_library;
- scoped_refptr<HttpAuthHandlerNegotiate> auth_handler;
+ scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
CreateHandler(false, false, "http://alias:500", &mock_library, &auth_handler);
EXPECT_TRUE(auth_handler->NeedsCanonicalName());
MockHostResolver* mock_resolver = new MockHostResolver();
diff --git a/net/http/http_auth_handler_negotiate_win.cc b/net/http/http_auth_handler_negotiate_win.cc
index 4051ab5..bfb8258 100644
--- a/net/http/http_auth_handler_negotiate_win.cc
+++ b/net/http/http_auth_handler_negotiate_win.cc
@@ -197,7 +197,7 @@ int HttpAuthHandlerNegotiate::Factory::CreateAuthHandler(
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
if (is_unsupported_ || reason == CREATE_PREEMPTIVE)
return ERR_UNSUPPORTED_AUTH_SCHEME;
if (max_token_length_ == 0) {
@@ -210,7 +210,7 @@ int HttpAuthHandlerNegotiate::Factory::CreateAuthHandler(
}
// TODO(cbentzel): Move towards model of parsing in the factory
// method and only constructing when valid.
- scoped_refptr<HttpAuthHandler> tmp_handler(
+ scoped_ptr<HttpAuthHandler> tmp_handler(
new HttpAuthHandlerNegotiate(sspi_library_, max_token_length_,
url_security_manager(),
disable_cname_lookup_, use_port_));
diff --git a/net/http/http_auth_handler_ntlm.h b/net/http/http_auth_handler_ntlm.h
index d2eb7f8..4467932 100644
--- a/net/http/http_auth_handler_ntlm.h
+++ b/net/http/http_auth_handler_ntlm.h
@@ -47,7 +47,7 @@ class HttpAuthHandlerNTLM : public HttpAuthHandler {
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler);
+ scoped_ptr<HttpAuthHandler>* handler);
#if defined(NTLM_SSPI)
// Set the SSPILibrary to use. Typically the only callers which need to
// use this are unit tests which pass in a mocked-out version of the
diff --git a/net/http/http_auth_handler_ntlm_portable.cc b/net/http/http_auth_handler_ntlm_portable.cc
index fb6db5f..940768c 100644
--- a/net/http/http_auth_handler_ntlm_portable.cc
+++ b/net/http/http_auth_handler_ntlm_portable.cc
@@ -732,14 +732,14 @@ int HttpAuthHandlerNTLM::Factory::CreateAuthHandler(
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
if (reason == CREATE_PREEMPTIVE)
return ERR_UNSUPPORTED_AUTH_SCHEME;
// TODO(cbentzel): Move towards model of parsing in the factory
// method and only constructing when valid.
// NOTE: Default credentials are not supported for the portable implementation
// of NTLM.
- scoped_refptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNTLM);
+ scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNTLM);
if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
return ERR_INVALID_RESPONSE;
handler->swap(tmp_handler);
diff --git a/net/http/http_auth_handler_ntlm_win.cc b/net/http/http_auth_handler_ntlm_win.cc
index 160b981..0bd1e71 100644
--- a/net/http/http_auth_handler_ntlm_win.cc
+++ b/net/http/http_auth_handler_ntlm_win.cc
@@ -77,7 +77,7 @@ int HttpAuthHandlerNTLM::Factory::CreateAuthHandler(
CreateReason reason,
int digest_nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
+ scoped_ptr<HttpAuthHandler>* handler) {
if (is_unsupported_ || reason == CREATE_PREEMPTIVE)
return ERR_UNSUPPORTED_AUTH_SCHEME;
if (max_token_length_ == 0) {
@@ -90,7 +90,7 @@ int HttpAuthHandlerNTLM::Factory::CreateAuthHandler(
}
// TODO(cbentzel): Move towards model of parsing in the factory
// method and only constructing when valid.
- scoped_refptr<HttpAuthHandler> tmp_handler(
+ scoped_ptr<HttpAuthHandler> tmp_handler(
new HttpAuthHandlerNTLM(sspi_library_, max_token_length_,
url_security_manager()));
if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
diff --git a/net/http/http_auth_unittest.cc b/net/http/http_auth_unittest.cc
index 10ce05d..a87ac6e 100644
--- a/net/http/http_auth_unittest.cc
+++ b/net/http/http_auth_unittest.cc
@@ -85,7 +85,7 @@ TEST(HttpAuthTest, ChooseBestChallenge) {
headers_with_status_line.c_str(),
headers_with_status_line.length())));
- scoped_refptr<HttpAuthHandler> handler;
+ scoped_ptr<HttpAuthHandler> handler;
HttpAuth::ChooseBestChallenge(http_auth_handler_factory.get(),
headers.get(),
HttpAuth::AUTH_SERVER,
@@ -93,7 +93,7 @@ TEST(HttpAuthTest, ChooseBestChallenge) {
BoundNetLog(),
&handler);
- if (handler) {
+ if (handler.get()) {
EXPECT_STREQ(tests[i].challenge_scheme, handler->scheme().c_str());
EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
} else {
@@ -129,9 +129,9 @@ TEST(HttpAuthTest, ChooseBestChallengeConnectionBased) {
};
GURL origin("http://www.example.com");
- scoped_refptr<HttpAuthHandler> handler;
scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory(
HttpAuthHandlerFactory::CreateDefault());
+ scoped_ptr<HttpAuthHandler> handler;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
// Make a HttpResponseHeaders object.
@@ -143,22 +143,22 @@ TEST(HttpAuthTest, ChooseBestChallengeConnectionBased) {
headers_with_status_line.c_str(),
headers_with_status_line.length())));
- scoped_refptr<HttpAuthHandler> old_handler = handler;
+ // possibly_deleted_old_handler may point to deleted memory
+ // after ChooseBestChallenge has been called, and should not
+ // be dereferenced.
+ HttpAuthHandler* possibly_deleted_old_handler = handler.get();
HttpAuth::ChooseBestChallenge(http_auth_handler_factory.get(),
headers.get(),
HttpAuth::AUTH_SERVER,
origin,
BoundNetLog(),
&handler);
-
EXPECT_TRUE(handler != NULL);
// Since NTLM is connection-based, we should continue to use the existing
// handler rather than creating a new one.
if (i != 0)
- EXPECT_EQ(old_handler, handler);
-
+ EXPECT_EQ(possibly_deleted_old_handler, handler.get());
ASSERT_NE(reinterpret_cast<net::HttpAuthHandler *>(NULL), handler.get());
-
EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
}
}
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 0ecb180..db67c13 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -1362,11 +1362,10 @@ int HttpNetworkTransaction::DoReadHeadersComplete(int result) {
}
int HttpNetworkTransaction::DoResolveCanonicalName() {
- HttpAuthHandler* auth_handler = auth_handler_[pending_auth_target_];
- DCHECK(auth_handler);
+ DCHECK(auth_handler_[pending_auth_target_].get());
next_state_ = STATE_RESOLVE_CANONICAL_NAME_COMPLETE;
- return auth_handler->ResolveCanonicalName(session_->host_resolver(),
- &io_callback_);
+ return auth_handler_[pending_auth_target_]->
+ ResolveCanonicalName(session_->host_resolver(), &io_callback_);
}
int HttpNetworkTransaction::DoResolveCanonicalNameComplete(int result) {
@@ -1992,7 +1991,7 @@ bool HttpNetworkTransaction::SelectPreemptiveAuth(HttpAuth::Target target) {
return false;
// Try to create a handler using the previous auth challenge.
- scoped_refptr<HttpAuthHandler> handler_preemptive;
+ scoped_ptr<HttpAuthHandler> handler_preemptive;
int rv_create = session_->http_auth_handler_factory()->
CreatePreemptiveAuthHandlerFromString(
entry->auth_challenge(), target, AuthOrigin(target),
@@ -2005,14 +2004,14 @@ bool HttpNetworkTransaction::SelectPreemptiveAuth(HttpAuth::Target target) {
auth_identity_[target].invalid = false;
auth_identity_[target].username = entry->username();
auth_identity_[target].password = entry->password();
- auth_handler_[target] = handler_preemptive;
+ auth_handler_[target].swap(handler_preemptive);
return true;
}
bool HttpNetworkTransaction::SelectNextAuthIdentityToTry(
HttpAuth::Target target,
const GURL& auth_origin) {
- DCHECK(auth_handler_[target]);
+ DCHECK(auth_handler_[target].get());
DCHECK(auth_identity_[target].invalid);
// Try to use the username/password encoded into the URL first.
@@ -2115,7 +2114,7 @@ int HttpNetworkTransaction::HandleAuthChallenge(bool establishing_tunnel) {
// See http://crbug.com/21015.
if (HaveAuth(target) && auth_handler_[target]->IsFinalRound()) {
InvalidateRejectedAuthFromCache(target, auth_origin);
- auth_handler_[target] = NULL;
+ auth_handler_[target].reset();
auth_identity_[target] = HttpAuth::Identity();
}
@@ -2129,7 +2128,7 @@ int HttpNetworkTransaction::HandleAuthChallenge(bool establishing_tunnel) {
&auth_handler_[target]);
}
- if (!auth_handler_[target]) {
+ if (!auth_handler_[target].get()) {
if (establishing_tunnel) {
LOG(ERROR) << "Can't perform auth to the " << AuthTargetString(target)
<< " " << auth_origin << " when establishing a tunnel"
diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h
index bf945fa..277df2a 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -294,7 +294,7 @@ class HttpNetworkTransaction : public HttpTransaction {
// auth_handler encapsulates the logic for the particular auth-scheme.
// This includes the challenge's parameters. If NULL, then there is no
// associated auth handler.
- scoped_refptr<HttpAuthHandler> auth_handler_[2];
+ scoped_ptr<HttpAuthHandler> auth_handler_[2];
// auth_identity_ holds the (username/password) that should be used by
// the auth_handler_ to generate credentials. This identity can come from
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index f0c111a..e34b0f3 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -5401,8 +5401,13 @@ class MockAuthHandlerCanonical : public HttpAuthHandler {
RESOLVE_TESTED,
};
- MockAuthHandlerCanonical() : resolve_(RESOLVE_INIT), user_callback_(NULL) {}
- virtual ~MockAuthHandlerCanonical() {}
+ MockAuthHandlerCanonical()
+ : resolve_(RESOLVE_INIT), user_callback_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
+ }
+
+ virtual ~MockAuthHandlerCanonical() {
+ }
void SetResolveExpectation(Resolve resolve) {
EXPECT_EQ(RESOLVE_INIT, resolve_);
@@ -5441,9 +5446,8 @@ class MockAuthHandlerCanonical : public HttpAuthHandler {
rv = ERR_IO_PENDING;
user_callback_ = callback;
MessageLoop::current()->PostTask(
- FROM_HERE,
- NewRunnableMethod(
- this, &MockAuthHandlerCanonical::OnResolveCanonicalName));
+ FROM_HERE, method_factory_.NewRunnableMethod(
+ &MockAuthHandlerCanonical::OnResolveCanonicalName));
break;
default:
NOTREACHED();
@@ -5491,11 +5495,8 @@ class MockAuthHandlerCanonical : public HttpAuthHandler {
Factory() {}
virtual ~Factory() {}
- void set_mock_handler(MockAuthHandlerCanonical* mock_handler) {
- mock_handler_ = mock_handler;
- }
- MockAuthHandlerCanonical* mock_handler() const {
- return mock_handler_.get();
+ void set_mock_handler(HttpAuthHandler* handler) {
+ handler_.reset(handler);
}
virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge,
@@ -5504,33 +5505,36 @@ class MockAuthHandlerCanonical : public HttpAuthHandler {
CreateReason reason,
int nonce_count,
const BoundNetLog& net_log,
- scoped_refptr<HttpAuthHandler>* handler) {
- *handler = mock_handler_;
+ scoped_ptr<HttpAuthHandler>* handler) {
+ if (!handler_.get())
+ return ERR_UNEXPECTED;
+ handler->swap(handler_);
return OK;
}
private:
- scoped_refptr<MockAuthHandlerCanonical> mock_handler_;
+ scoped_ptr<HttpAuthHandler> handler_;
};
private:
Resolve resolve_;
CompletionCallback* user_callback_;
+ ScopedRunnableMethodFactory<MockAuthHandlerCanonical> method_factory_;
};
// Tests that ResolveCanonicalName is handled correctly by the
// HttpNetworkTransaction.
TEST_F(HttpNetworkTransactionTest, ResolveCanonicalName) {
SessionDependencies session_deps;
- scoped_refptr<MockAuthHandlerCanonical> auth_handler(
- new MockAuthHandlerCanonical());
- auth_handler->Init(NULL);
MockAuthHandlerCanonical::Factory* auth_factory(
new MockAuthHandlerCanonical::Factory());
- auth_factory->set_mock_handler(auth_handler);
session_deps.http_auth_handler_factory.reset(auth_factory);
for (int i = 0; i < 2; ++i) {
+ MockAuthHandlerCanonical* auth_handler(new MockAuthHandlerCanonical());
+ auth_handler->Init(NULL);
+ auth_factory->set_mock_handler(auth_handler);
+
scoped_ptr<HttpTransaction> trans(
new HttpNetworkTransaction(CreateSession(&session_deps)));