diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 22:07:34 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 22:07:34 +0000 |
commit | ea8e1813f4dec2371093983e7503aae2d591c1e4 (patch) | |
tree | 102acfab138debea374a8d0e850d872bf98adcef /content | |
parent | ea93125d7961a09ba90d44a9c3013483399a2051 (diff) | |
download | chromium_src-ea8e1813f4dec2371093983e7503aae2d591c1e4.zip chromium_src-ea8e1813f4dec2371093983e7503aae2d591c1e4.tar.gz chromium_src-ea8e1813f4dec2371093983e7503aae2d591c1e4.tar.bz2 |
Add extra data to BrowserContext so that content layer and other embedders can stash data with it that has the same lifetime. Converted SSLHostState to use it for now. I'll do the rest in a followup.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9348109
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122164 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/resource_dispatcher_host_request_info.cc | 1 | ||||
-rw-r--r-- | content/browser/renderer_host/resource_dispatcher_host_request_info.h | 9 | ||||
-rw-r--r-- | content/browser/renderer_host/resource_dispatcher_host_unittest.cc | 6 | ||||
-rw-r--r-- | content/browser/renderer_host/resource_queue.cc | 1 | ||||
-rw-r--r-- | content/browser/ssl/ssl_host_state.cc | 31 | ||||
-rw-r--r-- | content/browser/ssl/ssl_host_state.h | 13 | ||||
-rw-r--r-- | content/browser/ssl/ssl_host_state_unittest.cc | 4 | ||||
-rw-r--r-- | content/content_browser.gypi | 1 | ||||
-rw-r--r-- | content/public/browser/browser_context.cc | 13 | ||||
-rw-r--r-- | content/public/browser/browser_context.h | 5 | ||||
-rw-r--r-- | content/public/browser/notification_types.h | 4 |
11 files changed, 30 insertions, 58 deletions
diff --git a/content/browser/renderer_host/resource_dispatcher_host_request_info.cc b/content/browser/renderer_host/resource_dispatcher_host_request_info.cc index 74e1a54..60fc30c 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_request_info.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_request_info.cc @@ -7,6 +7,7 @@ #include "content/browser/renderer_host/resource_handler.h" #include "content/browser/ssl/ssl_client_auth_handler.h" #include "content/public/browser/resource_dispatcher_host_login_delegate.h" +#include "net/url_request/url_request.h" #include "webkit/blob/blob_data.h" ResourceDispatcherHostRequestInfo::ResourceDispatcherHostRequestInfo( diff --git a/content/browser/renderer_host/resource_dispatcher_host_request_info.h b/content/browser/renderer_host/resource_dispatcher_host_request_info.h index 2296640..c4a0cb1 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_request_info.h +++ b/content/browser/renderer_host/resource_dispatcher_host_request_info.h @@ -9,13 +9,14 @@ #include <string> #include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "base/supports_user_data.h" #include "base/time.h" #include "content/common/content_export.h" #include "content/public/common/page_transition_types.h" #include "content/public/common/process_type.h" #include "content/public/common/referrer.h" #include "net/base/load_states.h" -#include "net/url_request/url_request.h" #include "webkit/glue/resource_type.h" class ResourceDispatcherHost; @@ -28,13 +29,17 @@ class ResourceContext; class ResourceDispatcherHostLoginDelegate; } +namespace net { +class URLRequest; +} + namespace webkit_blob { class BlobData; } // Holds the data ResourceDispatcherHost associates with each request. // Retrieve this data by calling ResourceDispatcherHost::InfoForRequest. -class ResourceDispatcherHostRequestInfo : public net::URLRequest::UserData { +class ResourceDispatcherHostRequestInfo : public base::SupportsUserData::Data { public: // This will take a reference to the handler. CONTENT_EXPORT ResourceDispatcherHostRequestInfo( diff --git a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc index 1a89561..5075014 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc @@ -270,7 +270,7 @@ URLRequestTestDelayedStartJob* URLRequestTestDelayedStartJob::list_head_ = NULL; // Associated with an URLRequest to determine if the URLRequest gets deleted. -class TestUserData : public net::URLRequest::UserData { +class TestUserData : public base::SupportsUserData::Data { public: explicit TestUserData(bool* was_deleted) : was_deleted_(was_deleted) { @@ -291,7 +291,7 @@ class TestResourceDispatcherHostDelegate : defer_start_(false) { } - void set_url_request_user_data(net::URLRequest::UserData* user_data) { + void set_url_request_user_data(base::SupportsUserData::Data* user_data) { user_data_.reset(user_data); } @@ -321,7 +321,7 @@ class TestResourceDispatcherHostDelegate private: bool defer_start_; - scoped_ptr<net::URLRequest::UserData> user_data_; + scoped_ptr<base::SupportsUserData::Data> user_data_; }; class ResourceDispatcherHostTest : public testing::Test, diff --git a/content/browser/renderer_host/resource_queue.cc b/content/browser/renderer_host/resource_queue.cc index ef0ebe3..50ea004 100644 --- a/content/browser/renderer_host/resource_queue.cc +++ b/content/browser/renderer_host/resource_queue.cc @@ -8,6 +8,7 @@ #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/global_request_id.h" +#include "net/url_request/url_request.h" using content::BrowserThread; using content::GlobalRequestID; diff --git a/content/browser/ssl/ssl_host_state.cc b/content/browser/ssl/ssl_host_state.cc index 67f3fd8..e0ceea4 100644 --- a/content/browser/ssl/ssl_host_state.cc +++ b/content/browser/ssl/ssl_host_state.cc @@ -6,25 +6,20 @@ #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" +#include "content/public/browser/browser_context.h" -namespace { -typedef std::map<content::BrowserContext*, SSLHostState*> HostStateMap; -static base::LazyInstance<HostStateMap> g_host_state_map = - LAZY_INSTANCE_INITIALIZER; -} +static const char* kKeyName = "content_ssl_host_state"; -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::GetFor(content::BrowserContext* context) { + SSLHostState* rv = static_cast<SSLHostState*>(context->GetUserData(kKeyName)); + if (!rv) { + rv = new SSLHostState(); + context->SetUserData(kKeyName, rv); + } + return rv; } -SSLHostState::SSLHostState(content::BrowserContext* browser_context) { - registrar_.Add(this, content::NOTIFICATION_BROWSER_CONTEXT_DESTRUCTION, - content::Source<content::BrowserContext>(browser_context)); +SSLHostState::SSLHostState() { } SSLHostState::~SSLHostState() { @@ -61,9 +56,3 @@ 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 498046e..b051b05 100644 --- a/content/browser/ssl/ssl_host_state.h +++ b/content/browser/ssl/ssl_host_state.h @@ -12,10 +12,9 @@ #include "base/compiler_specific.h" #include "base/basictypes.h" +#include "base/supports_user_data.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" @@ -32,12 +31,12 @@ class BrowserContext; // controllers. class CONTENT_EXPORT SSLHostState - : public content::NotificationObserver, + : NON_EXPORTED_BASE(base::SupportsUserData::Data), NON_EXPORTED_BASE(public base::NonThreadSafe) { public: static SSLHostState* GetFor(content::BrowserContext* browser_context); - explicit SSLHostState(content::BrowserContext* browser_context); + SSLHostState(); virtual ~SSLHostState(); // Records that a host has run insecure content. @@ -57,10 +56,6 @@ 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; @@ -73,8 +68,6 @@ 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 e057262..08a589f 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(NULL); + SSLHostState state; 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(NULL); + SSLHostState state; EXPECT_EQ(state.QueryPolicy(google_cert.get(), "www.google.com"), net::CertPolicy::UNKNOWN); diff --git a/content/content_browser.gypi b/content/content_browser.gypi index b9b9346..1010d5e 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -32,7 +32,6 @@ '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 index c3f931e..b8f540f 100644 --- a/content/public/browser/browser_context.cc +++ b/content/public/browser/browser_context.cc @@ -4,20 +4,7 @@ #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 6832bec..9618315 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 "base/supports_user_data.h" #include "content/common/content_export.h" namespace fileapi { @@ -40,9 +41,9 @@ class SpeechInputPreferences; // This class holds the context needed for a browsing session. // It lives on the UI thread. -class CONTENT_EXPORT BrowserContext { +class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { public: - virtual ~BrowserContext(); + virtual ~BrowserContext() {} // Returns the path of the directory where this context's data is stored. virtual FilePath GetPath() = 0; diff --git a/content/public/browser/notification_types.h b/content/public/browser/notification_types.h index b7b45ce..5e4fb1a 100644 --- a/content/public/browser/notification_types.h +++ b/content/public/browser/notification_types.h @@ -414,10 +414,6 @@ 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, }; |