summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-13 17:23:26 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-13 17:23:26 +0000
commit7134b1ff692fc6c57c71dd0eaedabc8db0ec792b (patch)
tree2b0bb156cb205d94a2c1ae562d17f89698b1d707 /content
parent9cdaf7474c46f9a01fd7d28260a3c6d789aa6847 (diff)
downloadchromium_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')
-rw-r--r--content/browser/ssl/ssl_host_state.cc26
-rw-r--r--content/browser/ssl/ssl_host_state.h21
-rw-r--r--content/browser/ssl/ssl_host_state_unittest.cc4
-rw-r--r--content/browser/ssl/ssl_policy_backend.cc2
-rw-r--r--content/content_browser.gypi1
-rw-r--r--content/public/browser/browser_context.cc23
-rw-r--r--content/public/browser/browser_context.h11
-rw-r--r--content/public/browser/notification_types.h18
-rw-r--r--content/shell/shell_browser_context.cc7
-rw-r--r--content/shell/shell_browser_context.h3
-rw-r--r--content/test/test_browser_context.cc4
-rw-r--r--content/test/test_browser_context.h1
12 files changed, 84 insertions, 37 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_);
}
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index b506fb8d..418832d 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -32,6 +32,7 @@
'public/browser/browser_child_process_host_delegate.h',
'public/browser/browser_child_process_host_iterator.cc',
'public/browser/browser_child_process_host_iterator.h',
+ 'public/browser/browser_context.cc',
'public/browser/browser_context.h',
'public/browser/browser_main_parts.h',
'public/browser/browser_main_runner.h',
diff --git a/content/public/browser/browser_context.cc b/content/public/browser/browser_context.cc
new file mode 100644
index 0000000..c3f931e
--- /dev/null
+++ b/content/public/browser/browser_context.cc
@@ -0,0 +1,23 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/browser_context.h"
+
+#include "base/logging.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/notification_types.h"
+
+namespace content {
+
+BrowserContext::~BrowserContext() {
+ NotificationService::current()->Notify(
+ content::NOTIFICATION_BROWSER_CONTEXT_DESTRUCTION,
+ content::Source<BrowserContext>(this),
+ content::NotificationService::NoDetails());
+}
+
+} // namespace content
diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h
index bf235d6..6832bec 100644
--- a/content/public/browser/browser_context.h
+++ b/content/public/browser/browser_context.h
@@ -7,6 +7,7 @@
#pragma once
#include "base/hash_tables.h"
+#include "content/common/content_export.h"
namespace fileapi {
class FileSystemContext;
@@ -27,7 +28,6 @@ class DatabaseTracker;
class ChromeAppCacheService;
class ChromeBlobStorageContext;
class FilePath;
-class SSLHostState;
class WebKitContext;
namespace content {
@@ -40,9 +40,9 @@ class SpeechInputPreferences;
// This class holds the context needed for a browsing session.
// It lives on the UI thread.
-class BrowserContext {
+class CONTENT_EXPORT BrowserContext {
public:
- virtual ~BrowserContext() {}
+ virtual ~BrowserContext();
// Returns the path of the directory where this context's data is stored.
virtual FilePath GetPath() = 0;
@@ -51,11 +51,6 @@ class BrowserContext {
// This doesn't belong here; http://crbug.com/89628
virtual bool IsOffTheRecord() = 0;
- // Retrieves a pointer to the SSLHostState associated with this context.
- // The SSLHostState is lazily created the first time that this method is
- // called.
- virtual SSLHostState* GetSSLHostState() = 0;
-
// Returns the DownloadManager associated with this context.
virtual content::DownloadManager* GetDownloadManager() = 0;
diff --git a/content/public/browser/notification_types.h b/content/public/browser/notification_types.h
index a5c3f9c..f51a926 100644
--- a/content/public/browser/notification_types.h
+++ b/content/public/browser/notification_types.h
@@ -192,17 +192,17 @@ enum NotificationType {
NOTIFICATION_APP_EXITING,
// Indicates that a devtools window is opening. The source is the
- // content::BrowserContext* and the details is the inspected RenderViewHost*.
+ // BrowserContext* and the details is the inspected RenderViewHost*.
NOTIFICATION_DEVTOOLS_WINDOW_OPENING,
// Indicates that a devtools window is closing. The source is the
- // content::BrowserContext* and the details is the inspected RenderViewHost*.
+ // BrowserContext* and the details is the inspected RenderViewHost*.
NOTIFICATION_DEVTOOLS_WINDOW_CLOSING,
// Tabs --------------------------------------------------------------------
// Sent when a tab is added to a WebContentsDelegate. The source is the
- // WebContentsDelegate and the details is the added content::WebContents.
+ // WebContentsDelegate and the details is the added WebContents.
NOTIFICATION_TAB_ADDED,
// This notification is sent after a tab has been appended to the tab_strip.
@@ -373,20 +373,20 @@ enum NotificationType {
// This notification is sent when a child process host has connected to a
// child process. There is no usable source, since it is sent from an
// ephemeral task; register for AllSources() to receive this notification.
- // The details are in a Details<content::ChildProcessData>.
+ // The details are in a Details<ChildProcessData>.
NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED,
// This message is sent after a ChildProcessHost is disconnected from the
// child process. There is no usable source, since it is sent from an
// ephemeral task; register for AllSources() to receive this notification.
- // The details are in a Details<content::ChildProcessData>.
+ // The details are in a Details<ChildProcessData>.
NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED,
// This message is sent when a child process disappears
// unexpectedly as a result of a crash. There is no usable
// source, since it is sent from an ephemeral task; register for
// AllSources() to receive this notification. The details are in
- // a Details<content::ChildProcessData>.
+ // a Details<ChildProcessData>.
NOTIFICATION_CHILD_PROCESS_CRASHED,
// This message indicates that an instance of a particular child was
@@ -396,7 +396,7 @@ enum NotificationType {
//
// There is no usable source, since it is sent from an ephemeral task;
// register for AllSources() to receive this notification. The details are
- // in a Details<content::ChildProcessData>.
+ // in a Details<ChildProcessData>.
NOTIFICATION_CHILD_INSTANCE_CREATED,
// Saved Pages -------------------------------------------------------------
@@ -421,6 +421,10 @@ enum NotificationType {
// of a temporary zoom level change, the details is an empty string.
NOTIFICATION_ZOOM_LEVEL_CHANGED,
+ // Sent when a BrowserContext is being deleted, in case any objects want to do
+ // related cleanup. The source is the BrowserContext.
+ NOTIFICATION_BROWSER_CONTEXT_DESTRUCTION,
+
// Custom notifications used by the embedder should start from here.
NOTIFICATION_CONTENT_END,
};
diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc
index e4200c9..cd47383 100644
--- a/content/shell/shell_browser_context.cc
+++ b/content/shell/shell_browser_context.cc
@@ -16,7 +16,6 @@
#include "content/browser/file_system/browser_file_system_helper.h"
#include "content/browser/host_zoom_map_impl.h"
#include "content/browser/in_process_webkit/webkit_context.h"
-#include "content/browser/ssl/ssl_host_state.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/geolocation_permission_context.h"
#include "content/public/browser/speech_input_preferences.h"
@@ -129,12 +128,6 @@ bool ShellBrowserContext::IsOffTheRecord() {
return false;
}
-SSLHostState* ShellBrowserContext::GetSSLHostState() {
- if (!ssl_host_state_.get())
- ssl_host_state_.reset(new SSLHostState());
- return ssl_host_state_.get();
-}
-
DownloadManager* ShellBrowserContext::GetDownloadManager() {
if (!download_manager_.get()) {
download_manager_delegate_ = new ShellDownloadManagerDelegate();
diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h
index b9681d7..84d29b8 100644
--- a/content/shell/shell_browser_context.h
+++ b/content/shell/shell_browser_context.h
@@ -13,7 +13,6 @@
#include "content/public/browser/browser_context.h"
class DownloadManager;
-class SSLHostState;
namespace content {
@@ -30,7 +29,6 @@ class ShellBrowserContext : public BrowserContext {
// BrowserContext implementation.
virtual FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() OVERRIDE;
- virtual SSLHostState* GetSSLHostState() OVERRIDE;
virtual DownloadManager* GetDownloadManager() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
@@ -54,7 +52,6 @@ class ShellBrowserContext : public BrowserContext {
FilePath path_;
scoped_ptr<ResourceContext> resource_context_;
- scoped_ptr<SSLHostState> ssl_host_state_;
scoped_refptr<ShellDownloadManagerDelegate> download_manager_delegate_;
scoped_refptr<DownloadManager> download_manager_;
scoped_refptr<net::URLRequestContextGetter> url_request_getter_;
diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc
index 41fc78f..bc8a3ee 100644
--- a/content/test/test_browser_context.cc
+++ b/content/test/test_browser_context.cc
@@ -27,10 +27,6 @@ bool TestBrowserContext::IsOffTheRecord() {
return false;
}
-SSLHostState* TestBrowserContext::GetSSLHostState() {
- return NULL;
-}
-
DownloadManager* TestBrowserContext::GetDownloadManager() {
return NULL;
}
diff --git a/content/test/test_browser_context.h b/content/test/test_browser_context.h
index e060d29..ee5acf6 100644
--- a/content/test/test_browser_context.h
+++ b/content/test/test_browser_context.h
@@ -22,7 +22,6 @@ class TestBrowserContext : public content::BrowserContext {
virtual FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() OVERRIDE;
- virtual SSLHostState* GetSSLHostState() OVERRIDE;
virtual content::DownloadManager* GetDownloadManager() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(