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/browser/renderer_host/media/webrtc_identity_service_host.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/common/media/webrtc_identity_messages.h" | |
| 9 #include "content/public/browser/render_process_host.h" | |
| 10 #include "net/base/net_errors.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 WebRTCIdentityServiceHost::WebRTCIdentityServiceHost( | |
| 15 WebRTCIdentityStore* identity_store) | |
| 16 : pending_request_id_(-1), identity_store_(identity_store) {} | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
This assumes -1 is not a valid request_id. Should
jiayl
2013/06/27 21:08:37
Removed.
| |
| 17 | |
| 18 WebRTCIdentityServiceHost::~WebRTCIdentityServiceHost() { | |
| 19 if (cancel_callback_.is_null()) | |
| 20 return; | |
| 21 cancel_callback_.Run(); | |
| 22 } | |
| 23 | |
| 24 bool WebRTCIdentityServiceHost::OnMessageReceived(const IPC::Message& message, | |
| 25 bool* message_was_ok) { | |
| 26 bool handled = true; | |
| 27 IPC_BEGIN_MESSAGE_MAP_EX(WebRTCIdentityServiceHost, message, *message_was_ok) | |
| 28 IPC_MESSAGE_HANDLER(WebRTCIdentityMsg_RequestIdentity, OnRequestIdentity) | |
| 29 IPC_MESSAGE_HANDLER(WebRTCIdentityMsg_CancelRequest, OnCancelRequest) | |
| 30 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 31 IPC_END_MESSAGE_MAP_EX() | |
| 32 return handled; | |
| 33 } | |
| 34 | |
| 35 void WebRTCIdentityServiceHost::OnRequestIdentity( | |
| 36 int request_id, | |
| 37 const GURL& origin, | |
| 38 const std::string& identity_name, | |
| 39 const std::string& common_name) { | |
| 40 if (!cancel_callback_.is_null()) { | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
|| pending_request_id_ != -1
?
(put another way,
| |
| 41 DLOG(WARNING) | |
| 42 << "The request is rejected because there is already a pending request"; | |
| 43 SendErrorMessage(request_id, net::ERR_INSUFFICIENT_RESOURCES); | |
| 44 return; | |
| 45 } | |
| 46 bool success = identity_store_->RequestIdentity( | |
| 47 origin, | |
| 48 identity_name, | |
| 49 common_name, | |
| 50 base::Bind(&WebRTCIdentityServiceHost::OnComplete, | |
| 51 base::Unretained(this), | |
| 52 request_id), | |
| 53 &cancel_callback_); | |
| 54 if (success) { | |
| 55 pending_request_id_ = request_id; | |
| 56 } else { | |
| 57 SendErrorMessage(request_id, net::ERR_UNEXPECTED); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 void WebRTCIdentityServiceHost::OnCancelRequest(int request_id) { | |
| 62 if (request_id != pending_request_id_ || cancel_callback_.is_null()) | |
| 63 return; | |
| 64 cancel_callback_.Run(); | |
| 65 cancel_callback_.Reset(); | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
base::ResetAndRun(&cancel_callback_);
?
jiayl
2013/06/27 21:08:37
Done.
| |
| 66 pending_request_id_ = -1; | |
| 67 } | |
| 68 | |
| 69 void WebRTCIdentityServiceHost::OnComplete(int request_id, | |
| 70 int error, | |
| 71 const std::string& certificate, | |
| 72 const std::string& private_key) { | |
| 73 DCHECK_EQ(request_id, pending_request_id_); | |
|
Ami GONE FROM CHROMIUM
2013/06/27 20:05:18
Why does pending_request_id_ exist?
If it's to saf
jiayl
2013/06/27 21:08:37
Done.
| |
| 74 | |
| 75 pending_request_id_ = -1; | |
| 76 cancel_callback_.Reset(); | |
| 77 if (error == net::OK) { | |
| 78 Send(new WebRTCIdentityHostMsg_IdentityReady( | |
| 79 request_id, certificate, private_key)); | |
| 80 } else { | |
| 81 SendErrorMessage(request_id, error); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 void WebRTCIdentityServiceHost::SendErrorMessage(int request_id, int error) { | |
| 86 Send(new WebRTCIdentityHostMsg_RequestFailed(request_id, error)); | |
| 87 } | |
| 88 | |
| 89 } // namespace content | |
| OLD | NEW |