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