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()
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) {
......
......@@ -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_;
......
......@@ -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,
......
......@@ -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>
......
......@@ -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,
......
......@@ -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,
......
......@@ -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.
......
......@@ -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.
......
......@@ -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)
......
......@@ -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.
......
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