diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-13 17:23:26 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-13 17:23:26 +0000 |
commit | 7134b1ff692fc6c57c71dd0eaedabc8db0ec792b (patch) | |
tree | 2b0bb156cb205d94a2c1ae562d17f89698b1d707 /content/browser/ssl | |
parent | 9cdaf7474c46f9a01fd7d28260a3c6d789aa6847 (diff) | |
download | chromium_src-7134b1ff692fc6c57c71dd0eaedabc8db0ec792b.zip chromium_src-7134b1ff692fc6c57c71dd0eaedabc8db0ec792b.tar.gz chromium_src-7134b1ff692fc6c57c71dd0eaedabc8db0ec792b.tar.bz2 |
Remove ssl_host_state.h dependency from chrome.
I suspect there'll be a few objects that hang off BrowserContext/ResourceContext which are per profile that we don't want chrome to know about or even to create. For now, I did a one-off by manually keeping a map and deleting it when the BrowserContext goes away. If we hit others, we can generalize this into a template, perhaps like RenderViewHostObserverTracker.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9384029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121706 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/ssl')
-rw-r--r-- | content/browser/ssl/ssl_host_state.cc | 26 | ||||
-rw-r--r-- | content/browser/ssl/ssl_host_state.h | 21 | ||||
-rw-r--r-- | content/browser/ssl/ssl_host_state_unittest.cc | 4 | ||||
-rw-r--r-- | content/browser/ssl/ssl_policy_backend.cc | 2 |
4 files changed, 46 insertions, 7 deletions
diff --git a/content/browser/ssl/ssl_host_state.cc b/content/browser/ssl/ssl_host_state.cc index 7b0deef..67f3fd8 100644 --- a/content/browser/ssl/ssl_host_state.cc +++ b/content/browser/ssl/ssl_host_state.cc @@ -5,8 +5,26 @@ #include "content/browser/ssl/ssl_host_state.h" #include "base/logging.h" +#include "base/lazy_instance.h" +#include "content/public/browser/notification_details.h" +#include "content/public/browser/notification_source.h" +#include "content/public/browser/notification_types.h" -SSLHostState::SSLHostState() { +namespace { +typedef std::map<content::BrowserContext*, SSLHostState*> HostStateMap; +static base::LazyInstance<HostStateMap> g_host_state_map = + LAZY_INSTANCE_INITIALIZER; +} + +SSLHostState* SSLHostState::GetFor(content::BrowserContext* browser_context) { + if (!g_host_state_map.Get().count(browser_context)) + g_host_state_map.Get()[browser_context] = new SSLHostState(browser_context); + return g_host_state_map.Get()[browser_context]; +} + +SSLHostState::SSLHostState(content::BrowserContext* browser_context) { + registrar_.Add(this, content::NOTIFICATION_BROWSER_CONTEXT_DESTRUCTION, + content::Source<content::BrowserContext>(browser_context)); } SSLHostState::~SSLHostState() { @@ -43,3 +61,9 @@ net::CertPolicy::Judgment SSLHostState::QueryPolicy( return cert_policy_for_host_[host].Check(cert); } + +void SSLHostState::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + delete this; +} diff --git a/content/browser/ssl/ssl_host_state.h b/content/browser/ssl/ssl_host_state.h index 7bceaa7..498046e 100644 --- a/content/browser/ssl/ssl_host_state.h +++ b/content/browser/ssl/ssl_host_state.h @@ -14,9 +14,15 @@ #include "base/basictypes.h" #include "base/threading/non_thread_safe.h" #include "content/common/content_export.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" #include "googleurl/src/gurl.h" #include "net/base/x509_certificate.h" +namespace content { +class BrowserContext; +} + // SSLHostState // // The SSLHostState encapulates the host-specific state for SSL errors. For @@ -26,10 +32,13 @@ // controllers. class CONTENT_EXPORT SSLHostState - : NON_EXPORTED_BASE(public base::NonThreadSafe) { + : public content::NotificationObserver, + NON_EXPORTED_BASE(public base::NonThreadSafe) { public: - SSLHostState(); - ~SSLHostState(); + static SSLHostState* GetFor(content::BrowserContext* browser_context); + + explicit SSLHostState(content::BrowserContext* browser_context); + virtual ~SSLHostState(); // Records that a host has run insecure content. void HostRanInsecureContent(const std::string& host, int pid); @@ -48,6 +57,10 @@ class CONTENT_EXPORT SSLHostState net::X509Certificate* cert, const std::string& host); private: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + // A BrokenHostEntry is a pair of (host, process_id) that indicates the host // contains insecure content in that renderer process. typedef std::pair<std::string, int> BrokenHostEntry; @@ -60,6 +73,8 @@ class CONTENT_EXPORT SSLHostState // Certificate policies for each host. std::map<std::string, net::CertPolicy> cert_policy_for_host_; + content::NotificationRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(SSLHostState); }; diff --git a/content/browser/ssl/ssl_host_state_unittest.cc b/content/browser/ssl/ssl_host_state_unittest.cc index 08a589f..e057262 100644 --- a/content/browser/ssl/ssl_host_state_unittest.cc +++ b/content/browser/ssl/ssl_host_state_unittest.cc @@ -92,7 +92,7 @@ class SSLHostStateTest : public testing::Test { }; TEST_F(SSLHostStateTest, DidHostRunInsecureContent) { - SSLHostState state; + SSLHostState state(NULL); EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 42)); EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); @@ -116,7 +116,7 @@ TEST_F(SSLHostStateTest, QueryPolicy) { net::X509Certificate::CreateFromBytes( reinterpret_cast<const char*>(google_der), sizeof(google_der))); - SSLHostState state; + SSLHostState state(NULL); EXPECT_EQ(state.QueryPolicy(google_cert.get(), "www.google.com"), net::CertPolicy::UNKNOWN); diff --git a/content/browser/ssl/ssl_policy_backend.cc b/content/browser/ssl/ssl_policy_backend.cc index b19965a..1a95e80 100644 --- a/content/browser/ssl/ssl_policy_backend.cc +++ b/content/browser/ssl/ssl_policy_backend.cc @@ -9,7 +9,7 @@ #include "content/public/browser/browser_context.h" SSLPolicyBackend::SSLPolicyBackend(NavigationControllerImpl* controller) - : ssl_host_state_(controller->GetBrowserContext()->GetSSLHostState()), + : ssl_host_state_(SSLHostState::GetFor(controller->GetBrowserContext())), controller_(controller) { DCHECK(controller_); } |