Commit 877182bb authored by toyoshim@chromium.org's avatar toyoshim@chromium.org

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
parent 930df085
...@@ -320,6 +320,7 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() ...@@ -320,6 +320,7 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
save_file_manager_(new SaveFileManager()), save_file_manager_(new SaveFileManager()),
request_id_(-1), request_id_(-1),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(ssl_delegate_weak_factory_(this)),
is_shutdown_(false), is_shutdown_(false),
max_outstanding_requests_cost_per_process_( max_outstanding_requests_cost_per_process_(
kMaxOutstandingRequestsCostPerProcess), kMaxOutstandingRequestsCostPerProcess),
...@@ -1535,9 +1536,9 @@ void ResourceDispatcherHostImpl::OnSSLCertificateError( ...@@ -1535,9 +1536,9 @@ void ResourceDispatcherHostImpl::OnSSLCertificateError(
int render_view_id; int render_view_id;
if(!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) if(!info->GetAssociatedRenderView(&render_process_id, &render_view_id))
NOTREACHED(); NOTREACHED();
SSLManager::OnSSLCertificateError(this, request_id, info->GetResourceType(), SSLManager::OnSSLCertificateError(ssl_delegate_weak_factory_.GetWeakPtr(),
request->url(), render_process_id, render_view_id, ssl_info, request_id, info->GetResourceType(), request->url(), render_process_id,
is_hsts_host); render_view_id, ssl_info, is_hsts_host);
} }
void ResourceDispatcherHostImpl::OnResponseStarted(net::URLRequest* request) { void ResourceDispatcherHostImpl::OnResponseStarted(net::URLRequest* request) {
......
...@@ -472,6 +472,9 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl ...@@ -472,6 +472,9 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl
// For running tasks. // For running tasks.
base::WeakPtrFactory<ResourceDispatcherHostImpl> weak_factory_; 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. // True if the resource dispatcher host has been shut down.
bool is_shutdown_; bool is_shutdown_;
......
...@@ -21,7 +21,8 @@ SocketStreamDispatcherHost::SocketStreamDispatcherHost( ...@@ -21,7 +21,8 @@ SocketStreamDispatcherHost::SocketStreamDispatcherHost(
int render_process_id, int render_process_id,
ResourceMessageFilter::URLRequestContextSelector* selector, ResourceMessageFilter::URLRequestContextSelector* selector,
content::ResourceContext* resource_context) 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), url_request_context_selector_(selector),
resource_context_(resource_context) { resource_context_(resource_context) {
DCHECK(selector); DCHECK(selector);
...@@ -110,9 +111,10 @@ void SocketStreamDispatcherHost::OnSSLCertificateError( ...@@ -110,9 +111,10 @@ void SocketStreamDispatcherHost::OnSSLCertificateError(
SocketStreamHost* socket_stream_host = hosts_.Lookup(socket_id); SocketStreamHost* socket_stream_host = hosts_.Lookup(socket_id);
DCHECK(socket_stream_host); DCHECK(socket_stream_host);
content::GlobalRequestID request_id(-1, socket_id); content::GlobalRequestID request_id(-1, socket_id);
SSLManager::OnSSLCertificateError(this, request_id, SSLManager::OnSSLCertificateError(ssl_delegate_weak_factory_.GetWeakPtr(),
ResourceType::SUB_RESOURCE, socket->url(), render_process_id_, request_id, ResourceType::SUB_RESOURCE, socket->url(),
socket_stream_host->render_view_id(), ssl_info, fatal); render_process_id_, socket_stream_host->render_view_id(), ssl_info,
fatal);
} }
bool SocketStreamDispatcherHost::CanGetCookies(net::SocketStream* socket, bool SocketStreamDispatcherHost::CanGetCookies(net::SocketStream* socket,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "base/id_map.h" #include "base/id_map.h"
#include "base/memory/weak_ptr.h"
#include "content/browser/renderer_host/resource_message_filter.h" #include "content/browser/renderer_host/resource_message_filter.h"
#include "content/browser/ssl/ssl_error_handler.h" #include "content/browser/ssl/ssl_error_handler.h"
#include "content/public/browser/browser_message_filter.h" #include "content/public/browser/browser_message_filter.h"
...@@ -80,6 +81,9 @@ class SocketStreamDispatcherHost : public content::BrowserMessageFilter, ...@@ -80,6 +81,9 @@ class SocketStreamDispatcherHost : public content::BrowserMessageFilter,
net::URLRequestContext* GetURLRequestContext(); net::URLRequestContext* GetURLRequestContext();
// For SSLErrorHandler::Delegate calls from SSLManager.
base::WeakPtrFactory<SSLErrorHandler::Delegate> ssl_delegate_weak_factory_;
IDMap<SocketStreamHost> hosts_; IDMap<SocketStreamHost> hosts_;
int render_process_id_; int render_process_id_;
const scoped_ptr<ResourceMessageFilter::URLRequestContextSelector> const scoped_ptr<ResourceMessageFilter::URLRequestContextSelector>
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
using content::ResourceDispatcherHostImpl; using content::ResourceDispatcherHostImpl;
SSLCertErrorHandler::SSLCertErrorHandler( SSLCertErrorHandler::SSLCertErrorHandler(
Delegate* delegate, base::WeakPtr<Delegate> delegate,
const content::GlobalRequestID& id, const content::GlobalRequestID& id,
ResourceType::Type resource_type, ResourceType::Type resource_type,
const GURL& url, const GURL& url,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#include "base/memory/weak_ptr.h"
#include "content/browser/ssl/ssl_error_handler.h" #include "content/browser/ssl/ssl_error_handler.h"
#include "net/base/ssl_info.h" #include "net/base/ssl_info.h"
...@@ -17,7 +18,7 @@ ...@@ -17,7 +18,7 @@
class SSLCertErrorHandler : public SSLErrorHandler { class SSLCertErrorHandler : public SSLErrorHandler {
public: public:
// Construct on the IO thread. // Construct on the IO thread.
SSLCertErrorHandler(Delegate* delegate, SSLCertErrorHandler(base::WeakPtr<Delegate> delegate,
const content::GlobalRequestID& id, const content::GlobalRequestID& id,
ResourceType::Type resource_type, ResourceType::Type resource_type,
const GURL& url, const GURL& url,
......
...@@ -19,7 +19,7 @@ using content::RenderViewHostImpl; ...@@ -19,7 +19,7 @@ using content::RenderViewHostImpl;
using content::WebContents; using content::WebContents;
using net::SSLInfo; using net::SSLInfo;
SSLErrorHandler::SSLErrorHandler(Delegate* delegate, SSLErrorHandler::SSLErrorHandler(base::WeakPtr<Delegate> delegate,
const content::GlobalRequestID& id, const content::GlobalRequestID& id,
ResourceType::Type resource_type, ResourceType::Type resource_type,
const GURL& url, const GURL& url,
...@@ -134,7 +134,8 @@ void SSLErrorHandler::CompleteCancelRequest(int error) { ...@@ -134,7 +134,8 @@ void SSLErrorHandler::CompleteCancelRequest(int error) {
const SSLInfo* ssl_info = NULL; const SSLInfo* ssl_info = NULL;
if (cert_error) if (cert_error)
ssl_info = &cert_error->ssl_info(); 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; request_has_been_notified_ = true;
// We're done with this object on the IO thread. // We're done with this object on the IO thread.
...@@ -151,7 +152,8 @@ void SSLErrorHandler::CompleteContinueRequest() { ...@@ -151,7 +152,8 @@ void SSLErrorHandler::CompleteContinueRequest() {
if (request_has_been_notified_) if (request_has_been_notified_)
return; return;
delegate_->ContinueSSLRequest(request_id_); if (delegate_)
delegate_->ContinueSSLRequest(request_id_);
request_has_been_notified_ = true; request_has_been_notified_ = true;
// We're done with this object on the IO thread. // We're done with this object on the IO thread.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/global_request_id.h" #include "content/public/browser/global_request_id.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
...@@ -105,7 +106,7 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { ...@@ -105,7 +106,7 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> {
friend class base::RefCountedThreadSafe<SSLErrorHandler>; friend class base::RefCountedThreadSafe<SSLErrorHandler>;
// Construct on the IO thread. // Construct on the IO thread.
SSLErrorHandler(Delegate* delegate, SSLErrorHandler(base::WeakPtr<Delegate> delegate,
const content::GlobalRequestID& id, const content::GlobalRequestID& id,
ResourceType::Type resource_type, ResourceType::Type resource_type,
const GURL& url, const GURL& url,
...@@ -128,7 +129,7 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { ...@@ -128,7 +129,7 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> {
content::GlobalRequestID request_id_; content::GlobalRequestID request_id_;
// The delegate we are associated with. // The delegate we are associated with.
Delegate* delegate_; base::WeakPtr<Delegate> delegate_;
private: private:
// Completes the CancelRequest operation on the IO thread. // Completes the CancelRequest operation on the IO thread.
......
...@@ -35,14 +35,15 @@ using content::SSLStatus; ...@@ -35,14 +35,15 @@ using content::SSLStatus;
using content::WebContents; using content::WebContents;
// static // static
void SSLManager::OnSSLCertificateError(SSLErrorHandler::Delegate* delegate, void SSLManager::OnSSLCertificateError(
const content::GlobalRequestID& id, base::WeakPtr<SSLErrorHandler::Delegate> delegate,
const ResourceType::Type resource_type, const content::GlobalRequestID& id,
const GURL& url, const ResourceType::Type resource_type,
int render_process_id, const GURL& url,
int render_view_id, int render_process_id,
const net::SSLInfo& ssl_info, int render_view_id,
bool fatal) { const net::SSLInfo& ssl_info,
bool fatal) {
DCHECK(delegate); DCHECK(delegate);
DVLOG(1) << "OnSSLCertificateError() cert_error: " DVLOG(1) << "OnSSLCertificateError() cert_error: "
<< net::MapCertStatusToNetError(ssl_info.cert_status) << net::MapCertStatusToNetError(ssl_info.cert_status)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.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_policy_backend.h"
#include "content/browser/ssl/ssl_error_handler.h" #include "content/browser/ssl/ssl_error_handler.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
...@@ -50,14 +51,15 @@ class SSLManager : public content::NotificationObserver { ...@@ -50,14 +51,15 @@ class SSLManager : public content::NotificationObserver {
// |ContinueSSLRequest| of |delegate| with |id| as the first argument. // |ContinueSSLRequest| of |delegate| with |id| as the first argument.
// //
// Called on the IO thread. // Called on the IO thread.
static void OnSSLCertificateError(SSLErrorHandler::Delegate* delegate, static void OnSSLCertificateError(
const content::GlobalRequestID& id, base::WeakPtr<SSLErrorHandler::Delegate> delegate,
ResourceType::Type resource_type, const content::GlobalRequestID& id,
const GURL& url, ResourceType::Type resource_type,
int render_process_id, const GURL& url,
int render_view_id, int render_process_id,
const net::SSLInfo& ssl_info, int render_view_id,
bool fatal); const net::SSLInfo& ssl_info,
bool fatal);
// Called when SSL state for a host or tab changes. Broadcasts the // Called when SSL state for a host or tab changes. Broadcasts the
// SSL_INTERNAL_STATE_CHANGED notification. // SSL_INTERNAL_STATE_CHANGED notification.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment