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
3 // found in the LICENSE file.
5 #include "content/renderer/media/peer_connection_identity_service.h"
7 #include "content/renderer/media/webrtc_identity_service.h"
8 #include "content/renderer/render_thread_impl.h"
12 PeerConnectionIdentityService::PeerConnectionIdentityService(const GURL
& origin
)
13 : origin_(origin
), pending_observer_(NULL
), pending_request_id_(0) {}
15 PeerConnectionIdentityService::~PeerConnectionIdentityService() {
16 if (pending_observer_
)
17 RenderThreadImpl::current()->get_webrtc_identity_service()
18 ->CancelRequest(pending_request_id_
);
21 bool PeerConnectionIdentityService::RequestIdentity(
22 const std::string
& identity_name
,
23 const std::string
& common_name
,
24 webrtc::DTLSIdentityRequestObserver
* observer
) {
26 if (pending_observer_
)
29 pending_observer_
= observer
;
30 pending_request_id_
= RenderThreadImpl::current()
31 ->get_webrtc_identity_service()->RequestIdentity(
35 base::Bind(&PeerConnectionIdentityService::OnIdentityReady
,
36 base::Unretained(this)),
37 base::Bind(&PeerConnectionIdentityService::OnRequestFailed
,
38 base::Unretained(this)));
42 void PeerConnectionIdentityService::OnIdentityReady(
43 const std::string
& certificate
,
44 const std::string
& private_key
) {
45 pending_observer_
->OnSuccess(certificate
, private_key
);
46 ResetPendingRequest();
49 void PeerConnectionIdentityService::OnRequestFailed(int error
) {
50 pending_observer_
->OnFailure(error
);
51 ResetPendingRequest();
54 void PeerConnectionIdentityService::ResetPendingRequest() {
55 pending_observer_
= NULL
;
56 pending_request_id_
= 0;
59 } // namespace content