Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: net/ftp/ftp_auth_cache.h

Issue 201083: Cache login identity for NewFTP transactions. (Closed)
Patch Set: better Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_FTP_FTP_AUTH_CACHE_H_ 5 #ifndef NET_FTP_FTP_AUTH_CACHE_H_
6 #define NET_FTP_FTP_AUTH_CACHE_H_ 6 #define NET_FTP_FTP_AUTH_CACHE_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string>
9 10
10 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
11 #include "net/base/auth.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 // The FtpAuthCache class is a simple cache structure to store authentication 15 // The FtpAuthCache class is a simple cache structure to store authentication
16 // information for ftp. Provides lookup, insertion, and deletion of entries. 16 // information for ftp. Provides lookup, insertion, and deletion of entries.
17 // The parameter for doing lookups, insertions, and deletions is a GURL of the 17 // The parameter for doing lookups, insertions, and deletions is a GURL of the
18 // server's address (not a full URL with path, since FTP auth isn't per path). 18 // server's address (not a full URL with path, since FTP auth isn't per path).
19 // For example: 19 // For example:
20 // GURL("ftp://myserver") -- OK (implied port of 21) 20 // GURL("ftp://myserver") -- OK (implied port of 21)
21 // GURL("ftp://myserver:21") -- OK 21 // GURL("ftp://myserver:21") -- OK
22 // GURL("ftp://myserver/PATH") -- WRONG, paths not allowed 22 // GURL("ftp://myserver/PATH") -- WRONG, paths not allowed
23 class FtpAuthCache { 23 class FtpAuthCache {
24 public: 24 public:
25 // Maximum number of entries we allow in the cache. 25 // Maximum number of entries we allow in the cache.
26 static const size_t kMaxEntries; 26 static const size_t kMaxEntries;
27 27
28 struct Entry {
29 Entry(const GURL& origin,
30 const std::wstring& username,
31 const std::wstring& password)
32 : origin(origin),
33 username(username),
34 password(password) {
35 }
36
37 const GURL origin;
38 std::wstring username;
39 std::wstring password;
40 };
41
28 FtpAuthCache() {} 42 FtpAuthCache() {}
29 ~FtpAuthCache() {} 43 ~FtpAuthCache() {}
30 44
31 // Check if we have authentication data for ftp server at |origin|. 45 // Return Entry corresponding to given |origin| or NULL if not found.
32 // Returns the address of corresponding AuthData object (if found) or NULL 46 Entry* Lookup(const GURL& origin);
33 // (if not found).
34 AuthData* Lookup(const GURL& origin);
35 47
36 // Add an entry for |origin| to the cache. If there is already an 48 // Add an entry for |origin| to the cache (consisting of |username| and
37 // entry for |origin|, it will be overwritten. Both parameters are IN only. 49 // |password|). If there is already an entry for |origin|, it will be
38 void Add(const GURL& origin, AuthData* auth_data); 50 // overwritten.
51 void Add(const GURL& origin, const std::wstring& username,
52 const std::wstring& password);
39 53
40 // Remove the entry for |origin| from the cache, if one exists. 54 // Remove the entry for |origin| from the cache, if one exists and matches
41 void Remove(const GURL& origin); 55 // |username| and |password|.
56 void Remove(const GURL& origin, const std::wstring& username,
57 const std::wstring& password);
42 58
43 private: 59 private:
44 struct Entry {
45 Entry(const GURL& origin, AuthData* auth_data)
46 : origin(origin),
47 auth_data(auth_data) {
48 }
49
50 const GURL origin;
51 scoped_refptr<AuthData> auth_data;
52 };
53 typedef std::list<Entry> EntryList; 60 typedef std::list<Entry> EntryList;
54 61
55 // Return Entry corresponding to given |origin| or NULL if not found.
56 Entry* LookupEntry(const GURL& origin);
57
58 // Internal representation of cache, an STL list. This makes lookups O(n), 62 // Internal representation of cache, an STL list. This makes lookups O(n),
59 // but we expect n to be very low. 63 // but we expect n to be very low.
60 EntryList entries_; 64 EntryList entries_;
61 }; 65 };
62 66
63 } // namespace net 67 } // namespace net
64 68
65 #endif // NET_FTP_FTP_AUTH_CACHE_H_ 69 #endif // NET_FTP_FTP_AUTH_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698