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

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

Issue 8340026: Use AuthCredentials throughout the network stack instead of username/password. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix comments Created 9 years, 1 month 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
« no previous file with comments | « net/ftp/ftp_auth_cache.h ('k') | net/ftp/ftp_auth_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #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 "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 // static 12 // static
13 const size_t FtpAuthCache::kMaxEntries = 10; 13 const size_t FtpAuthCache::kMaxEntries = 10;
14 14
15 FtpAuthCache::Entry::Entry(const GURL& origin, 15 FtpAuthCache::Entry::Entry(const GURL& origin,
16 const string16& username, 16 const AuthCredentials& credentials)
17 const string16& password)
18 : origin(origin), 17 : origin(origin),
19 username(username), 18 credentials(credentials) {
20 password(password) {
21 } 19 }
22 20
23 FtpAuthCache::Entry::~Entry() {} 21 FtpAuthCache::Entry::~Entry() {}
24 22
25 FtpAuthCache::FtpAuthCache() {} 23 FtpAuthCache::FtpAuthCache() {}
26 24
27 FtpAuthCache::~FtpAuthCache() {} 25 FtpAuthCache::~FtpAuthCache() {}
28 26
29 FtpAuthCache::Entry* FtpAuthCache::Lookup(const GURL& origin) { 27 FtpAuthCache::Entry* FtpAuthCache::Lookup(const GURL& origin) {
30 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { 28 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) {
31 if (it->origin == origin) 29 if (it->origin == origin)
32 return &(*it); 30 return &(*it);
33 } 31 }
34 return NULL; 32 return NULL;
35 } 33 }
36 34
37 void FtpAuthCache::Add(const GURL& origin, const string16& username, 35 void FtpAuthCache::Add(const GURL& origin, const AuthCredentials& credentials) {
38 const string16& password) {
39 DCHECK(origin.SchemeIs("ftp")); 36 DCHECK(origin.SchemeIs("ftp"));
40 DCHECK_EQ(origin.GetOrigin(), origin); 37 DCHECK_EQ(origin.GetOrigin(), origin);
41 38
42 Entry* entry = Lookup(origin); 39 Entry* entry = Lookup(origin);
43 if (entry) { 40 if (entry) {
44 entry->username = username; 41 entry->credentials = credentials;
45 entry->password = password;
46 } else { 42 } else {
47 entries_.push_front(Entry(origin, username, password)); 43 entries_.push_front(Entry(origin, credentials));
48 44
49 // Prevent unbound memory growth of the cache. 45 // Prevent unbound memory growth of the cache.
50 if (entries_.size() > kMaxEntries) 46 if (entries_.size() > kMaxEntries)
51 entries_.pop_back(); 47 entries_.pop_back();
52 } 48 }
53 } 49 }
54 50
55 void FtpAuthCache::Remove(const GURL& origin, const string16& username, 51 void FtpAuthCache::Remove(const GURL& origin,
56 const string16& password) { 52 const AuthCredentials& credentials) {
57 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { 53 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) {
58 if (it->origin == origin && it->username == username && 54 if (it->origin == origin && it->credentials.Equals(credentials)) {
59 it->password == password) {
60 entries_.erase(it); 55 entries_.erase(it);
61 DCHECK(!Lookup(origin)); 56 DCHECK(!Lookup(origin));
62 return; 57 return;
63 } 58 }
64 } 59 }
65 } 60 }
66 61
67 } // namespace net 62 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_auth_cache.h ('k') | net/ftp/ftp_auth_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698