OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/ocsp/nss_ocsp.h" | 5 #include "net/ocsp/nss_ocsp.h" |
6 | 6 |
7 #include <certt.h> | 7 #include <certt.h> |
8 #include <certdb.h> | 8 #include <certdb.h> |
9 #include <ocsp.h> | 9 #include <ocsp.h> |
10 #include <nspr.h> | 10 #include <nspr.h> |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "net/http/http_response_headers.h" | 34 #include "net/http/http_response_headers.h" |
35 #include "net/url_request/url_request.h" | 35 #include "net/url_request/url_request.h" |
36 #include "net/url_request/url_request_context.h" | 36 #include "net/url_request/url_request_context.h" |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // Protects |g_request_context|. | 40 // Protects |g_request_context|. |
41 pthread_mutex_t g_request_context_lock = PTHREAD_MUTEX_INITIALIZER; | 41 pthread_mutex_t g_request_context_lock = PTHREAD_MUTEX_INITIALIZER; |
42 static net::URLRequestContext* g_request_context = NULL; | 42 static net::URLRequestContext* g_request_context = NULL; |
43 | 43 |
44 static bool g_disable_ocsp = false; | |
45 | |
46 class OCSPRequestSession; | 44 class OCSPRequestSession; |
47 | 45 |
48 class OCSPIOLoop { | 46 class OCSPIOLoop { |
49 public: | 47 public: |
50 void StartUsing() { | 48 void StartUsing() { |
51 base::AutoLock autolock(lock_); | 49 base::AutoLock autolock(lock_); |
52 used_ = true; | 50 used_ = true; |
53 } | 51 } |
54 | 52 |
55 // Called on IO loop. | 53 // Called on IO loop. |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 } | 902 } |
905 | 903 |
906 return NULL; | 904 return NULL; |
907 } | 905 } |
908 | 906 |
909 } // anonymous namespace | 907 } // anonymous namespace |
910 | 908 |
911 namespace net { | 909 namespace net { |
912 | 910 |
913 void SetMessageLoopForOCSP() { | 911 void SetMessageLoopForOCSP() { |
914 // Must not be called when OCSP is disabled. | |
915 DCHECK(!g_disable_ocsp); | |
916 | |
917 // Must have a MessageLoopForIO. | 912 // Must have a MessageLoopForIO. |
918 DCHECK(MessageLoopForIO::current()); | 913 DCHECK(MessageLoopForIO::current()); |
919 | 914 |
920 bool used = g_ocsp_io_loop.Get().used(); | 915 bool used = g_ocsp_io_loop.Get().used(); |
921 | 916 |
922 // Should not be called when g_ocsp_io_loop has already been used. | 917 // Should not be called when g_ocsp_io_loop has already been used. |
923 DCHECK(!used); | 918 DCHECK(!used); |
924 } | 919 } |
925 | 920 |
926 void DisableOCSP() { | |
927 g_disable_ocsp = true; | |
928 } | |
929 | |
930 void EnsureOCSPInit() { | 921 void EnsureOCSPInit() { |
931 if (!g_disable_ocsp) { | 922 g_ocsp_io_loop.Get().StartUsing(); |
932 g_ocsp_io_loop.Get().StartUsing(); | 923 g_ocsp_nss_initialization.Get(); |
933 g_ocsp_nss_initialization.Get(); | |
934 } | |
935 } | 924 } |
936 | 925 |
937 void ShutdownOCSP() { | 926 void ShutdownOCSP() { |
938 if (!g_disable_ocsp) | 927 g_ocsp_io_loop.Get().Shutdown(); |
939 g_ocsp_io_loop.Get().Shutdown(); | |
940 } | 928 } |
941 | 929 |
942 // This function would be called before NSS initialization. | 930 // This function would be called before NSS initialization. |
943 void SetURLRequestContextForOCSP(URLRequestContext* request_context) { | 931 void SetURLRequestContextForOCSP(URLRequestContext* request_context) { |
944 // Must not be called when OCSP is disabled. | |
945 DCHECK(!g_disable_ocsp); | |
946 | |
947 pthread_mutex_lock(&g_request_context_lock); | 932 pthread_mutex_lock(&g_request_context_lock); |
948 if (request_context) { | 933 if (request_context) { |
949 DCHECK(!g_request_context); | 934 DCHECK(!g_request_context); |
950 } | 935 } |
951 g_request_context = request_context; | 936 g_request_context = request_context; |
952 pthread_mutex_unlock(&g_request_context_lock); | 937 pthread_mutex_unlock(&g_request_context_lock); |
953 } | 938 } |
954 | 939 |
955 } // namespace net | 940 } // namespace net |
OLD | NEW |