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 #include "content/browser/ssl/ssl_host_state.h" | 5 #include "content/browser/ssl/ssl_host_state.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
| 10 #include "net/http/http_transaction_factory.h" |
| 11 #include "net/url_request/url_request_context.h" |
| 12 #include "net/url_request/url_request_context_getter.h" |
10 | 13 |
11 const char kKeyName[] = "content_ssl_host_state"; | 14 const char kKeyName[] = "content_ssl_host_state"; |
12 | 15 |
| 16 namespace { |
| 17 |
| 18 void CloseIdleConnections( |
| 19 const std::string& host, |
| 20 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) { |
| 21 url_request_context_getter->GetURLRequestContext() |
| 22 ->http_transaction_factory() |
| 23 ->GetSession() |
| 24 ->CloseIdleConnections(); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
13 namespace content { | 29 namespace content { |
14 | 30 |
15 SSLHostState* SSLHostState::GetFor(BrowserContext* context) { | 31 SSLHostState* SSLHostState::GetFor(BrowserContext* context) { |
16 SSLHostState* rv = static_cast<SSLHostState*>(context->GetUserData(kKeyName)); | 32 SSLHostState* rv = static_cast<SSLHostState*>(context->GetUserData(kKeyName)); |
17 if (!rv) { | 33 if (!rv) { |
18 rv = new SSLHostState(); | 34 rv = new SSLHostState(); |
| 35 rv->browser_context_ = context; |
19 context->SetUserData(kKeyName, rv); | 36 context->SetUserData(kKeyName, rv); |
20 } | 37 } |
21 return rv; | 38 return rv; |
22 } | 39 } |
23 | 40 |
24 SSLHostState::SSLHostState() { | 41 SSLHostState::SSLHostState() { |
25 } | 42 } |
26 | 43 |
27 SSLHostState::~SSLHostState() { | 44 SSLHostState::~SSLHostState() { |
28 } | 45 } |
(...skipping 24 matching lines...) Expand all Loading... |
53 | 70 |
54 cert_policy_for_host_[host].Allow(cert, error); | 71 cert_policy_for_host_[host].Allow(cert, error); |
55 } | 72 } |
56 | 73 |
57 void SSLHostState::Clear() { | 74 void SSLHostState::Clear() { |
58 DCHECK(CalledOnValidThread()); | 75 DCHECK(CalledOnValidThread()); |
59 | 76 |
60 cert_policy_for_host_.clear(); | 77 cert_policy_for_host_.clear(); |
61 } | 78 } |
62 | 79 |
| 80 void SSLHostState::RevokeAllowAndDenyPreferences(const std::string& host) { |
| 81 DCHECK(CalledOnValidThread()); |
| 82 |
| 83 cert_policy_for_host_.erase(cert_policy_for_host_.find(host)); |
| 84 scoped_refptr<net::URLRequestContextGetter> getter( |
| 85 browser_context_->GetRequestContext()); |
| 86 browser_context_->GetRequestContext()->GetNetworkTaskRunner()->PostTask( |
| 87 FROM_HERE, base::Bind(&CloseIdleConnections, host, getter)); |
| 88 } |
| 89 |
| 90 bool SSLHostState::HasAllowedOrDeniedCert(const std::string& host) { |
| 91 DCHECK(CalledOnValidThread()); |
| 92 |
| 93 return cert_policy_for_host_[host].HasAllowedCert() || |
| 94 cert_policy_for_host_[host].HasDeniedCert(); |
| 95 } |
| 96 |
63 net::CertPolicy::Judgment SSLHostState::QueryPolicy(net::X509Certificate* cert, | 97 net::CertPolicy::Judgment SSLHostState::QueryPolicy(net::X509Certificate* cert, |
64 const std::string& host, | 98 const std::string& host, |
65 net::CertStatus error) { | 99 net::CertStatus error) { |
66 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
67 | 101 |
68 return cert_policy_for_host_[host].Check(cert, error); | 102 return cert_policy_for_host_[host].Check(cert, error); |
69 } | 103 } |
70 | 104 |
71 } // namespace content | 105 } // namespace content |
OLD | NEW |