| Index: content/renderer/media/dtls_identity_service.cc
|
| diff --git a/content/renderer/media/dtls_identity_service.cc b/content/renderer/media/dtls_identity_service.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..78ad9d59703b6d834fba6ab7e0dc94687390165e
|
| --- /dev/null
|
| +++ b/content/renderer/media/dtls_identity_service.cc
|
| @@ -0,0 +1,79 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/renderer/media/dtls_identity_service.h"
|
| +
|
| +#include "content/common/media/dtls_identity_messages.h"
|
| +#include "content/public/renderer/render_thread.h"
|
| +
|
| +namespace content {
|
| +
|
| +DTLSIdentityService::DTLSIdentityService(const GURL& origin)
|
| + : origin_(origin), pending_observer_(NULL), pending_request_id_(0) {
|
| + RenderThread::Get()->AddObserver(this);
|
| +}
|
| +
|
| +DTLSIdentityService::~DTLSIdentityService() {
|
| + RenderThread::Get()->RemoveObserver(this);
|
| + if (pending_observer_) {
|
| + RenderThread::Get()->Send(
|
| + new DTLSIdentityMsg_CancelRequest(pending_request_id_));
|
| + }
|
| +}
|
| +
|
| +bool DTLSIdentityService::RequestIdentity(
|
| + const std::string& identity_name,
|
| + const std::string& common_name,
|
| + webrtc::DTLSIdentityRequestObserver* observer) {
|
| + static int s_next_request_id = 0;
|
| + DCHECK(observer);
|
| + if (pending_observer_)
|
| + return false;
|
| +
|
| + pending_observer_ = observer;
|
| + pending_request_id_ = s_next_request_id++;
|
| + RenderThread::Get()->Send(
|
| + new DTLSIdentityMsg_RequestIdentity(
|
| + pending_request_id_, origin_, identity_name, common_name));
|
| + return true;
|
| +}
|
| +
|
| +bool DTLSIdentityService::OnControlMessageReceived(
|
| + const IPC::Message& message) {
|
| + if (!pending_observer_)
|
| + return false;
|
| +
|
| + int old_pending_request_id = pending_request_id_;
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(DTLSIdentityService, message)
|
| + IPC_MESSAGE_HANDLER(DTLSIdentityHostMsg_IdentityReady, OnIdentityReady)
|
| + IPC_MESSAGE_HANDLER(DTLSIdentityHostMsg_RequestFailed, OnRequestFailed)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| +
|
| + if (pending_request_id_ == old_pending_request_id)
|
| + handled = false;
|
| +
|
| + return handled;
|
| +}
|
| +
|
| +void DTLSIdentityService::OnIdentityReady(int request_id,
|
| + const std::string& certificate,
|
| + const std::string& private_key) {
|
| + if (request_id != pending_request_id_)
|
| + return;
|
| + pending_observer_->OnSuccess(certificate, private_key);
|
| + pending_observer_ = NULL;
|
| + pending_request_id_ = 0;
|
| +}
|
| +
|
| +void DTLSIdentityService::OnRequestFailed(int request_id, int error) {
|
| + if (request_id != pending_request_id_)
|
| + return;
|
| + pending_observer_->OnFailure(error);
|
| + pending_observer_ = NULL;
|
| + pending_request_id_ = 0;
|
| +}
|
| +
|
| +} // namespace content
|
|
|