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 #include "net/ftp/ftp_auth_cache.h"
7 #include "base/logging.h"
13 const size_t FtpAuthCache::kMaxEntries
= 10;
15 FtpAuthCache::Entry::Entry(const GURL
& origin
,
16 const AuthCredentials
& credentials
)
18 credentials(credentials
) {
21 FtpAuthCache::Entry::~Entry() {}
23 FtpAuthCache::FtpAuthCache() {}
25 FtpAuthCache::~FtpAuthCache() {}
27 FtpAuthCache::Entry
* FtpAuthCache::Lookup(const GURL
& origin
) {
28 for (EntryList::iterator it
= entries_
.begin(); it
!= entries_
.end(); ++it
) {
29 if (it
->origin
== origin
)
35 void FtpAuthCache::Add(const GURL
& origin
, const AuthCredentials
& credentials
) {
36 DCHECK(origin
.SchemeIs("ftp"));
37 DCHECK_EQ(origin
.GetOrigin(), origin
);
39 Entry
* entry
= Lookup(origin
);
41 entry
->credentials
= credentials
;
43 entries_
.push_front(Entry(origin
, credentials
));
45 // Prevent unbound memory growth of the cache.
46 if (entries_
.size() > kMaxEntries
)
51 void FtpAuthCache::Remove(const GURL
& origin
,
52 const AuthCredentials
& credentials
) {
53 for (EntryList::iterator it
= entries_
.begin(); it
!= entries_
.end(); ++it
) {
54 if (it
->origin
== origin
&& it
->credentials
.Equals(credentials
)) {
56 DCHECK(!Lookup(origin
));