1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_SSL_SSL_ADD_CERT_HANDLER_H_ 6#define CHROME_BROWSER_SSL_SSL_ADD_CERT_HANDLER_H_ 7#pragma once 8 9#include "base/basictypes.h" 10#include "base/memory/ref_counted.h" 11 12namespace net { 13class URLRequest; 14class X509Certificate; 15} 16 17// This class handles adding a newly-generated client cert. It ensures there's a 18// private key for the cert, displays the cert to the user, and adds it upon 19// user approval. 20// It is self-owned and deletes itself when finished. 21class SSLAddCertHandler : public base::RefCountedThreadSafe<SSLAddCertHandler> { 22 public: 23 SSLAddCertHandler(net::URLRequest* request, net::X509Certificate* cert, 24 int render_process_host_id, int render_view_id); 25 26 net::X509Certificate* cert() { return cert_; } 27 28 int network_request_id() const { return network_request_id_; } 29 30 // The platform-specific code calls this when it's done, to clean up. 31 // If |addCert| is true, the cert will be added to the CertDatabase. 32 void Finished(bool add_cert); 33 34 private: 35 friend class base::RefCountedThreadSafe<SSLAddCertHandler>; 36 virtual ~SSLAddCertHandler(); 37 38 // Runs the handler. Called on the IO thread. 39 void Run(); 40 41 // Platform-specific code that asks the user whether to add the cert. 42 // Called on the UI thread. 43 void AskToAddCert(); 44 45 // The cert to add. 46 scoped_refptr<net::X509Certificate> cert_; 47 48 // The id of the request which started the process. 49 int network_request_id_; 50 // The id of the |RenderProcessHost| which started the download. 51 int render_process_host_id_; 52 // The id of the |RenderView| which started the download. 53 int render_view_id_; 54 55 DISALLOW_COPY_AND_ASSIGN(SSLAddCertHandler); 56}; 57 58#endif // CHROME_BROWSER_SSL_SSL_ADD_CERT_HANDLER_H_ 59