OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/peer_connection_identity_service.h" | 5 #include "content/renderer/media/peer_connection_identity_service.h" |
6 | 6 |
7 #include "content/renderer/media/webrtc_identity_service.h" | 7 #include "content/renderer/media/webrtc_identity_service.h" |
8 #include "content/renderer/render_thread_impl.h" | 8 #include "content/renderer/render_thread_impl.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 PeerConnectionIdentityService::PeerConnectionIdentityService(const GURL& origin) | 12 PeerConnectionIdentityService* PeerConnectionIdentityService::Create( |
13 : origin_(origin), pending_observer_(NULL), pending_request_id_(0) {} | 13 const GURL& origin) { |
| 14 // The crypto APIs needed for generating identities are not implenented for |
| 15 // OPENSSL yet (crbug/91512). So returning NULL in that case. |
| 16 // TODO(jiayl): remove the #if once the crypto APIs are implemented for OPENSSL. |
| 17 #if defined(USE_OPENSSL) |
| 18 return NULL; |
| 19 #else |
| 20 return new PeerConnectionIdentityService(origin); |
| 21 #endif // defined(USE_OPENSSL) |
| 22 } |
14 | 23 |
15 PeerConnectionIdentityService::~PeerConnectionIdentityService() { | 24 PeerConnectionIdentityService::~PeerConnectionIdentityService() { |
16 if (pending_observer_) | 25 if (pending_observer_) |
17 RenderThreadImpl::current()->get_webrtc_identity_service() | 26 RenderThreadImpl::current()->get_webrtc_identity_service() |
18 ->CancelRequest(pending_request_id_); | 27 ->CancelRequest(pending_request_id_); |
19 } | 28 } |
20 | 29 |
21 bool PeerConnectionIdentityService::RequestIdentity( | 30 bool PeerConnectionIdentityService::RequestIdentity( |
22 const std::string& identity_name, | 31 const std::string& identity_name, |
23 const std::string& common_name, | 32 const std::string& common_name, |
24 webrtc::DTLSIdentityRequestObserver* observer) { | 33 webrtc::DTLSIdentityRequestObserver* observer) { |
25 DCHECK(observer); | 34 DCHECK(observer); |
26 if (pending_observer_) | 35 if (pending_observer_) |
27 return false; | 36 return false; |
28 | 37 |
29 pending_observer_ = observer; | 38 pending_observer_ = observer; |
30 pending_request_id_ = RenderThreadImpl::current() | 39 pending_request_id_ = RenderThreadImpl::current() |
31 ->get_webrtc_identity_service()->RequestIdentity( | 40 ->get_webrtc_identity_service()->RequestIdentity( |
32 origin_, | 41 origin_, |
33 identity_name, | 42 identity_name, |
34 common_name, | 43 common_name, |
35 base::Bind(&PeerConnectionIdentityService::OnIdentityReady, | 44 base::Bind(&PeerConnectionIdentityService::OnIdentityReady, |
36 base::Unretained(this)), | 45 base::Unretained(this)), |
37 base::Bind(&PeerConnectionIdentityService::OnRequestFailed, | 46 base::Bind(&PeerConnectionIdentityService::OnRequestFailed, |
38 base::Unretained(this))); | 47 base::Unretained(this))); |
39 return true; | 48 return true; |
40 } | 49 } |
41 | 50 |
| 51 PeerConnectionIdentityService::PeerConnectionIdentityService(const GURL& origin) |
| 52 : origin_(origin), pending_observer_(NULL), pending_request_id_(0) {} |
| 53 |
42 void PeerConnectionIdentityService::OnIdentityReady( | 54 void PeerConnectionIdentityService::OnIdentityReady( |
43 const std::string& certificate, | 55 const std::string& certificate, |
44 const std::string& private_key) { | 56 const std::string& private_key) { |
45 pending_observer_->OnSuccess(certificate, private_key); | 57 pending_observer_->OnSuccess(certificate, private_key); |
46 ResetPendingRequest(); | 58 ResetPendingRequest(); |
47 } | 59 } |
48 | 60 |
49 void PeerConnectionIdentityService::OnRequestFailed(int error) { | 61 void PeerConnectionIdentityService::OnRequestFailed(int error) { |
50 pending_observer_->OnFailure(error); | 62 pending_observer_->OnFailure(error); |
51 ResetPendingRequest(); | 63 ResetPendingRequest(); |
52 } | 64 } |
53 | 65 |
54 void PeerConnectionIdentityService::ResetPendingRequest() { | 66 void PeerConnectionIdentityService::ResetPendingRequest() { |
55 pending_observer_ = NULL; | 67 pending_observer_ = NULL; |
56 pending_request_id_ = 0; | 68 pending_request_id_ = 0; |
57 } | 69 } |
58 | 70 |
59 } // namespace content | 71 } // namespace content |
OLD | NEW |