OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <string> | |
11 | 10 |
| 11 #include "base/string16.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 // The FtpAuthCache class is a simple cache structure to store authentication | 16 // The FtpAuthCache class is a simple cache structure to store authentication |
17 // information for ftp. Provides lookup, insertion, and deletion of entries. | 17 // information for ftp. Provides lookup, insertion, and deletion of entries. |
18 // The parameter for doing lookups, insertions, and deletions is a GURL of the | 18 // The parameter for doing lookups, insertions, and deletions is a GURL of the |
19 // server's address (not a full URL with path, since FTP auth isn't per path). | 19 // server's address (not a full URL with path, since FTP auth isn't per path). |
20 // For example: | 20 // For example: |
21 // GURL("ftp://myserver") -- OK (implied port of 21) | 21 // GURL("ftp://myserver") -- OK (implied port of 21) |
22 // GURL("ftp://myserver:21") -- OK | 22 // GURL("ftp://myserver:21") -- OK |
23 // GURL("ftp://myserver/PATH") -- WRONG, paths not allowed | 23 // GURL("ftp://myserver/PATH") -- WRONG, paths not allowed |
24 class FtpAuthCache { | 24 class FtpAuthCache { |
25 public: | 25 public: |
26 // Maximum number of entries we allow in the cache. | 26 // Maximum number of entries we allow in the cache. |
27 static const size_t kMaxEntries; | 27 static const size_t kMaxEntries; |
28 | 28 |
29 struct Entry { | 29 struct Entry { |
30 Entry(const GURL& origin, const std::wstring& username, | 30 Entry(const GURL& origin, const string16& username, |
31 const std::wstring& password) | 31 const string16& password) |
32 : origin(origin), | 32 : origin(origin), |
33 username(username), | 33 username(username), |
34 password(password) { | 34 password(password) { |
35 } | 35 } |
36 | 36 |
37 const GURL origin; | 37 const GURL origin; |
38 std::wstring username; | 38 string16 username; |
39 std::wstring password; | 39 string16 password; |
40 }; | 40 }; |
41 | 41 |
42 FtpAuthCache() {} | 42 FtpAuthCache() {} |
43 ~FtpAuthCache() {} | 43 ~FtpAuthCache() {} |
44 | 44 |
45 // Return Entry corresponding to given |origin| or NULL if not found. | 45 // Return Entry corresponding to given |origin| or NULL if not found. |
46 Entry* Lookup(const GURL& origin); | 46 Entry* Lookup(const GURL& origin); |
47 | 47 |
48 // Add an entry for |origin| to the cache (consisting of |username| and | 48 // Add an entry for |origin| to the cache (consisting of |username| and |
49 // |password|). If there is already an entry for |origin|, it will be | 49 // |password|). If there is already an entry for |origin|, it will be |
50 // overwritten. | 50 // overwritten. |
51 void Add(const GURL& origin, const std::wstring& username, | 51 void Add(const GURL& origin, const string16& username, |
52 const std::wstring& password); | 52 const string16& password); |
53 | 53 |
54 // Remove the entry for |origin| from the cache, if one exists and matches | 54 // Remove the entry for |origin| from the cache, if one exists and matches |
55 // |username| and |password|. | 55 // |username| and |password|. |
56 void Remove(const GURL& origin, const std::wstring& username, | 56 void Remove(const GURL& origin, const string16& username, |
57 const std::wstring& password); | 57 const string16& password); |
58 | 58 |
59 private: | 59 private: |
60 typedef std::list<Entry> EntryList; | 60 typedef std::list<Entry> EntryList; |
61 | 61 |
62 // 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), |
63 // but we expect n to be very low. | 63 // but we expect n to be very low. |
64 EntryList entries_; | 64 EntryList entries_; |
65 }; | 65 }; |
66 | 66 |
67 } // namespace net | 67 } // namespace net |
68 | 68 |
69 #endif // NET_FTP_FTP_AUTH_CACHE_H_ | 69 #endif // NET_FTP_FTP_AUTH_CACHE_H_ |
OLD | NEW |