OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 | 52 |
53 class OCSPRequestSession; | 53 class OCSPRequestSession; |
54 | 54 |
55 class OCSPIOLoop { | 55 class OCSPIOLoop { |
56 public: | 56 public: |
57 void StartUsing() { | 57 void StartUsing() { |
58 base::AutoLock autolock(lock_); | 58 base::AutoLock autolock(lock_); |
59 used_ = true; | 59 used_ = true; |
60 io_loop_ = MessageLoopForIO::current(); | 60 io_loop_ = MessageLoopForIO::current(); |
61 DCHECK(io_loop_); | 61 DCHECK(io_loop_); |
62 // In tests |g_ocsp_io_loop| may be shut down and restarted. Ensure that | |
63 // the thread checker is associated with the correct thread after a restart | |
64 // to avoid DCHECK's going off later. | |
65 if (shutdown_) { | |
66 thread_checker_.DetachFromThread(); | |
67 thread_checker_.CalledOnValidThread(); | |
68 shutdown_ = false; | |
69 } | |
Ryan Sleevi
2012/11/05 14:43:31
Perhaps moving this into an explicit Reset() metho
blundell
2012/11/05 15:19:02
I thought about factoring this out into its own me
Ryan Sleevi
2012/11/06 15:43:47
IMO, yeah. Makes it easier to separate out bugs-in
| |
62 } | 70 } |
63 | 71 |
64 // Called on IO loop. | 72 // Called on IO loop. |
65 void Shutdown(); | 73 void Shutdown(); |
66 | 74 |
67 bool used() const { | 75 bool used() const { |
68 base::AutoLock autolock(lock_); | 76 base::AutoLock autolock(lock_); |
69 return used_; | 77 return used_; |
70 } | 78 } |
71 | 79 |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 | 923 |
916 } // anonymous namespace | 924 } // anonymous namespace |
917 | 925 |
918 void SetMessageLoopForNSSHttpIO() { | 926 void SetMessageLoopForNSSHttpIO() { |
919 // Must have a MessageLoopForIO. | 927 // Must have a MessageLoopForIO. |
920 DCHECK(MessageLoopForIO::current()); | 928 DCHECK(MessageLoopForIO::current()); |
921 | 929 |
922 bool used = g_ocsp_io_loop.Get().used(); | 930 bool used = g_ocsp_io_loop.Get().used(); |
923 | 931 |
924 // Should not be called when g_ocsp_io_loop has already been used. | 932 // Should not be called when g_ocsp_io_loop has already been used. |
925 DCHECK(!used); | 933 DCHECK(!used); |
Ryan Sleevi
2012/11/05 14:43:31
What about the fact that this is not reset?
Attem
blundell
2012/11/05 15:19:02
used_ is set to false in Shutdown() (where shutdow
| |
934 // Ensure that |g_ocsp_io_loop| is associated with the current message loop. | |
935 g_ocsp_io_loop.Get().StartUsing(); | |
Ryan Sleevi
2012/11/05 14:43:31
I'm not sure I understand the motivation here for
blundell
2012/11/05 15:19:02
|SetMessageLoopForNSSHttpIO| is called in |IOThrea
Ryan Sleevi
2012/11/06 15:43:47
I would prefer not to tightly couple these two (eg
| |
926 } | 936 } |
927 | 937 |
928 void EnsureNSSHttpIOInit() { | 938 void EnsureNSSHttpIOInit() { |
929 g_ocsp_io_loop.Get().StartUsing(); | 939 g_ocsp_io_loop.Get().StartUsing(); |
930 g_ocsp_nss_initialization.Get(); | 940 g_ocsp_nss_initialization.Get(); |
931 } | 941 } |
932 | 942 |
933 void ShutdownNSSHttpIO() { | 943 void ShutdownNSSHttpIO() { |
934 g_ocsp_io_loop.Get().Shutdown(); | 944 g_ocsp_io_loop.Get().Shutdown(); |
935 } | 945 } |
936 | 946 |
937 // This function would be called before NSS initialization. | 947 // This function would be called before NSS initialization. |
938 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { | 948 void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) { |
939 pthread_mutex_lock(&g_request_context_lock); | 949 pthread_mutex_lock(&g_request_context_lock); |
940 if (request_context) { | 950 if (request_context) { |
941 DCHECK(!g_request_context); | 951 DCHECK(!g_request_context); |
942 } | 952 } |
943 g_request_context = request_context; | 953 g_request_context = request_context; |
944 pthread_mutex_unlock(&g_request_context_lock); | 954 pthread_mutex_unlock(&g_request_context_lock); |
945 } | 955 } |
946 | 956 |
947 } // namespace net | 957 } // namespace net |
OLD | NEW |