Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ssl / ssl_client_auth_observer.h
blobee2613481925541d32f659e6273a11d6ce828661
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_
6 #define CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
14 namespace net {
15 class SSLCertRequestInfo;
16 class X509Certificate;
19 namespace content {
20 class BrowserContext;
21 class ClientCertificateDelegate;
24 // SSLClientAuthObserver is a base class that wraps a
25 // ClientCertificateDelegate. It links client certificate selection dialogs
26 // attached to the same BrowserContext. When CertificateSelected is called via
27 // one of them, the rest simulate the same action.
28 class SSLClientAuthObserver : public content::NotificationObserver {
29 public:
30 SSLClientAuthObserver(
31 const content::BrowserContext* browser_context,
32 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info,
33 scoped_ptr<content::ClientCertificateDelegate> delegate);
34 ~SSLClientAuthObserver() override;
36 // UI should implement this to close the dialog.
37 virtual void OnCertSelectedByNotification() = 0;
39 // Continues the request with a certificate. Can also call with NULL to
40 // continue with no certificate. Derived classes must use this instead of
41 // caching the delegate and calling it directly.
42 void CertificateSelected(net::X509Certificate* cert);
44 // Cancels the certificate selection and aborts the request.
45 void CancelCertificateSelection();
47 // Begins observing notifications from other SSLClientAuthHandler instances.
48 // If another instance chooses a cert for a matching SSLCertRequestInfo, we
49 // will also use the same cert and OnCertSelectedByNotification will be called
50 // so that the cert selection UI can be closed.
51 void StartObserving();
53 // Stops observing notifications. We will no longer act on client auth
54 // notifications.
55 void StopObserving();
57 net::SSLCertRequestInfo* cert_request_info() const {
58 return cert_request_info_.get();
61 private:
62 // content::NotificationObserver implementation:
63 void Observe(int type,
64 const content::NotificationSource& source,
65 const content::NotificationDetails& details) override;
67 const content::BrowserContext* browser_context_;
68 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
69 scoped_ptr<content::ClientCertificateDelegate> delegate_;
70 content::NotificationRegistrar notification_registrar_;
72 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthObserver);
75 #endif // CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_