| OLD | NEW |
| 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 "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/notification_details.h" | 9 #include "content/public/browser/browser_context.h" |
| 10 #include "content/public/browser/notification_source.h" | |
| 11 #include "content/public/browser/notification_types.h" | |
| 12 | 10 |
| 13 namespace { | 11 static const char* kKeyName = "content_ssl_host_state"; |
| 14 typedef std::map<content::BrowserContext*, SSLHostState*> HostStateMap; | 12 |
| 15 static base::LazyInstance<HostStateMap> g_host_state_map = | 13 SSLHostState* SSLHostState::GetFor(content::BrowserContext* context) { |
| 16 LAZY_INSTANCE_INITIALIZER; | 14 SSLHostState* rv = static_cast<SSLHostState*>(context->GetUserData(kKeyName)); |
| 15 if (!rv) { |
| 16 rv = new SSLHostState(); |
| 17 context->SetUserData(kKeyName, rv); |
| 18 } |
| 19 return rv; |
| 17 } | 20 } |
| 18 | 21 |
| 19 SSLHostState* SSLHostState::GetFor(content::BrowserContext* browser_context) { | 22 SSLHostState::SSLHostState() { |
| 20 if (!g_host_state_map.Get().count(browser_context)) | |
| 21 g_host_state_map.Get()[browser_context] = new SSLHostState(browser_context); | |
| 22 return g_host_state_map.Get()[browser_context]; | |
| 23 } | |
| 24 | |
| 25 SSLHostState::SSLHostState(content::BrowserContext* browser_context) { | |
| 26 registrar_.Add(this, content::NOTIFICATION_BROWSER_CONTEXT_DESTRUCTION, | |
| 27 content::Source<content::BrowserContext>(browser_context)); | |
| 28 } | 23 } |
| 29 | 24 |
| 30 SSLHostState::~SSLHostState() { | 25 SSLHostState::~SSLHostState() { |
| 31 } | 26 } |
| 32 | 27 |
| 33 void SSLHostState::HostRanInsecureContent(const std::string& host, int pid) { | 28 void SSLHostState::HostRanInsecureContent(const std::string& host, int pid) { |
| 34 DCHECK(CalledOnValidThread()); | 29 DCHECK(CalledOnValidThread()); |
| 35 ran_insecure_content_hosts_.insert(BrokenHostEntry(host, pid)); | 30 ran_insecure_content_hosts_.insert(BrokenHostEntry(host, pid)); |
| 36 } | 31 } |
| 37 | 32 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 54 | 49 |
| 55 cert_policy_for_host_[host].Allow(cert); | 50 cert_policy_for_host_[host].Allow(cert); |
| 56 } | 51 } |
| 57 | 52 |
| 58 net::CertPolicy::Judgment SSLHostState::QueryPolicy( | 53 net::CertPolicy::Judgment SSLHostState::QueryPolicy( |
| 59 net::X509Certificate* cert, const std::string& host) { | 54 net::X509Certificate* cert, const std::string& host) { |
| 60 DCHECK(CalledOnValidThread()); | 55 DCHECK(CalledOnValidThread()); |
| 61 | 56 |
| 62 return cert_policy_for_host_[host].Check(cert); | 57 return cert_policy_for_host_[host].Check(cert); |
| 63 } | 58 } |
| 64 | |
| 65 void SSLHostState::Observe(int type, | |
| 66 const content::NotificationSource& source, | |
| 67 const content::NotificationDetails& details) { | |
| 68 delete this; | |
| 69 } | |
| OLD | NEW |