diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 22:16:53 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 22:16:53 +0000 |
commit | 0a78913b92ee56625e18e91f55c00c22c53c517a (patch) | |
tree | 6c98dd541ffa2fbcb22b522659d95b589717f7ad /net/ftp/ftp_auth_cache.h | |
parent | 4fcbf00281b3564d9ae4c42817442bf87b29b6e0 (diff) | |
download | chromium_src-0a78913b92ee56625e18e91f55c00c22c53c517a.zip chromium_src-0a78913b92ee56625e18e91f55c00c22c53c517a.tar.gz chromium_src-0a78913b92ee56625e18e91f55c00c22c53c517a.tar.bz2 |
Enforce maximum number of entries in FtpAuthCache.
TEST=Covered by net_unittests.
BUG=none
Review URL: http://codereview.chromium.org/165167
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23094 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp/ftp_auth_cache.h')
-rw-r--r-- | net/ftp/ftp_auth_cache.h | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/net/ftp/ftp_auth_cache.h b/net/ftp/ftp_auth_cache.h index 1286511..c63828d 100644 --- a/net/ftp/ftp_auth_cache.h +++ b/net/ftp/ftp_auth_cache.h @@ -5,12 +5,10 @@ #ifndef NET_FTP_FTP_AUTH_CACHE_H_ #define NET_FTP_FTP_AUTH_CACHE_H_ -#include <string> -#include <map> +#include <list> #include "net/base/auth.h" - -class GURL; +#include "googleurl/src/gurl.h" namespace net { @@ -27,6 +25,9 @@ class FtpAuthCache { FtpAuthCache() {} ~FtpAuthCache() {} + // Maximum number of entries we allow in the cache. + static const size_t kMaxEntries; + // 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). @@ -34,22 +35,29 @@ class FtpAuthCache { // 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); + void Add(const GURL& origin, AuthData* auth_data); // 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; + struct Entry { + Entry(const GURL& origin, AuthData* auth_data) + : origin(origin), + auth_data(auth_data) { + } + + const GURL origin; + scoped_refptr<AuthData> auth_data; + }; + typedef std::list<Entry> EntryList; - // Get the key in hash table |cache_| where entries for ftp server |origin| - // should be saved. - static AuthCacheKey MakeKey(const GURL& origin); + // Return Entry corresponding to given |origin| or NULL if not found. + Entry* LookupByOrigin(const GURL& origin); - // internal representation of cache, an STL map. - AuthCacheMap cache_; + // Internal representation of cache, an STL list. This makes lookups O(n), + // but we expect n to be very low. + EntryList entries_; }; } // namespace net |