Home | History | Annotate | Download | only in media
      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.
      4 
      5 #include "content/renderer/media/peer_connection_identity_service.h"
      6 
      7 #include "content/renderer/media/webrtc_identity_service.h"
      8 #include "content/renderer/render_thread_impl.h"
      9 
     10 namespace content {
     11 
     12 PeerConnectionIdentityService* PeerConnectionIdentityService::Create(
     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 }
     23 
     24 PeerConnectionIdentityService::~PeerConnectionIdentityService() {
     25   if (pending_observer_)
     26     RenderThreadImpl::current()->get_webrtc_identity_service()
     27         ->CancelRequest(pending_request_id_);
     28 }
     29 
     30 bool PeerConnectionIdentityService::RequestIdentity(
     31     const std::string& identity_name,
     32     const std::string& common_name,
     33     webrtc::DTLSIdentityRequestObserver* observer) {
     34   DCHECK(observer);
     35   if (pending_observer_)
     36     return false;
     37 
     38   pending_observer_ = observer;
     39   pending_request_id_ = RenderThreadImpl::current()
     40       ->get_webrtc_identity_service()->RequestIdentity(
     41           origin_,
     42           identity_name,
     43           common_name,
     44           base::Bind(&PeerConnectionIdentityService::OnIdentityReady,
     45                      base::Unretained(this)),
     46           base::Bind(&PeerConnectionIdentityService::OnRequestFailed,
     47                      base::Unretained(this)));
     48   return true;
     49 }
     50 
     51 PeerConnectionIdentityService::PeerConnectionIdentityService(const GURL& origin)
     52     : origin_(origin), pending_observer_(NULL), pending_request_id_(0) {}
     53 
     54 void PeerConnectionIdentityService::OnIdentityReady(
     55     const std::string& certificate,
     56     const std::string& private_key) {
     57   pending_observer_->OnSuccess(certificate, private_key);
     58   ResetPendingRequest();
     59 }
     60 
     61 void PeerConnectionIdentityService::OnRequestFailed(int error) {
     62   pending_observer_->OnFailure(error);
     63   ResetPendingRequest();
     64 }
     65 
     66 void PeerConnectionIdentityService::ResetPendingRequest() {
     67   pending_observer_ = NULL;
     68   pending_request_id_ = 0;
     69 }
     70 
     71 }  // namespace content
     72