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

Side by Side 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, 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/renderer/media/webrtc_identity_service.h"
6
7 #include "base/atomic_sequence_num.h"
8 #include "content/common/media/webrtc_identity_messages.h"
9 #include "content/public/renderer/render_thread.h"
10
11 namespace content {
12
13 WebRTCIdentityService::WebRTCIdentityService(const GURL& origin)
14 : origin_(origin), pending_observer_(NULL), pending_request_id_(0) {
15 RenderThread::Get()->AddObserver(this);
16 }
17
18 WebRTCIdentityService::~WebRTCIdentityService() {
19 RenderThread::Get()->RemoveObserver(this);
20 if (pending_observer_) {
21 RenderThread::Get()->Send(
22 new WebRTCIdentityMsg_CancelRequest(pending_request_id_));
23 }
24 }
25
26 bool WebRTCIdentityService::RequestIdentity(
27 const std::string& identity_name,
28 const std::string& common_name,
29 webrtc::DTLSIdentityRequestObserver* observer) {
30 static base::AtomicSequenceNumber s_next_request_id;
Ami GONE FROM CHROMIUM 2013/06/27 21:30:32 "static" storage generally is a code smell so good
jiayl 2013/06/27 21:48:28 Done.
31
32 DCHECK(observer);
33 if (pending_observer_)
34 return false;
35
36 pending_observer_ = observer;
37 pending_request_id_ = s_next_request_id.GetNext();
38 RenderThread::Get()->Send(new WebRTCIdentityMsg_RequestIdentity(
39 pending_request_id_, origin_, identity_name, common_name));
40 return true;
41 }
42
43 bool WebRTCIdentityService::OnControlMessageReceived(
44 const IPC::Message& message) {
45 if (!pending_observer_)
46 return false;
47
48 int old_pending_request_id = pending_request_id_;
49 bool handled = true;
50 IPC_BEGIN_MESSAGE_MAP(WebRTCIdentityService, message)
51 IPC_MESSAGE_HANDLER(WebRTCIdentityHostMsg_IdentityReady, OnIdentityReady)
52 IPC_MESSAGE_HANDLER(WebRTCIdentityHostMsg_RequestFailed, OnRequestFailed)
53 IPC_MESSAGE_UNHANDLED(handled = false)
54 IPC_END_MESSAGE_MAP()
55
56 if (pending_request_id_ == old_pending_request_id)
57 handled = false;
58
59 return handled;
60 }
61
62 void WebRTCIdentityService::OnIdentityReady(int request_id,
63 const std::string& certificate,
64 const std::string& private_key) {
65 if (request_id != pending_request_id_)
66 return;
67 pending_observer_->OnSuccess(certificate, private_key);
68 pending_observer_ = NULL;
69 pending_request_id_ = 0;
70 }
71
72 void WebRTCIdentityService::OnRequestFailed(int request_id, int error) {
73 if (request_id != pending_request_id_)
74 return;
75 pending_observer_->OnFailure(error);
76 pending_observer_ = NULL;
77 pending_request_id_ = 0;
78 }
79
80 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698