Chromium Code Reviews| Index: content/renderer/media/webrtc_identity_service.cc |
| diff --git a/content/renderer/media/webrtc_identity_service.cc b/content/renderer/media/webrtc_identity_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9378a690254d291a768737865b4e4fc0e37ce14f |
| --- /dev/null |
| +++ b/content/renderer/media/webrtc_identity_service.cc |
| @@ -0,0 +1,78 @@ |
| +// 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/webrtc_identity_service.h" |
| + |
| +#include "content/common/media/webrtc_identity_messages.h" |
| +#include "content/public/renderer/render_thread.h" |
| + |
| +namespace content { |
| + |
| +WebRTCIdentityService::WebRTCIdentityService(const GURL& origin) |
| + : origin_(origin), pending_observer_(NULL), pending_request_id_(0) { |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
s/0/-1/ to match browser side?
jiayl
2013/06/27 21:08:37
Browser side initial value removed.
|
| + RenderThread::Get()->AddObserver(this); |
| +} |
| + |
| +WebRTCIdentityService::~WebRTCIdentityService() { |
| + RenderThread::Get()->RemoveObserver(this); |
| + if (pending_observer_) { |
| + RenderThread::Get()->Send( |
| + new WebRTCIdentityMsg_CancelRequest(pending_request_id_)); |
| + } |
| +} |
| + |
| +bool WebRTCIdentityService::RequestIdentity( |
| + const std::string& identity_name, |
| + const std::string& common_name, |
| + webrtc::DTLSIdentityRequestObserver* observer) { |
| + static int s_next_request_id = 0; |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
This is not thread-safe.
You might want base::At
jiayl
2013/06/27 21:08:37
Done.
|
| + DCHECK(observer); |
| + if (pending_observer_) |
| + return false; |
| + |
| + pending_observer_ = observer; |
| + pending_request_id_ = s_next_request_id++; |
| + RenderThread::Get()->Send(new WebRTCIdentityMsg_RequestIdentity( |
| + pending_request_id_, origin_, identity_name, common_name)); |
| + return true; |
| +} |
| + |
| +bool WebRTCIdentityService::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(WebRTCIdentityService, message) |
| + IPC_MESSAGE_HANDLER(WebRTCIdentityHostMsg_IdentityReady, OnIdentityReady) |
| + IPC_MESSAGE_HANDLER(WebRTCIdentityHostMsg_RequestFailed, OnRequestFailed) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + |
| + if (pending_request_id_ == old_pending_request_id) |
| + handled = false; |
| + |
| + return handled; |
| +} |
| + |
| +void WebRTCIdentityService::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; |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
ditto s/0/-1/
|
| +} |
| + |
| +void WebRTCIdentityService::OnRequestFailed(int request_id, int error) { |
| + if (request_id != pending_request_id_) |
| + return; |
| + pending_observer_->OnFailure(error); |
| + pending_observer_ = NULL; |
| + pending_request_id_ = 0; |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
ditto s/0/-1/
|
| +} |
| + |
| +} // namespace content |