OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "net/ftp/ftp_auth_cache.h" | 5 #include "net/ftp/ftp_auth_cache.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "url/gurl.h" | |
9 | 8 |
10 namespace net { | 9 namespace net { |
11 | 10 |
12 // static | 11 // static |
13 const size_t FtpAuthCache::kMaxEntries = 10; | 12 const size_t FtpAuthCache::kMaxEntries = 10; |
14 | 13 |
15 FtpAuthCache::Entry::Entry(const GURL& origin, | 14 FtpAuthCache::Entry::Entry(const url::Origin& origin, |
16 const AuthCredentials& credentials) | 15 const AuthCredentials& credentials) |
17 : origin(origin), | 16 : origin(origin), credentials(credentials) { |
18 credentials(credentials) { | |
19 } | 17 } |
20 | 18 |
21 FtpAuthCache::Entry::~Entry() {} | 19 FtpAuthCache::Entry::~Entry() {} |
22 | 20 |
23 FtpAuthCache::FtpAuthCache() {} | 21 FtpAuthCache::FtpAuthCache() {} |
24 | 22 |
25 FtpAuthCache::~FtpAuthCache() {} | 23 FtpAuthCache::~FtpAuthCache() {} |
26 | 24 |
27 FtpAuthCache::Entry* FtpAuthCache::Lookup(const GURL& origin) { | 25 FtpAuthCache::Entry* FtpAuthCache::Lookup(const url::Origin& origin) { |
28 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { | 26 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { |
29 if (it->origin == origin) | 27 if (it->origin == origin) |
30 return &(*it); | 28 return &(*it); |
31 } | 29 } |
32 return NULL; | 30 return nullptr; |
33 } | 31 } |
34 | 32 |
35 void FtpAuthCache::Add(const GURL& origin, const AuthCredentials& credentials) { | 33 void FtpAuthCache::Add(const url::Origin& origin, |
| 34 const AuthCredentials& credentials) { |
36 DCHECK(origin.SchemeIs("ftp")); | 35 DCHECK(origin.SchemeIs("ftp")); |
37 DCHECK_EQ(origin.GetOrigin(), origin); | |
38 | 36 |
39 Entry* entry = Lookup(origin); | 37 Entry* entry = Lookup(origin); |
40 if (entry) { | 38 if (entry) { |
41 entry->credentials = credentials; | 39 entry->credentials = credentials; |
42 } else { | 40 } else { |
43 entries_.push_front(Entry(origin, credentials)); | 41 entries_.push_front(Entry(origin, credentials)); |
44 | 42 |
45 // Prevent unbound memory growth of the cache. | 43 // Prevent unbound memory growth of the cache. |
46 if (entries_.size() > kMaxEntries) | 44 if (entries_.size() > kMaxEntries) |
47 entries_.pop_back(); | 45 entries_.pop_back(); |
48 } | 46 } |
49 } | 47 } |
50 | 48 |
51 void FtpAuthCache::Remove(const GURL& origin, | 49 void FtpAuthCache::Remove(const url::Origin& origin, |
52 const AuthCredentials& credentials) { | 50 const AuthCredentials& credentials) { |
53 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { | 51 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { |
54 if (it->origin == origin && it->credentials.Equals(credentials)) { | 52 if (it->origin == origin && it->credentials.Equals(credentials)) { |
55 entries_.erase(it); | 53 entries_.erase(it); |
56 DCHECK(!Lookup(origin)); | 54 DCHECK(!Lookup(origin)); |
57 return; | 55 return; |
58 } | 56 } |
59 } | 57 } |
60 } | 58 } |
61 | 59 |
62 } // namespace net | 60 } // namespace net |
OLD | NEW |