Updating trunk VERSION from 1014.0 to 1015.0
[chromium-blink-merge.git] / net / ftp / ftp_auth_cache.h
blob393b23daa86209dc92d2ebb0fae132ba846e2f5d
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_FTP_FTP_AUTH_CACHE_H_
6 #define NET_FTP_FTP_AUTH_CACHE_H_
7 #pragma once
9 #include <list>
11 #include "googleurl/src/gurl.h"
12 #include "net/base/auth.h"
13 #include "net/base/net_export.h"
15 namespace net {
17 // The FtpAuthCache class is a simple cache structure to store authentication
18 // information for ftp. Provides lookup, insertion, and deletion of entries.
19 // The parameter for doing lookups, insertions, and deletions is a GURL of the
20 // server's address (not a full URL with path, since FTP auth isn't per path).
21 // For example:
22 // GURL("ftp://myserver") -- OK (implied port of 21)
23 // GURL("ftp://myserver:21") -- OK
24 // GURL("ftp://myserver/PATH") -- WRONG, paths not allowed
25 class NET_EXPORT_PRIVATE FtpAuthCache {
26 public:
27 // Maximum number of entries we allow in the cache.
28 static const size_t kMaxEntries;
30 struct Entry {
31 Entry(const GURL& origin, const AuthCredentials& credentials);
32 ~Entry();
34 const GURL origin;
35 AuthCredentials credentials;
38 FtpAuthCache();
39 ~FtpAuthCache();
41 // Return Entry corresponding to given |origin| or NULL if not found.
42 Entry* Lookup(const GURL& origin);
44 // Add an entry for |origin| to the cache using |credentials|. If there is
45 // already an entry for |origin|, it will be overwritten.
46 void Add(const GURL& origin, const AuthCredentials& credentials);
48 // Remove the entry for |origin| from the cache, if one exists and matches
49 // |credentials|.
50 void Remove(const GURL& origin, const AuthCredentials& credentials);
52 private:
53 typedef std::list<Entry> EntryList;
55 // Internal representation of cache, an STL list. This makes lookups O(n),
56 // but we expect n to be very low.
57 EntryList entries_;
60 } // namespace net
62 #endif // NET_FTP_FTP_AUTH_CACHE_H_