summaryrefslogtreecommitdiffstats
path: root/content/browser/ssl/ssl_client_auth_handler.h
diff options
context:
space:
mode:
authordavidben <davidben@chromium.org>2014-12-03 11:41:51 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-03 19:42:30 +0000
commit78fee7dab63602d70b5fe3f58ee114d2968187a6 (patch)
treec06da125d52b7d39029512389f6cbb9005c68c60 /content/browser/ssl/ssl_client_auth_handler.h
parent426c5c108f7d63cfe388a0442c31cd1e7f006e34 (diff)
downloadchromium_src-78fee7dab63602d70b5fe3f58ee114d2968187a6.zip
chromium_src-78fee7dab63602d70b5fe3f58ee114d2968187a6.tar.gz
chromium_src-78fee7dab63602d70b5fe3f58ee114d2968187a6.tar.bz2
Re-revert of "Remove SSLClientAuthHandler's RDH dependency." (https://codereview.chromium.org/596873002)
Reason for revert: Causes browser crash if URL request is cancelled during client cert loading. This is a reland of https://codereview.chromium.org/766463002/ which reverted https://codereview.chromium.org/596873002. The revert was reverted because it introduced a memory leak. The source of this memory leak was a reference cycle in chrome/browser/chromeos/net/client_cert_filter_chromeos.cc whose fix is included in this CL. If InitIfSlotsAvailable returns true (synchronously), the callback should not be retained. This was not a problem before as the code in question was introduced after https://codereview.chromium.org/596873002 which unrefcounted an object. After this is merged into M-40, https://codereview.chromium.org/596873002 should be reworked with the crash fixed as this reference cycle is too subtle and the object really needn't be reference-counted. TBR=mmenke@chromium.org,benm@chromium.org,jam@chromium.org BUG=422765, 427844, 376003 Review URL: https://codereview.chromium.org/773003004 Cr-Commit-Position: refs/heads/master@{#306649}
Diffstat (limited to 'content/browser/ssl/ssl_client_auth_handler.h')
-rw-r--r--content/browser/ssl/ssl_client_auth_handler.h58
1 files changed, 40 insertions, 18 deletions
diff --git a/content/browser/ssl/ssl_client_auth_handler.h b/content/browser/ssl/ssl_client_auth_handler.h
index f95e65d..b848d54 100644
--- a/content/browser/ssl/ssl_client_auth_handler.h
+++ b/content/browser/ssl/ssl_client_auth_handler.h
@@ -6,57 +6,79 @@
#define CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_
#include "base/basictypes.h"
-#include "base/callback.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
+#include "base/sequenced_task_runner_helpers.h"
+#include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h"
#include "net/ssl/ssl_cert_request_info.h"
namespace net {
class ClientCertStore;
+class HttpNetworkSession;
class URLRequest;
class X509Certificate;
} // namespace net
namespace content {
+class ResourceContext;
+
// This class handles the approval and selection of a certificate for SSL client
-// authentication by the user. Should only be used on the IO thread. If the
-// SSLClientAuthHandler is destroyed before the certificate is selected, the
-// selection is canceled and the callback never called.
-class SSLClientAuthHandler {
+// authentication by the user.
+// It is self-owned and deletes itself when the UI reports the user selection or
+// when the net::URLRequest is cancelled.
+class CONTENT_EXPORT SSLClientAuthHandler
+ : public base::RefCountedThreadSafe<
+ SSLClientAuthHandler, BrowserThread::DeleteOnIOThread> {
public:
- typedef base::Callback<void(net::X509Certificate*)> CertificateCallback;
-
SSLClientAuthHandler(scoped_ptr<net::ClientCertStore> client_cert_store,
net::URLRequest* request,
- net::SSLCertRequestInfo* cert_request_info,
- const CertificateCallback& callback);
- ~SSLClientAuthHandler();
+ net::SSLCertRequestInfo* cert_request_info);
// Selects a certificate and resumes the URL request with that certificate.
+ // Should only be called on the IO thread.
void SelectCertificate();
+ // Invoked when the request associated with this handler is cancelled.
+ // Should only be called on the IO thread.
+ void OnRequestCancelled();
+
+ // Calls DoCertificateSelected on the I/O thread.
+ // Called on the UI thread after the user has made a selection (which may
+ // be long after DoSelectCertificate returns, if the UI is modeless/async.)
+ void CertificateSelected(net::X509Certificate* cert);
+
+ protected:
+ virtual ~SSLClientAuthHandler();
+
private:
+ friend class base::RefCountedThreadSafe<
+ SSLClientAuthHandler, BrowserThread::DeleteOnIOThread>;
+ friend class BrowserThread;
+ friend class base::DeleteHelper<SSLClientAuthHandler>;
+
// Called when ClientCertStore is done retrieving the cert list.
void DidGetClientCerts();
- // Called when the user has selected a cert.
- void CertificateSelected(net::X509Certificate* cert);
+ // Notifies that the user has selected a cert.
+ // Called on the IO thread.
+ void DoCertificateSelected(net::X509Certificate* cert);
+
+ // Selects a client certificate on the UI thread.
+ void DoSelectCertificate(int render_process_host_id,
+ int render_frame_host_id);
// The net::URLRequest that triggered this client auth.
net::URLRequest* request_;
+ // The HttpNetworkSession |request_| is associated with.
+ const net::HttpNetworkSession* http_network_session_;
+
// The certs to choose from.
scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
scoped_ptr<net::ClientCertStore> client_cert_store_;
- // The callback to call when the certificate is selected.
- CertificateCallback callback_;
-
- base::WeakPtrFactory<SSLClientAuthHandler> weak_factory_;
-
DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler);
};