Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2309)

Unified Diff: content/renderer/media/webrtc_identity_service.cc

Issue 15969025: Generates the DTLS identity in browser process and returns it to render process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {
+ 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;
Ryan Sleevi 2013/06/27 18:05:24 Are you sure a static is appropriate here? Seems
jiayl 2013/06/27 18:29:36 WebRTCIdentityService is per peer connection, so m
+ 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;
+}
+
+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;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698