| OLD | NEW |
| 1 // Copyright (c) 2010 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 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 string16& username, | 30 Entry(const GURL& origin, const string16& username, |
| 31 const string16& password) | 31 const string16& password); |
| 32 : origin(origin), | 32 ~Entry(); |
| 33 username(username), | |
| 34 password(password) { | |
| 35 } | |
| 36 | 33 |
| 37 const GURL origin; | 34 const GURL origin; |
| 38 string16 username; | 35 string16 username; |
| 39 string16 password; | 36 string16 password; |
| 40 }; | 37 }; |
| 41 | 38 |
| 42 FtpAuthCache() {} | 39 FtpAuthCache(); |
| 43 ~FtpAuthCache() {} | 40 ~FtpAuthCache(); |
| 44 | 41 |
| 45 // Return Entry corresponding to given |origin| or NULL if not found. | 42 // Return Entry corresponding to given |origin| or NULL if not found. |
| 46 Entry* Lookup(const GURL& origin); | 43 Entry* Lookup(const GURL& origin); |
| 47 | 44 |
| 48 // Add an entry for |origin| to the cache (consisting of |username| and | 45 // 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 | 46 // |password|). If there is already an entry for |origin|, it will be |
| 50 // overwritten. | 47 // overwritten. |
| 51 void Add(const GURL& origin, const string16& username, | 48 void Add(const GURL& origin, const string16& username, |
| 52 const string16& password); | 49 const string16& password); |
| 53 | 50 |
| 54 // Remove the entry for |origin| from the cache, if one exists and matches | 51 // Remove the entry for |origin| from the cache, if one exists and matches |
| 55 // |username| and |password|. | 52 // |username| and |password|. |
| 56 void Remove(const GURL& origin, const string16& username, | 53 void Remove(const GURL& origin, const string16& username, |
| 57 const string16& password); | 54 const string16& password); |
| 58 | 55 |
| 59 private: | 56 private: |
| 60 typedef std::list<Entry> EntryList; | 57 typedef std::list<Entry> EntryList; |
| 61 | 58 |
| 62 // Internal representation of cache, an STL list. This makes lookups O(n), | 59 // Internal representation of cache, an STL list. This makes lookups O(n), |
| 63 // but we expect n to be very low. | 60 // but we expect n to be very low. |
| 64 EntryList entries_; | 61 EntryList entries_; |
| 65 }; | 62 }; |
| 66 | 63 |
| 67 } // namespace net | 64 } // namespace net |
| 68 | 65 |
| 69 #endif // NET_FTP_FTP_AUTH_CACHE_H_ | 66 #endif // NET_FTP_FTP_AUTH_CACHE_H_ |
| OLD | NEW |