diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-15 06:43:48 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-15 06:43:48 +0000 |
commit | 515838ce76cb8bec7f51f6143cac74f113e247ad (patch) | |
tree | 71b70d594974310b35d1c8f7843aeda5717c044b | |
parent | 92352a66515fd9a01f538529356ad45870109f28 (diff) | |
download | chromium_src-515838ce76cb8bec7f51f6143cac74f113e247ad.zip chromium_src-515838ce76cb8bec7f51f6143cac74f113e247ad.tar.gz chromium_src-515838ce76cb8bec7f51f6143cac74f113e247ad.tar.bz2 |
post-winhttp cleanup: refactor net/base/auth_cache into net/ftp/ftp_auth_cache.
Also moves AuthCache::HttpKey() --> GetSignonRealmKey().
Review URL: http://codereview.chromium.org/18218
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8085 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/login_prompt.cc | 36 | ||||
-rw-r--r-- | chrome/browser/login_prompt.h | 7 | ||||
-rw-r--r-- | chrome/browser/login_prompt_unittest.cc (renamed from net/base/auth_cache_unittest.cc) | 13 | ||||
-rw-r--r-- | chrome/test/unit/unit_tests.scons | 1 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 4 | ||||
-rw-r--r-- | net/base/auth_cache.cc | 49 | ||||
-rw-r--r-- | net/base/auth_cache.h | 62 | ||||
-rw-r--r-- | net/build/net.vcproj | 16 | ||||
-rw-r--r-- | net/build/net_unittests.vcproj | 12 | ||||
-rw-r--r-- | net/ftp/ftp_auth_cache.cc | 35 | ||||
-rw-r--r-- | net/ftp/ftp_auth_cache.h | 58 | ||||
-rw-r--r-- | net/ftp/ftp_auth_cache_unittest.cc | 70 | ||||
-rw-r--r-- | net/ftp/ftp_network_layer.cc | 2 | ||||
-rw-r--r-- | net/ftp/ftp_network_layer.h | 2 | ||||
-rw-r--r-- | net/ftp/ftp_network_session.h | 6 | ||||
-rw-r--r-- | net/ftp/ftp_transaction_factory.h | 4 | ||||
-rw-r--r-- | net/net.xcodeproj/project.pbxproj | 24 | ||||
-rw-r--r-- | net/net_lib.scons | 4 | ||||
-rw-r--r-- | net/net_unittests.scons | 4 | ||||
-rw-r--r-- | net/url_request/url_request_context.h | 8 | ||||
-rw-r--r-- | net/url_request/url_request_ftp_job.cc | 9 |
21 files changed, 257 insertions, 169 deletions
diff --git a/chrome/browser/login_prompt.cc b/chrome/browser/login_prompt.cc index 377753f..5ce0638 100644 --- a/chrome/browser/login_prompt.cc +++ b/chrome/browser/login_prompt.cc @@ -43,6 +43,35 @@ static void ResetLoginHandlerForRequest(URLRequest* request) { } // ---------------------------------------------------------------------------- +// LoginHandler + +// Get the signon_realm under which this auth info should be stored. +// +// The format of the signon_realm for proxy auth is: +// proxy-host/auth-realm +// The format of the signon_realm for server auth is: +// url-scheme://url-host[:url-port]/auth-realm +// +// Be careful when changing this function, since you could make existing +// saved logins un-retrievable. + +// static +std::string LoginHandler::GetSignonRealm(const GURL& url, + const net::AuthChallengeInfo& auth_info) { + std::string signon_realm; + if (auth_info.is_proxy) { + signon_realm = WideToASCII(auth_info.host); + signon_realm.append("/"); + } else { + // Take scheme, host, and port from the url. + signon_realm = url.GetOrigin().spec(); + // This ends with a "/". + } + signon_realm.append(WideToUTF8(auth_info.realm)); + return signon_realm; +} + +// ---------------------------------------------------------------------------- // LoginHandlerImpl // This class simply forwards the authentication from the LoginView (on @@ -358,11 +387,8 @@ class LoginDialogTask : public Task { dialog_form.scheme = PasswordForm::SCHEME_OTHER; } dialog_form.origin = origin_url; - // TODO(timsteele): Shouldn't depend on HttpKey since a change to the - // format would result in not being able to retrieve existing logins - // for a site. Refactor HttpKey behavior to be more reusable. - dialog_form.signon_realm = - net::AuthCache::HttpKey(dialog_form.origin, *auth_info_); + dialog_form.signon_realm = LoginHandler::GetSignonRealm(dialog_form.origin, + *auth_info_); password_manager_input->push_back(dialog_form); // Set the password form for the handler (by copy). handler_->set_password_form(dialog_form); diff --git a/chrome/browser/login_prompt.h b/chrome/browser/login_prompt.h index 5c7fab9..0e37467 100644 --- a/chrome/browser/login_prompt.h +++ b/chrome/browser/login_prompt.h @@ -13,9 +13,10 @@ namespace net { class AuthChallengeInfo; } -class URLRequest; +class GURL; class MessageLoop; class TabContents; +class URLRequest; // This is the interface for the class that routes authentication info to // the URLRequest that needs it. Used by the automation proxy for testing. @@ -35,6 +36,10 @@ class LoginHandler { // Notify the handler that the request was cancelled. // This function can only be called from the IO thread. virtual void OnRequestCancelled() = 0; + + // Get the signon_realm under which the identity should be saved. + static std::string GetSignonRealm(const GURL& url, + const net::AuthChallengeInfo& auth_info); }; // Details to provide the NotificationObserver. Used by the automation proxy diff --git a/net/base/auth_cache_unittest.cc b/chrome/browser/login_prompt_unittest.cc index e730345..e16093a 100644 --- a/net/base/auth_cache_unittest.cc +++ b/chrome/browser/login_prompt_unittest.cc @@ -2,18 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/login_prompt.h" #include "googleurl/src/gurl.h" -#include "net/base/auth_cache.h" +#include "net/base/auth.h" #include "testing/gtest/include/gtest/gtest.h" -namespace { -class AuthCacheTest : public testing::Test { -}; - -} // namespace - -TEST(AuthCacheTest, HttpKey) { +TEST(LoginHandlerTest, GetSignonRealm) { scoped_refptr<net::AuthChallengeInfo> auth_info = new net::AuthChallengeInfo; auth_info->is_proxy = false; // server auth // auth_info->host is intentionally left empty. @@ -41,7 +36,7 @@ TEST(AuthCacheTest, HttpKey) { }; for (size_t i = 0; i < arraysize(url); i++) { - std::string key = net::AuthCache::HttpKey(GURL(url[i]), *auth_info); + std::string key = LoginHandler::GetSignonRealm(GURL(url[i]), *auth_info); EXPECT_EQ(expected[i], key); } } diff --git a/chrome/test/unit/unit_tests.scons b/chrome/test/unit/unit_tests.scons index ed28d02..7d0c68a 100644 --- a/chrome/test/unit/unit_tests.scons +++ b/chrome/test/unit/unit_tests.scons @@ -193,6 +193,7 @@ if env.Bit('windows'): '$CHROME_DIR/browser/history/url_database_unittest.cc', '$CHROME_DIR/browser/importer/firefox_importer_unittest.cc', '$CHROME_DIR/browser/importer/importer_unittest.cc', + '$CHROME_DIR/browser/login_prompt_unittest.cc', '$CHROME_DIR/browser/metrics_log_unittest.cc', '$CHROME_DIR/browser/navigation_controller_unittest.cc', '$CHROME_DIR/browser/net/dns_master_unittest.cc', diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index d76579d..f00154e 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -495,6 +495,10 @@ > </File> <File + RelativePath="..\..\browser\login_prompt_unittest.cc" + > + </File> + <File RelativePath="..\..\browser\metrics_log_unittest.cc" > </File> diff --git a/net/base/auth_cache.cc b/net/base/auth_cache.cc deleted file mode 100644 index 025a520..0000000 --- a/net/base/auth_cache.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/base/auth_cache.h" - -#include "base/string_util.h" -#include "googleurl/src/gurl.h" - -namespace net { - -// Create an AuthCacheKey from url and auth_info. -// -// The cache key is made up of two components, separated by a slash /. -// 1. The host (proxy or server) requesting authentication. For a server, -// this component also includes the scheme (protocol) and port (if not -// the default port for the protocol) to distinguish between multiple -// servers running on the same computer. -// 2. The realm. -// -// The format of the cache key for proxy auth is: -// proxy-host/auth-realm -// The format of the cache key for server auth is: -// url-scheme://url-host[:url-port]/auth-realm - -// static -AuthCache::AuthCacheKey AuthCache::HttpKey( - const GURL& url, - const AuthChallengeInfo& auth_info) { - AuthCacheKey auth_cache_key; - if (auth_info.is_proxy) { - auth_cache_key = WideToASCII(auth_info.host); - auth_cache_key.append("/"); - } else { - // Take scheme, host, and port from the url. - auth_cache_key = url.GetOrigin().spec(); - // This ends with a "/". - } - auth_cache_key.append(WideToUTF8(auth_info.realm)); - return auth_cache_key; -} - -AuthData* AuthCache::Lookup(const AuthCacheKey& key) { - AuthCacheMap::iterator iter = cache_.find(key); - return (iter == cache_.end()) ? NULL : iter->second; -} - -} // namespace net - diff --git a/net/base/auth_cache.h b/net/base/auth_cache.h deleted file mode 100644 index ff7444d..0000000 --- a/net/base/auth_cache.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_BASE_AUTH_CACHE_H__ -#define NET_BASE_AUTH_CACHE_H__ - -#include <string> -#include <map> - -#include "net/base/auth.h" - -class GURL; - -namespace net { - -// The AuthCache class is a simple cache structure to store authentication -// information for ftp or http/https sites. Provides lookup, addition, and -// validation of entries. -class AuthCache { - public: - AuthCache() {} - ~AuthCache() {} - - typedef std::string AuthCacheKey; - - // Return the key for looking up the auth data in the auth cache for HTTP, - // consisting of the scheme, host, and port of the request URL and the - // realm in the auth challenge. - static AuthCacheKey HttpKey(const GURL& url, - const AuthChallengeInfo& auth_info); - - // Check if we have authentication data for given key. The key parameter - // is input, consisting of the hostname and any other info (such as realm) - // appropriate for the protocol. Return the address of corresponding - // AuthData object (if found) or NULL (if not found). - AuthData* Lookup(const AuthCacheKey& key); - - // Add to the cache. If key already exists, this will overwrite. Both - // parameters are IN only. - void Add(const AuthCacheKey& key, AuthData* value) { - cache_[key] = value; - } - - // Called when we have an auth failure to remove - // the likely invalid credentials. - void Remove(const AuthCacheKey& key) { - cache_.erase(key); - } - - private: - typedef scoped_refptr<AuthData> AuthCacheValue; - typedef std::map<AuthCacheKey,AuthCacheValue> AuthCacheMap; - - // internal representation of cache, an STL map. - AuthCacheMap cache_; -}; - -} // namespace net - -#endif // NET_BASE_AUTH_CACHE_H__ - diff --git a/net/build/net.vcproj b/net/build/net.vcproj index 5a71089..79732cc 100644 --- a/net/build/net.vcproj +++ b/net/build/net.vcproj @@ -149,14 +149,6 @@ > </File> <File - RelativePath="..\base\auth_cache.cc" - > - </File> - <File - RelativePath="..\base\auth_cache.h" - > - </File> - <File RelativePath="..\base\base64.cc" > </File> @@ -1041,6 +1033,14 @@ Name="ftp" > <File + RelativePath="..\ftp\ftp_auth_cache.cc" + > + </File> + <File + RelativePath="..\ftp\ftp_auth_cache.h" + > + </File> + <File RelativePath="..\ftp\ftp_network_layer.cc" > </File> diff --git a/net/build/net_unittests.vcproj b/net/build/net_unittests.vcproj index c28bc20..b157a22 100644 --- a/net/build/net_unittests.vcproj +++ b/net/build/net_unittests.vcproj @@ -283,10 +283,6 @@ Name="base" > <File - RelativePath="..\base\auth_cache_unittest.cc" - > - </File> - <File RelativePath="..\base\base64_unittest.cc" > </File> @@ -392,6 +388,14 @@ </File> </Filter> <Filter + Name="ftp" + > + <File + RelativePath="..\ftp\ftp_auth_cache_unittest.cc" + > + </File> + </Filter> + <Filter Name="url_request" > <File diff --git a/net/ftp/ftp_auth_cache.cc b/net/ftp/ftp_auth_cache.cc new file mode 100644 index 0000000..8f1d18a --- /dev/null +++ b/net/ftp/ftp_auth_cache.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/ftp/ftp_auth_cache.h" + +#include "base/string_util.h" +#include "googleurl/src/gurl.h" + +namespace net { + +AuthData* FtpAuthCache::Lookup(const GURL& origin) { + AuthCacheMap::iterator iter = cache_.find(MakeKey(origin)); + return (iter == cache_.end()) ? NULL : iter->second; +} + +void FtpAuthCache::Add(const GURL& origin, AuthData* value) { + cache_[MakeKey(origin)] = value; + + // TODO(eroman): enforce a maximum number of entries. +} + +void FtpAuthCache::Remove(const GURL& origin) { + cache_.erase(MakeKey(origin)); +} + +// static +FtpAuthCache::AuthCacheKey FtpAuthCache::MakeKey(const GURL& origin) { + DCHECK(origin.SchemeIs("ftp")); + DCHECK(origin.GetOrigin() == origin); + return origin.spec(); +} + +} // namespace net + diff --git a/net/ftp/ftp_auth_cache.h b/net/ftp/ftp_auth_cache.h new file mode 100644 index 0000000..752842c --- /dev/null +++ b/net/ftp/ftp_auth_cache.h @@ -0,0 +1,58 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_FTP_FTP_AUTH_CACHE_H_ +#define NET_FTP_FTP_AUTH_CACHE_H_ + +#include <string> +#include <map> + +#include "net/base/auth.h" + +class GURL; + +namespace net { + +// The FtpAuthCache class is a simple cache structure to store authentication +// information for ftp. Provides lookup, insertion, and deletion of entries. +// The parameter for doing lookups, insertions, and deletions is a GURL of the +// server's address (not a full URL with path, since FTP auth isn't per path). +// For example: +// GURL("ftp://myserver") -- OK (implied port of 21) +// GURL("ftp://myserver:21") -- OK +// GURL("ftp://myserver/PATH") -- WRONG, paths not allowed +class FtpAuthCache { + public: + FtpAuthCache() {} + ~FtpAuthCache() {} + + // Check if we have authentication data for ftp server at |origin|. + // Returns the address of corresponding AuthData object (if found) or NULL + // (if not found). + AuthData* Lookup(const GURL& origin); + + // Add an entry for |origin| to the cache. If there is already an + // entry for |origin|, it will be overwritten. Both parameters are IN only. + void Add(const GURL& origin, AuthData* value); + + // Remove the entry for |origin| from the cache, if one exists. + void Remove(const GURL& origin); + + private: + typedef std::string AuthCacheKey; + typedef scoped_refptr<AuthData> AuthCacheValue; + typedef std::map<AuthCacheKey,AuthCacheValue> AuthCacheMap; + + // Get the key in hash table |cache_| where entries for ftp server |origin| + // should be saved. + static AuthCacheKey MakeKey(const GURL& origin); + + // internal representation of cache, an STL map. + AuthCacheMap cache_; +}; + +} // namespace net + +#endif // NET_FTP_FTP_AUTH_CACHE_H_ + diff --git a/net/ftp/ftp_auth_cache_unittest.cc b/net/ftp/ftp_auth_cache_unittest.cc new file mode 100644 index 0000000..1164540 --- /dev/null +++ b/net/ftp/ftp_auth_cache_unittest.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "googleurl/src/gurl.h" +#include "net/ftp/ftp_auth_cache.h" +#include "testing/gtest/include/gtest/gtest.h" + +using net::AuthData; +using net::FtpAuthCache; + +TEST(FtpAuthCacheTest, LookupAddRemove) { + FtpAuthCache cache; + + GURL origin1("ftp://foo1"); + scoped_refptr<AuthData> data1(new AuthData()); + + GURL origin2("ftp://foo2"); + scoped_refptr<AuthData> data2(new AuthData()); + + GURL origin3("ftp://foo3"); + scoped_refptr<AuthData> data3(new AuthData()); + + // Lookup non-existent entry. + EXPECT_EQ(NULL, cache.Lookup(origin1)); + + // Add entry for origin1. + cache.Add(origin1, data1.get()); + EXPECT_EQ(data1.get(), cache.Lookup(origin1)); + + // Add an entry for origin2. + cache.Add(origin2, data2.get()); + EXPECT_EQ(data1.get(), cache.Lookup(origin1)); + EXPECT_EQ(data2.get(), cache.Lookup(origin2)); + + // Overwrite the entry for origin1. + cache.Add(origin1, data3.get()); + EXPECT_EQ(data3.get(), cache.Lookup(origin1)); + EXPECT_EQ(data2.get(), cache.Lookup(origin2)); + + // Remove entry of origin1. + cache.Remove(origin1); + EXPECT_EQ(NULL, cache.Lookup(origin1)); + EXPECT_EQ(data2.get(), cache.Lookup(origin2)); + + // Remove non-existent entry + cache.Remove(origin1); + EXPECT_EQ(NULL, cache.Lookup(origin1)); + EXPECT_EQ(data2.get(), cache.Lookup(origin2)); +} + +// Check that if the origin differs only by port number, it is considered +// a separate origin. +TEST(FtpAuthCacheTest, LookupWithPort) { + FtpAuthCache cache; + + GURL origin1("ftp://foo:80"); + scoped_refptr<AuthData> data1(new AuthData()); + + GURL origin2("ftp://foo:21"); + scoped_refptr<AuthData> data2(new AuthData()); + + cache.Add(origin1, data1.get()); + cache.Add(origin2, data2.get()); + + EXPECT_EQ(data1.get(), cache.Lookup(origin1)); + EXPECT_EQ(data2.get(), cache.Lookup(origin2)); +} + + diff --git a/net/ftp/ftp_network_layer.cc b/net/ftp/ftp_network_layer.cc index ea21b4f..06884ce 100644 --- a/net/ftp/ftp_network_layer.cc +++ b/net/ftp/ftp_network_layer.cc @@ -26,7 +26,7 @@ FtpTransaction* FtpNetworkLayer::CreateTransaction() { session_, ClientSocketFactory::GetDefaultFactory()); } -AuthCache* FtpNetworkLayer::GetAuthCache() { +FtpAuthCache* FtpNetworkLayer::GetAuthCache() { return session_->auth_cache(); } diff --git a/net/ftp/ftp_network_layer.h b/net/ftp/ftp_network_layer.h index 0f071b9..fa5c430 100644 --- a/net/ftp/ftp_network_layer.h +++ b/net/ftp/ftp_network_layer.h @@ -19,7 +19,7 @@ class FtpNetworkLayer : public FtpTransactionFactory { // FtpTransactionFactory methods: virtual FtpTransaction* CreateTransaction(); - virtual AuthCache* GetAuthCache(); + virtual FtpAuthCache* GetAuthCache(); virtual void Suspend(bool suspend); private: diff --git a/net/ftp/ftp_network_session.h b/net/ftp/ftp_network_session.h index 83a1cc7..13ab216 100644 --- a/net/ftp/ftp_network_session.h +++ b/net/ftp/ftp_network_session.h @@ -6,7 +6,7 @@ #define NET_FTP_FTP_NETWORK_SESSION_H_ #include "base/ref_counted.h" -#include "net/base/auth_cache.h" +#include "net/ftp/ftp_auth_cache.h" namespace net { @@ -15,10 +15,10 @@ class FtpNetworkSession : public base::RefCounted<FtpNetworkSession> { public: FtpNetworkSession() {} - AuthCache* auth_cache() { return &auth_cache_; } + FtpAuthCache* auth_cache() { return &auth_cache_; } private: - AuthCache auth_cache_; + FtpAuthCache auth_cache_; }; } // namespace net diff --git a/net/ftp/ftp_transaction_factory.h b/net/ftp/ftp_transaction_factory.h index 67af645..f4cc53a 100644 --- a/net/ftp/ftp_transaction_factory.h +++ b/net/ftp/ftp_transaction_factory.h @@ -7,7 +7,7 @@ namespace net { -class AuthCache; +class FtpAuthCache; class FtpTransaction; // An interface to a class that can create FtpTransaction objects. @@ -19,7 +19,7 @@ class FtpTransactionFactory { virtual FtpTransaction* CreateTransaction() = 0; // Returns the associated FTP auth cache if any (may be NULL). - virtual AuthCache* GetAuthCache() = 0; + virtual FtpAuthCache* GetAuthCache() = 0; // Suspends the creation of new transactions. If |suspend| is false, creation // of new transactions is resumed. diff --git a/net/net.xcodeproj/project.pbxproj b/net/net.xcodeproj/project.pbxproj index d183dd9..e37f380 100644 --- a/net/net.xcodeproj/project.pbxproj +++ b/net/net.xcodeproj/project.pbxproj @@ -67,7 +67,6 @@ 7B82FF430E763602008F45CF /* host_resolver.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32B50E5A181C00A747DB /* host_resolver.cc */; }; 7B82FF460E763620008F45CF /* host_resolver_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7B82FF450E763620008F45CF /* host_resolver_unittest.cc */; }; 7B8502040E5A376900730B43 /* libgoogleurl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B8501FE0E5A372500730B43 /* libgoogleurl.a */; }; - 7B8502050E5A377100730B43 /* auth_cache_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32790E5A181C00A747DB /* auth_cache_unittest.cc */; }; 7B8502120E5A37A800730B43 /* base64_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32760E5A181C00A747DB /* base64_unittest.cc */; }; 7B85026D0E5A38D400730B43 /* libmodp_b64.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B85026A0E5A38BB00730B43 /* libmodp_b64.a */; }; 7B8503E90E5B2D4700730B43 /* address_list.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED327E0E5A181C00A747DB /* address_list.cc */; }; @@ -104,7 +103,6 @@ 7B8B5B9E0E5D188E002F9A97 /* registry_controlled_domain_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32990E5A181C00A747DB /* registry_controlled_domain_unittest.cc */; }; 7BA0151F0E5A1B9200044150 /* gzip_filter_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32B80E5A181C00A747DB /* gzip_filter_unittest.cc */; }; 7BA015210E5A1B9800044150 /* bzip2_filter_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32730E5A181C00A747DB /* bzip2_filter_unittest.cc */; }; - 7BA0152E0E5A1BF400044150 /* auth_cache.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED327C0E5A181C00A747DB /* auth_cache.cc */; }; 7BA015440E5A1BFA00044150 /* base64.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32770E5A181C00A747DB /* base64.cc */; }; 7BA0154C0E5A1C0400044150 /* filter.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32BC0E5A181C00A747DB /* filter.cc */; }; 7BA015510E5A1C0900044150 /* gzip_filter.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32BA0E5A181C00A747DB /* gzip_filter.cc */; }; @@ -165,8 +163,11 @@ A50055FE0EBF800D007B0A90 /* telnet_server.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED328D0E5A181C00A747DB /* telnet_server.cc */; }; A50055FF0EBF8018007B0A90 /* listen_socket.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32B30E5A181C00A747DB /* listen_socket.cc */; }; A5AB7BFC0EB7DBA10070A7D3 /* file_stream_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5AB7BFB0EB7DBA10070A7D3 /* file_stream_unittest.cc */; }; + B4DD1C3523B3890B287055E6 /* connection_type_histograms.cc in Sources */ = {isa = PBXBuildFile; fileRef = F17062083BCE6F0A42F4C479 /* connection_type_histograms.cc */; }; B5F622260E805FC40076681A /* url_request_job_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED33A30E5A198600A747DB /* url_request_job_manager.cc */; }; BAA46E3B0E5CE99A00E77460 /* net_util_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED329F0E5A181C00A747DB /* net_util_unittest.cc */; }; + C630F8F3C128BCFD5B403D7F /* ftp_auth_cache_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15C6370BF6FE62308A559648 /* ftp_auth_cache_unittest.cc */; }; + CC4B3509420B9663AAD7D16A /* ftp_auth_cache.cc in Sources */ = {isa = PBXBuildFile; fileRef = 0E81748E2B2E8B814DBB78EC /* ftp_auth_cache.cc */; }; DFC96EFA0EF9BC5D003C335B /* eviction.cc in Sources */ = {isa = PBXBuildFile; fileRef = DFC96EF80EF9BC5D003C335B /* eviction.cc */; }; DFEE18270E882E3600666107 /* stats_histogram.cc in Sources */ = {isa = PBXBuildFile; fileRef = DFEE18250E882E3600666107 /* stats_histogram.cc */; }; E4005E3A0E9FA63B0055B38E /* url_request_file_job.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED33B00E5A198600A747DB /* url_request_file_job.cc */; }; @@ -183,7 +184,6 @@ E4CE9C260E8C027900D5378C /* http_network_layer_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED335C0E5A194700A747DB /* http_network_layer_unittest.cc */; }; E4CE9C2E0E8C02ED00D5378C /* http_transaction_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED334A0E5A194700A747DB /* http_transaction_unittest.cc */; }; E4CE9C380E8C035C00D5378C /* http_network_transaction_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED33590E5A194700A747DB /* http_network_transaction_unittest.cc */; }; - B4DD1C3523B3890B287055E6 /* connection_type_histograms.cc in Sources */ = {isa = PBXBuildFile; fileRef = F17062083BCE6F0A42F4C479 /* connection_type_histograms.cc */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -438,6 +438,8 @@ 04C626D90E8DE3BA0067E92A /* http_auth_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_auth_unittest.cc; sourceTree = "<group>"; }; 04E7BD540EC4ECF60078FE58 /* http_auth_cache.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_auth_cache.cc; sourceTree = "<group>"; }; 04E7BD560EC4ED020078FE58 /* http_auth_cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = http_auth_cache.h; sourceTree = "<group>"; }; + 0E81748E2B2E8B814DBB78EC /* ftp_auth_cache.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ftp_auth_cache.cc; path = ftp/ftp_auth_cache.cc; sourceTree = SOURCE_ROOT; }; + 15C6370BF6FE62308A559648 /* ftp_auth_cache_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ftp_auth_cache_unittest.cc; path = ftp/ftp_auth_cache_unittest.cc; sourceTree = SOURCE_ROOT; }; 4D4C5C050EF1B8C5002CA805 /* filter_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = filter_unittest.cc; sourceTree = "<group>"; }; 533102E60E5E3EBF00FF8E32 /* net_util_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = net_util_posix.cc; sourceTree = "<group>"; }; 7B2630600E82F282001CE27F /* libevent.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libevent.xcodeproj; path = third_party/libevent/libevent.xcodeproj; sourceTree = "<group>"; }; @@ -494,10 +496,7 @@ 7BED32760E5A181C00A747DB /* base64_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = base64_unittest.cc; sourceTree = "<group>"; }; 7BED32770E5A181C00A747DB /* base64.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = base64.cc; sourceTree = "<group>"; }; 7BED32780E5A181C00A747DB /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = base64.h; sourceTree = "<group>"; }; - 7BED32790E5A181C00A747DB /* auth_cache_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = auth_cache_unittest.cc; sourceTree = "<group>"; }; - 7BED327A0E5A181C00A747DB /* auth_cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = auth_cache.h; sourceTree = "<group>"; }; 7BED327B0E5A181C00A747DB /* auth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = auth.h; sourceTree = "<group>"; }; - 7BED327C0E5A181C00A747DB /* auth_cache.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = auth_cache.cc; sourceTree = "<group>"; }; 7BED327D0E5A181C00A747DB /* address_list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = address_list.h; sourceTree = "<group>"; }; 7BED327E0E5A181C00A747DB /* address_list.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = address_list.cc; sourceTree = "<group>"; }; 7BED327F0E5A181C00A747DB /* x509_certificate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x509_certificate.h; sourceTree = "<group>"; }; @@ -686,6 +685,8 @@ 936882DC0E9154E200043405 /* file_stream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = file_stream.h; sourceTree = "<group>"; }; 93D11DCD0E91463000C36437 /* file_stream_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_stream_posix.cc; sourceTree = "<group>"; }; A5AB7BFB0EB7DBA10070A7D3 /* file_stream_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_stream_unittest.cc; sourceTree = "<group>"; }; + ACAB6D5C0F43A727D039E138 /* ftp_auth_cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ftp_auth_cache.h; path = ftp/ftp_auth_cache.h; sourceTree = SOURCE_ROOT; }; + D4726BC70CCE10F4FF2A5E12 /* connection_type_histograms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = connection_type_histograms.h; sourceTree = "<group>"; }; DFC96EF80EF9BC5D003C335B /* eviction.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = eviction.cc; sourceTree = "<group>"; }; DFC96EF90EF9BC5D003C335B /* eviction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = eviction.h; sourceTree = "<group>"; }; DFEE18250E882E3600666107 /* stats_histogram.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stats_histogram.cc; sourceTree = "<group>"; }; @@ -701,7 +702,6 @@ E4AFA6450E5241D300201347 /* base.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = base.xcodeproj; path = base/base.xcodeproj; sourceTree = "<group>"; }; E4BA04540E25613300BE02C6 /* libnet.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libnet.a; sourceTree = BUILT_PRODUCTS_DIR; }; F17062083BCE6F0A42F4C479 /* connection_type_histograms.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = connection_type_histograms.cc; sourceTree = "<group>"; }; - D4726BC70CCE10F4FF2A5E12 /* connection_type_histograms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = connection_type_histograms.h; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -747,6 +747,9 @@ 7BED31A20E5A15DD00A747DB /* Frameworks */, E4AFA62D0E52409300201347 /* Projects */, 1AB674ADFE9D54B511CA2CBB /* Products */, + 0E81748E2B2E8B814DBB78EC /* ftp_auth_cache.cc */, + ACAB6D5C0F43A727D039E138 /* ftp_auth_cache.h */, + 15C6370BF6FE62308A559648 /* ftp_auth_cache_unittest.cc */, ); name = zlib; sourceTree = "<group>"; @@ -884,9 +887,6 @@ 7BED327E0E5A181C00A747DB /* address_list.cc */, 7BED327D0E5A181C00A747DB /* address_list.h */, 7BED327B0E5A181C00A747DB /* auth.h */, - 7BED327C0E5A181C00A747DB /* auth_cache.cc */, - 7BED327A0E5A181C00A747DB /* auth_cache.h */, - 7BED32790E5A181C00A747DB /* auth_cache_unittest.cc */, 7BED32770E5A181C00A747DB /* base64.cc */, 7BED32780E5A181C00A747DB /* base64.h */, 7BED32760E5A181C00A747DB /* base64_unittest.cc */, @@ -1462,7 +1462,6 @@ buildActionMask = 2147483647; files = ( 7B8503E90E5B2D4700730B43 /* address_list.cc in Sources */, - 7BA0152E0E5A1BF400044150 /* auth_cache.cc in Sources */, 7B8503EA0E5B2D4F00730B43 /* backend_impl.cc in Sources */, 7BA015440E5A1BFA00044150 /* base64.cc in Sources */, 7B8503FC0E5B2DA200730B43 /* block_files.cc in Sources */, @@ -1485,6 +1484,7 @@ 7B8504150E5B2DF000730B43 /* file_posix.cc in Sources */, 93D11DCE0E91463000C36437 /* file_stream_posix.cc in Sources */, 7BA0154C0E5A1C0400044150 /* filter.cc in Sources */, + CC4B3509420B9663AAD7D16A /* ftp_auth_cache.cc in Sources */, 7BA015510E5A1C0900044150 /* gzip_filter.cc in Sources */, 7BA016A30E5A1EE900044150 /* gzip_header.cc in Sources */, 7B8504280E5B2E2A00730B43 /* hash.cc in Sources */, @@ -1553,7 +1553,6 @@ buildActionMask = 2147483647; files = ( 7B4DF6BD0E5B98F7004D7619 /* addr_unittest.cc in Sources */, - 7B8502050E5A377100730B43 /* auth_cache_unittest.cc in Sources */, 7BA3614C0E8C34390023C8B9 /* backend_unittest.cc in Sources */, 7B8502120E5A37A800730B43 /* base64_unittest.cc in Sources */, 7BD8F70C0E65DCD800034DE9 /* block_files_unittest.cc in Sources */, @@ -1569,6 +1568,7 @@ 7B4DF6B10E5B98ED004D7619 /* escape_unittest.cc in Sources */, A5AB7BFC0EB7DBA10070A7D3 /* file_stream_unittest.cc in Sources */, 4D4C5C060EF1B8C5002CA805 /* filter_unittest.cc in Sources */, + C630F8F3C128BCFD5B403D7F /* ftp_auth_cache_unittest.cc in Sources */, 7BA0151F0E5A1B9200044150 /* gzip_filter_unittest.cc in Sources */, 7B82FF460E763620008F45CF /* host_resolver_unittest.cc in Sources */, 042A4D480EC4F4500083281F /* http_auth_cache_unittest.cc in Sources */, diff --git a/net/net_lib.scons b/net/net_lib.scons index af94a53..9495a08 100644 --- a/net/net_lib.scons +++ b/net/net_lib.scons @@ -22,8 +22,6 @@ input_files = ChromeFileList([ 'base/address_list.cc', 'base/address_list.h', 'base/auth.h', - 'base/auth_cache.cc', - 'base/auth_cache.h', 'base/base64.cc', 'base/base64.h', 'base/bzip2_filter.cc', @@ -245,6 +243,8 @@ input_files = ChromeFileList([ 'proxy/proxy_service.h', ]), MSVSFilter('ftp', [ + 'ftp/ftp_auth_cache.cc', + 'ftp/ftp_auth_cache.h', 'ftp/ftp_network_layer.cc', 'ftp/ftp_network_layer.h', 'ftp/ftp_network_session.h', diff --git a/net/net_unittests.scons b/net/net_unittests.scons index fdbdf89..8f91e18 100644 --- a/net/net_unittests.scons +++ b/net/net_unittests.scons @@ -71,8 +71,10 @@ input_files = ChromeFileList([ 'http/http_util_unittest.cc', 'http/http_vary_data_unittest.cc', ]), + MSVSFilter('ftp', [ + 'ftp/ftp_auth_cache_unittest.cc', + ]), MSVSFilter('base', [ - 'base/auth_cache_unittest.cc', 'base/base64_unittest.cc', 'base/bzip2_filter_unittest.cc', 'base/client_socket_pool_unittest.cc', diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index ee05c9d..5941df8 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -15,8 +15,8 @@ #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "net/base/auth_cache.h" #include "net/base/cookie_policy.h" +#include "net/ftp/ftp_auth_cache.h" #include "net/http/http_transaction_factory.h" namespace net { @@ -50,8 +50,8 @@ class URLRequestContext : // Gets the cookie policy for this context. net::CookiePolicy* cookie_policy() { return &cookie_policy_; } - // Gets the FTP realm authentication cache for this context. - net::AuthCache* ftp_auth_cache() { return &ftp_auth_cache_; } + // Gets the FTP authentication cache for this context. + net::FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; } // Gets the UA string to use for this context. const std::string& user_agent() const { return user_agent_; } @@ -73,7 +73,7 @@ class URLRequestContext : net::HttpTransactionFactory* http_transaction_factory_; net::CookieMonster* cookie_store_; net::CookiePolicy cookie_policy_; - net::AuthCache ftp_auth_cache_; + net::FtpAuthCache ftp_auth_cache_; std::string user_agent_; std::string accept_language_; std::string accept_charset_; diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc index 7b72118..d63d248 100644 --- a/net/url_request/url_request_ftp_job.cc +++ b/net/url_request/url_request_ftp_job.cc @@ -127,7 +127,7 @@ void URLRequestFtpJob::SendRequest() { have_auth = true; username = WideToUTF8(server_auth_->username); password = WideToUTF8(server_auth_->password); - request_->context()->ftp_auth_cache()->Add(request_->url().host(), + request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(), server_auth_.get()); } else { if (request_->url().has_username()) { @@ -169,18 +169,17 @@ void URLRequestFtpJob::OnIOComplete(const AsyncResult& result) { case ERROR_INTERNET_INCORRECT_USER_NAME: // fall through case ERROR_INTERNET_INCORRECT_PASSWORD: { - // TODO(eroman): shouldn't the port be part of the key? - std::string cache_key = request_->url().host(); + GURL origin = request_->url().GetOrigin(); if (server_auth_ != NULL && server_auth_->state == net::AUTH_STATE_HAVE_AUTH) { - request_->context()->ftp_auth_cache()->Remove(cache_key); + request_->context()->ftp_auth_cache()->Remove(origin); } else { server_auth_ = new net::AuthData(); } server_auth_->state = net::AUTH_STATE_NEED_AUTH; scoped_refptr<net::AuthData> cached_auth = - request_->context()->ftp_auth_cache()->Lookup(cache_key); + request_->context()->ftp_auth_cache()->Lookup(origin); if (cached_auth) { // Retry using cached auth data. |