| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
| 6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
| 7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
| 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 9 * | 9 * |
| 10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
| (...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 CookieMonster::CookieItVector::iterator it_begin, | 1954 CookieMonster::CookieItVector::iterator it_begin, |
| 1955 CookieMonster::CookieItVector::iterator it_end) { | 1955 CookieMonster::CookieItVector::iterator it_end) { |
| 1956 for (CookieItVector::iterator it = it_begin; it != it_end; it++) { | 1956 for (CookieItVector::iterator it = it_begin; it != it_end; it++) { |
| 1957 histogram_evicted_last_access_minutes_->Add( | 1957 histogram_evicted_last_access_minutes_->Add( |
| 1958 (current - (*it)->second->LastAccessDate()).InMinutes()); | 1958 (current - (*it)->second->LastAccessDate()).InMinutes()); |
| 1959 InternalDeleteCookie((*it), true, cause); | 1959 InternalDeleteCookie((*it), true, cause); |
| 1960 } | 1960 } |
| 1961 return it_end - it_begin; | 1961 return it_end - it_begin; |
| 1962 } | 1962 } |
| 1963 | 1963 |
| 1964 // A wrapper around RegistryControlledDomainService::GetDomainAndRegistry | 1964 // A wrapper around registry_controlled_domains::GetDomainAndRegistry |
| 1965 // to make clear we're creating a key for our local map. Here and | 1965 // to make clear we're creating a key for our local map. Here and |
| 1966 // in FindCookiesForHostAndDomain() are the only two places where | 1966 // in FindCookiesForHostAndDomain() are the only two places where |
| 1967 // we need to conditionalize based on key type. | 1967 // we need to conditionalize based on key type. |
| 1968 // | 1968 // |
| 1969 // Note that this key algorithm explicitly ignores the scheme. This is | 1969 // Note that this key algorithm explicitly ignores the scheme. This is |
| 1970 // because when we're entering cookies into the map from the backing store, | 1970 // because when we're entering cookies into the map from the backing store, |
| 1971 // we in general won't have the scheme at that point. | 1971 // we in general won't have the scheme at that point. |
| 1972 // In practical terms, this means that file cookies will be stored | 1972 // In practical terms, this means that file cookies will be stored |
| 1973 // in the map either by an empty string or by UNC name (and will be | 1973 // in the map either by an empty string or by UNC name (and will be |
| 1974 // limited by kMaxCookiesPerHost), and extension cookies will be stored | 1974 // limited by kMaxCookiesPerHost), and extension cookies will be stored |
| 1975 // based on the single extension id, as the extension id won't have the | 1975 // based on the single extension id, as the extension id won't have the |
| 1976 // form of a DNS host and hence GetKey() will return it unchanged. | 1976 // form of a DNS host and hence GetKey() will return it unchanged. |
| 1977 // | 1977 // |
| 1978 // Arguably the right thing to do here is to make the key | 1978 // Arguably the right thing to do here is to make the key |
| 1979 // algorithm dependent on the scheme, and make sure that the scheme is | 1979 // algorithm dependent on the scheme, and make sure that the scheme is |
| 1980 // available everywhere the key must be obtained (specfically at backing | 1980 // available everywhere the key must be obtained (specfically at backing |
| 1981 // store load time). This would require either changing the backing store | 1981 // store load time). This would require either changing the backing store |
| 1982 // database schema to include the scheme (far more trouble than it's worth), or | 1982 // database schema to include the scheme (far more trouble than it's worth), or |
| 1983 // separating out file cookies into their own CookieMonster instance and | 1983 // separating out file cookies into their own CookieMonster instance and |
| 1984 // thus restricting each scheme to a single cookie monster (which might | 1984 // thus restricting each scheme to a single cookie monster (which might |
| 1985 // be worth it, but is still too much trouble to solve what is currently a | 1985 // be worth it, but is still too much trouble to solve what is currently a |
| 1986 // non-problem). | 1986 // non-problem). |
| 1987 std::string CookieMonster::GetKey(const std::string& domain) const { | 1987 std::string CookieMonster::GetKey(const std::string& domain) const { |
| 1988 std::string effective_domain( | 1988 std::string effective_domain( |
| 1989 RegistryControlledDomainService::GetDomainAndRegistry(domain)); | 1989 registry_controlled_domains::GetDomainAndRegistry( |
| 1990 domain, registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)); |
| 1990 if (effective_domain.empty()) | 1991 if (effective_domain.empty()) |
| 1991 effective_domain = domain; | 1992 effective_domain = domain; |
| 1992 | 1993 |
| 1993 if (!effective_domain.empty() && effective_domain[0] == '.') | 1994 if (!effective_domain.empty() && effective_domain[0] == '.') |
| 1994 return effective_domain.substr(1); | 1995 return effective_domain.substr(1); |
| 1995 return effective_domain; | 1996 return effective_domain; |
| 1996 } | 1997 } |
| 1997 | 1998 |
| 1998 bool CookieMonster::IsCookieableScheme(const std::string& scheme) { | 1999 bool CookieMonster::IsCookieableScheme(const std::string& scheme) { |
| 1999 base::AutoLock autolock(lock_); | 2000 base::AutoLock autolock(lock_); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2149 | 2150 |
| 2150 // The system resolution is not high enough, so we can have multiple | 2151 // The system resolution is not high enough, so we can have multiple |
| 2151 // set cookies that result in the same system time. When this happens, we | 2152 // set cookies that result in the same system time. When this happens, we |
| 2152 // increment by one Time unit. Let's hope computers don't get too fast. | 2153 // increment by one Time unit. Let's hope computers don't get too fast. |
| 2153 Time CookieMonster::CurrentTime() { | 2154 Time CookieMonster::CurrentTime() { |
| 2154 return std::max(Time::Now(), | 2155 return std::max(Time::Now(), |
| 2155 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2156 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
| 2156 } | 2157 } |
| 2157 | 2158 |
| 2158 } // namespace net | 2159 } // namespace net |
| OLD | NEW |