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

Side by Side Diff: content/browser/renderer_host/media/webrtc_identity_service_host.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, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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/browser/renderer_host/media/webrtc_identity_service_host.h"
6
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "content/browser/media/webrtc_identity_store.h"
10 #include "content/common/media/webrtc_identity_messages.h"
11 #include "net/base/net_errors.h"
12
13 namespace content {
14
15 WebRTCIdentityServiceHost::WebRTCIdentityServiceHost(
16 WebRTCIdentityStore* identity_store)
17 : identity_store_(identity_store) {}
18
19 WebRTCIdentityServiceHost::~WebRTCIdentityServiceHost() {
20 if (cancel_callback_.is_null())
21 return;
22 cancel_callback_.Run();
23 }
24
25 bool WebRTCIdentityServiceHost::OnMessageReceived(const IPC::Message& message,
26 bool* message_was_ok) {
27 bool handled = true;
28 IPC_BEGIN_MESSAGE_MAP_EX(WebRTCIdentityServiceHost, message, *message_was_ok)
29 IPC_MESSAGE_HANDLER(WebRTCIdentityMsg_RequestIdentity, OnRequestIdentity)
30 IPC_MESSAGE_HANDLER(WebRTCIdentityMsg_CancelRequest, OnCancelRequest)
31 IPC_MESSAGE_UNHANDLED(handled = false)
32 IPC_END_MESSAGE_MAP_EX()
33 return handled;
34 }
35
36 void WebRTCIdentityServiceHost::OnRequestIdentity(
37 int request_id,
38 const GURL& origin,
39 const std::string& identity_name,
40 const std::string& common_name) {
41 if (!cancel_callback_.is_null()) {
42 DLOG(WARNING)
43 << "The request is rejected because there is already a pending request";
44 SendErrorMessage(request_id, net::ERR_INSUFFICIENT_RESOURCES);
45 return;
46 }
47 cancel_callback_ = identity_store_->RequestIdentity(
48 origin,
49 identity_name,
50 common_name,
51 base::Bind(&WebRTCIdentityServiceHost::OnComplete,
52 base::Unretained(this),
53 request_id));
54 if (cancel_callback_.is_null()) {
55 SendErrorMessage(request_id, net::ERR_UNEXPECTED);
56 }
57 }
58
59 void WebRTCIdentityServiceHost::OnCancelRequest(int request_id) {
60 base::ResetAndReturn(&cancel_callback_);
61 }
62
63 void WebRTCIdentityServiceHost::OnComplete(int request_id,
64 int error,
65 const std::string& certificate,
66 const std::string& private_key) {
67 cancel_callback_.Reset();
68 if (error == net::OK) {
69 Send(new WebRTCIdentityHostMsg_IdentityReady(
70 request_id, certificate, private_key));
71 } else {
72 SendErrorMessage(request_id, error);
73 }
74 }
75
76 void WebRTCIdentityServiceHost::SendErrorMessage(int request_id, int error) {
77 Send(new WebRTCIdentityHostMsg_RequestFailed(request_id, error));
78 }
79
80 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698