| Index: talk/app/webrtc/peerconnectionfactory.cc | 
| diff --git a/talk/app/webrtc/peerconnectionfactory.cc b/talk/app/webrtc/peerconnectionfactory.cc | 
| index 3524af7932a4f92f60da84e552f742d1a2aaa7ac..f48ccb25d1a9bc1271f02f490e86273df33110b6 100644 | 
| --- a/talk/app/webrtc/peerconnectionfactory.cc | 
| +++ b/talk/app/webrtc/peerconnectionfactory.cc | 
| @@ -28,8 +28,6 @@ | 
| #include "talk/app/webrtc/peerconnectionfactory.h" | 
|  | 
| #include "talk/app/webrtc/audiotrack.h" | 
| -#include "talk/app/webrtc/dtlsidentityservice.h" | 
| -#include "talk/app/webrtc/dtlsidentitystore.h" | 
| #include "talk/app/webrtc/localaudiosource.h" | 
| #include "talk/app/webrtc/mediastreamproxy.h" | 
| #include "talk/app/webrtc/mediastreamtrackproxy.h" | 
| @@ -49,6 +47,31 @@ | 
|  | 
| namespace webrtc { | 
|  | 
| +namespace { | 
| + | 
| +// Passes down the calls to |store_|. See usage in CreatePeerConnection. | 
| +class DtlsIdentityStoreWrapper : public DtlsIdentityStoreInterface { | 
| + public: | 
| +  DtlsIdentityStoreWrapper( | 
| +      const rtc::scoped_refptr<RefCountedDtlsIdentityStore>& store) | 
| +      : store_(store) { | 
| +    DCHECK(store_); | 
| +  } | 
| + | 
| +  void Initialize() override { | 
| +    store_->Initialize(); | 
| +  } | 
| +  void RequestIdentity(rtc::KeyType key_type, | 
| +                       ScopedRefPtrObserver observer) override { | 
| +    store_->RequestIdentity(key_type, observer); | 
| +  } | 
| + | 
| + private: | 
| +  rtc::scoped_refptr<RefCountedDtlsIdentityStore> store_; | 
| +}; | 
| + | 
| +}  // anonymous namespace | 
| + | 
| rtc::scoped_refptr<PeerConnectionFactoryInterface> | 
| CreatePeerConnectionFactory() { | 
| rtc::scoped_refptr<PeerConnectionFactory> pc_factory( | 
| @@ -130,12 +153,12 @@ PeerConnectionFactory::PeerConnectionFactory( | 
|  | 
| PeerConnectionFactory::~PeerConnectionFactory() { | 
| DCHECK(signaling_thread_->IsCurrent()); | 
| -  channel_manager_.reset(NULL); | 
| -  default_allocator_factory_ = NULL; | 
| +  channel_manager_.reset(nullptr); | 
| +  default_allocator_factory_ = nullptr; | 
|  | 
| // Make sure |worker_thread_| and |signaling_thread_| outlive | 
| // |dtls_identity_store_|. | 
| -  dtls_identity_store_.reset(NULL); | 
| +  dtls_identity_store_ = nullptr; | 
|  | 
| if (owns_ptrs_) { | 
| if (wraps_current_thread_) | 
| @@ -169,8 +192,8 @@ bool PeerConnectionFactory::Initialize() { | 
| return false; | 
| } | 
|  | 
| -  dtls_identity_store_.reset( | 
| -      new DtlsIdentityStore(signaling_thread_, worker_thread_)); | 
| +  dtls_identity_store_ = new RefCountedDtlsIdentityStore( | 
| +      signaling_thread_, worker_thread_); | 
| dtls_identity_store_->Initialize(); | 
|  | 
| return true; | 
| @@ -205,13 +228,17 @@ PeerConnectionFactory::CreatePeerConnection( | 
| const PeerConnectionInterface::RTCConfiguration& configuration, | 
| const MediaConstraintsInterface* constraints, | 
| PortAllocatorFactoryInterface* allocator_factory, | 
| -    DTLSIdentityServiceInterface* dtls_identity_service, | 
| +    rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | 
| PeerConnectionObserver* observer) { | 
| DCHECK(signaling_thread_->IsCurrent()); | 
| DCHECK(allocator_factory || default_allocator_factory_); | 
|  | 
| -  if (!dtls_identity_service) { | 
| -    dtls_identity_service = new DtlsIdentityService(dtls_identity_store_.get()); | 
| +  if (!dtls_identity_store.get()) { | 
| +    // Because |pc|->Initialize takes ownership of the store we need a new | 
| +    // wrapper object that can be deleted without deleting the underlying | 
| +    // |dtls_identity_store_|, protecting it from being deleted multiple times. | 
| +    dtls_identity_store.reset( | 
| +        new DtlsIdentityStoreWrapper(dtls_identity_store_)); | 
| } | 
|  | 
| PortAllocatorFactoryInterface* chosen_allocator_factory = | 
| @@ -224,7 +251,7 @@ PeerConnectionFactory::CreatePeerConnection( | 
| configuration, | 
| constraints, | 
| chosen_allocator_factory, | 
| -      dtls_identity_service, | 
| +      dtls_identity_store.Pass(), | 
| observer)) { | 
| return NULL; | 
| } | 
|  |