summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authortoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-17 17:23:08 +0000
committertoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-17 17:23:08 +0000
commit877182bb87fbe188efdb2d9fc641931706c9a469 (patch)
treeb74686831219bc8b81e19757d2031a04cab8175d /content
parent930df0858458d6f431b6378e7eae8f674a4139da (diff)
downloadchromium_src-877182bb87fbe188efdb2d9fc641931706c9a469.zip
chromium_src-877182bb87fbe188efdb2d9fc641931706c9a469.tar.gz
chromium_src-877182bb87fbe188efdb2d9fc641931706c9a469.tar.bz2
Use WeakPtr for passing SSLErrorHandler::Delegate to SSLManager.
If user close the owner tab while SSLManager suspend a query, SocketStreamDispatcherHost will disappear because it is owned by a renderer host. Because WebSocket is a sub resource, its request will be suspended until other major type resources (e.g., main frame) issue the same query request. I Introduce WeakPtr to make sure that SSLCertErrorHandler can call delegate functions safely. BUG=122654 TEST=none Review URL: https://chromiumcodereview.appspot.com/10034017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137676 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_impl.cc7
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_impl.h3
-rw-r--r--content/browser/renderer_host/socket_stream_dispatcher_host.cc10
-rw-r--r--content/browser/renderer_host/socket_stream_dispatcher_host.h4
-rw-r--r--content/browser/ssl/ssl_cert_error_handler.cc2
-rw-r--r--content/browser/ssl/ssl_cert_error_handler.h3
-rw-r--r--content/browser/ssl/ssl_error_handler.cc8
-rw-r--r--content/browser/ssl/ssl_error_handler.h5
-rw-r--r--content/browser/ssl/ssl_manager.cc17
-rw-r--r--content/browser/ssl/ssl_manager.h18
10 files changed, 47 insertions, 30 deletions
diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.cc b/content/browser/renderer_host/resource_dispatcher_host_impl.cc
index a561c6a0..0036ada 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_impl.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_impl.cc
@@ -320,6 +320,7 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
save_file_manager_(new SaveFileManager()),
request_id_(-1),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(ssl_delegate_weak_factory_(this)),
is_shutdown_(false),
max_outstanding_requests_cost_per_process_(
kMaxOutstandingRequestsCostPerProcess),
@@ -1535,9 +1536,9 @@ void ResourceDispatcherHostImpl::OnSSLCertificateError(
int render_view_id;
if(!info->GetAssociatedRenderView(&render_process_id, &render_view_id))
NOTREACHED();
- SSLManager::OnSSLCertificateError(this, request_id, info->GetResourceType(),
- request->url(), render_process_id, render_view_id, ssl_info,
- is_hsts_host);
+ SSLManager::OnSSLCertificateError(ssl_delegate_weak_factory_.GetWeakPtr(),
+ request_id, info->GetResourceType(), request->url(), render_process_id,
+ render_view_id, ssl_info, is_hsts_host);
}
void ResourceDispatcherHostImpl::OnResponseStarted(net::URLRequest* request) {
diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.h b/content/browser/renderer_host/resource_dispatcher_host_impl.h
index 1cb899a..6ec3e0d 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_impl.h
+++ b/content/browser/renderer_host/resource_dispatcher_host_impl.h
@@ -472,6 +472,9 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl
// For running tasks.
base::WeakPtrFactory<ResourceDispatcherHostImpl> weak_factory_;
+ // For SSLErrorHandler::Delegate calls from SSLManager.
+ base::WeakPtrFactory<SSLErrorHandler::Delegate> ssl_delegate_weak_factory_;
+
// True if the resource dispatcher host has been shut down.
bool is_shutdown_;
diff --git a/content/browser/renderer_host/socket_stream_dispatcher_host.cc b/content/browser/renderer_host/socket_stream_dispatcher_host.cc
index 2dc319c..84e5c8e 100644
--- a/content/browser/renderer_host/socket_stream_dispatcher_host.cc
+++ b/content/browser/renderer_host/socket_stream_dispatcher_host.cc
@@ -21,7 +21,8 @@ SocketStreamDispatcherHost::SocketStreamDispatcherHost(
int render_process_id,
ResourceMessageFilter::URLRequestContextSelector* selector,
content::ResourceContext* resource_context)
- : render_process_id_(render_process_id),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(ssl_delegate_weak_factory_(this)),
+ render_process_id_(render_process_id),
url_request_context_selector_(selector),
resource_context_(resource_context) {
DCHECK(selector);
@@ -110,9 +111,10 @@ void SocketStreamDispatcherHost::OnSSLCertificateError(
SocketStreamHost* socket_stream_host = hosts_.Lookup(socket_id);
DCHECK(socket_stream_host);
content::GlobalRequestID request_id(-1, socket_id);
- SSLManager::OnSSLCertificateError(this, request_id,
- ResourceType::SUB_RESOURCE, socket->url(), render_process_id_,
- socket_stream_host->render_view_id(), ssl_info, fatal);
+ SSLManager::OnSSLCertificateError(ssl_delegate_weak_factory_.GetWeakPtr(),
+ request_id, ResourceType::SUB_RESOURCE, socket->url(),
+ render_process_id_, socket_stream_host->render_view_id(), ssl_info,
+ fatal);
}
bool SocketStreamDispatcherHost::CanGetCookies(net::SocketStream* socket,
diff --git a/content/browser/renderer_host/socket_stream_dispatcher_host.h b/content/browser/renderer_host/socket_stream_dispatcher_host.h
index 2064059..b340ab9 100644
--- a/content/browser/renderer_host/socket_stream_dispatcher_host.h
+++ b/content/browser/renderer_host/socket_stream_dispatcher_host.h
@@ -9,6 +9,7 @@
#include <vector>
#include "base/id_map.h"
+#include "base/memory/weak_ptr.h"
#include "content/browser/renderer_host/resource_message_filter.h"
#include "content/browser/ssl/ssl_error_handler.h"
#include "content/public/browser/browser_message_filter.h"
@@ -80,6 +81,9 @@ class SocketStreamDispatcherHost : public content::BrowserMessageFilter,
net::URLRequestContext* GetURLRequestContext();
+ // For SSLErrorHandler::Delegate calls from SSLManager.
+ base::WeakPtrFactory<SSLErrorHandler::Delegate> ssl_delegate_weak_factory_;
+
IDMap<SocketStreamHost> hosts_;
int render_process_id_;
const scoped_ptr<ResourceMessageFilter::URLRequestContextSelector>
diff --git a/content/browser/ssl/ssl_cert_error_handler.cc b/content/browser/ssl/ssl_cert_error_handler.cc
index 9acd5df..ff6418a 100644
--- a/content/browser/ssl/ssl_cert_error_handler.cc
+++ b/content/browser/ssl/ssl_cert_error_handler.cc
@@ -13,7 +13,7 @@
using content::ResourceDispatcherHostImpl;
SSLCertErrorHandler::SSLCertErrorHandler(
- Delegate* delegate,
+ base::WeakPtr<Delegate> delegate,
const content::GlobalRequestID& id,
ResourceType::Type resource_type,
const GURL& url,
diff --git a/content/browser/ssl/ssl_cert_error_handler.h b/content/browser/ssl/ssl_cert_error_handler.h
index ac6a3eb..1424651 100644
--- a/content/browser/ssl/ssl_cert_error_handler.h
+++ b/content/browser/ssl/ssl_cert_error_handler.h
@@ -8,6 +8,7 @@
#include <string>
+#include "base/memory/weak_ptr.h"
#include "content/browser/ssl/ssl_error_handler.h"
#include "net/base/ssl_info.h"
@@ -17,7 +18,7 @@
class SSLCertErrorHandler : public SSLErrorHandler {
public:
// Construct on the IO thread.
- SSLCertErrorHandler(Delegate* delegate,
+ SSLCertErrorHandler(base::WeakPtr<Delegate> delegate,
const content::GlobalRequestID& id,
ResourceType::Type resource_type,
const GURL& url,
diff --git a/content/browser/ssl/ssl_error_handler.cc b/content/browser/ssl/ssl_error_handler.cc
index e193d0e..1a76172 100644
--- a/content/browser/ssl/ssl_error_handler.cc
+++ b/content/browser/ssl/ssl_error_handler.cc
@@ -19,7 +19,7 @@ using content::RenderViewHostImpl;
using content::WebContents;
using net::SSLInfo;
-SSLErrorHandler::SSLErrorHandler(Delegate* delegate,
+SSLErrorHandler::SSLErrorHandler(base::WeakPtr<Delegate> delegate,
const content::GlobalRequestID& id,
ResourceType::Type resource_type,
const GURL& url,
@@ -134,7 +134,8 @@ void SSLErrorHandler::CompleteCancelRequest(int error) {
const SSLInfo* ssl_info = NULL;
if (cert_error)
ssl_info = &cert_error->ssl_info();
- delegate_->CancelSSLRequest(request_id_, error, ssl_info);
+ if (delegate_)
+ delegate_->CancelSSLRequest(request_id_, error, ssl_info);
request_has_been_notified_ = true;
// We're done with this object on the IO thread.
@@ -151,7 +152,8 @@ void SSLErrorHandler::CompleteContinueRequest() {
if (request_has_been_notified_)
return;
- delegate_->ContinueSSLRequest(request_id_);
+ if (delegate_)
+ delegate_->ContinueSSLRequest(request_id_);
request_has_been_notified_ = true;
// We're done with this object on the IO thread.
diff --git a/content/browser/ssl/ssl_error_handler.h b/content/browser/ssl/ssl_error_handler.h
index 15832df..647ee71 100644
--- a/content/browser/ssl/ssl_error_handler.h
+++ b/content/browser/ssl/ssl_error_handler.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "content/public/browser/global_request_id.h"
#include "googleurl/src/gurl.h"
@@ -105,7 +106,7 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> {
friend class base::RefCountedThreadSafe<SSLErrorHandler>;
// Construct on the IO thread.
- SSLErrorHandler(Delegate* delegate,
+ SSLErrorHandler(base::WeakPtr<Delegate> delegate,
const content::GlobalRequestID& id,
ResourceType::Type resource_type,
const GURL& url,
@@ -128,7 +129,7 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> {
content::GlobalRequestID request_id_;
// The delegate we are associated with.
- Delegate* delegate_;
+ base::WeakPtr<Delegate> delegate_;
private:
// Completes the CancelRequest operation on the IO thread.
diff --git a/content/browser/ssl/ssl_manager.cc b/content/browser/ssl/ssl_manager.cc
index 8a6f500..4f88b05 100644
--- a/content/browser/ssl/ssl_manager.cc
+++ b/content/browser/ssl/ssl_manager.cc
@@ -35,14 +35,15 @@ using content::SSLStatus;
using content::WebContents;
// static
-void SSLManager::OnSSLCertificateError(SSLErrorHandler::Delegate* delegate,
- const content::GlobalRequestID& id,
- const ResourceType::Type resource_type,
- const GURL& url,
- int render_process_id,
- int render_view_id,
- const net::SSLInfo& ssl_info,
- bool fatal) {
+void SSLManager::OnSSLCertificateError(
+ base::WeakPtr<SSLErrorHandler::Delegate> delegate,
+ const content::GlobalRequestID& id,
+ const ResourceType::Type resource_type,
+ const GURL& url,
+ int render_process_id,
+ int render_view_id,
+ const net::SSLInfo& ssl_info,
+ bool fatal) {
DCHECK(delegate);
DVLOG(1) << "OnSSLCertificateError() cert_error: "
<< net::MapCertStatusToNetError(ssl_info.cert_status)
diff --git a/content/browser/ssl/ssl_manager.h b/content/browser/ssl/ssl_manager.h
index 101f1c9..5b8a17d 100644
--- a/content/browser/ssl/ssl_manager.h
+++ b/content/browser/ssl/ssl_manager.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "content/browser/ssl/ssl_policy_backend.h"
#include "content/browser/ssl/ssl_error_handler.h"
#include "content/common/content_export.h"
@@ -50,14 +51,15 @@ class SSLManager : public content::NotificationObserver {
// |ContinueSSLRequest| of |delegate| with |id| as the first argument.
//
// Called on the IO thread.
- static void OnSSLCertificateError(SSLErrorHandler::Delegate* delegate,
- const content::GlobalRequestID& id,
- ResourceType::Type resource_type,
- const GURL& url,
- int render_process_id,
- int render_view_id,
- const net::SSLInfo& ssl_info,
- bool fatal);
+ static void OnSSLCertificateError(
+ base::WeakPtr<SSLErrorHandler::Delegate> delegate,
+ const content::GlobalRequestID& id,
+ ResourceType::Type resource_type,
+ const GURL& url,
+ int render_process_id,
+ int render_view_id,
+ const net::SSLInfo& ssl_info,
+ bool fatal);
// Called when SSL state for a host or tab changes. Broadcasts the
// SSL_INTERNAL_STATE_CHANGED notification.