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/dtls_identity_service_host.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/common/media/dtls_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 DTLSIdentityServiceHost::DTLSIdentityServiceHost( | |
| 15 DTLSIdentityStore* dtls_identity_store) | |
| 16 : dtls_identity_store_(dtls_identity_store) { | |
| 17 } | |
| 18 | |
| 19 DTLSIdentityServiceHost::~DTLSIdentityServiceHost() { | |
| 20 RequestCancellerMap::iterator it; | |
| 21 for (it = pending_request_canceller_map_.begin(); | |
| 22 it != pending_request_canceller_map_.end(); | |
| 23 ++it) { | |
| 24 it->second.Run(); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 bool DTLSIdentityServiceHost::OnMessageReceived(const IPC::Message& message, | |
| 29 bool* message_was_ok) { | |
| 30 bool handled = true; | |
| 31 IPC_BEGIN_MESSAGE_MAP_EX(DTLSIdentityServiceHost, message, *message_was_ok) | |
| 32 IPC_MESSAGE_HANDLER(DTLSIdentityMsg_RequestIdentity, OnRequestIdentity) | |
| 33 IPC_MESSAGE_HANDLER(DTLSIdentityMsg_CancelRequest, OnCancelRequest) | |
| 34 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 35 IPC_END_MESSAGE_MAP_EX() | |
| 36 return handled; | |
| 37 } | |
| 38 | |
| 39 void DTLSIdentityServiceHost::OnRequestIdentity( | |
| 40 int request_id, | |
| 41 const GURL& origin, | |
| 42 const std::string& identity_name, | |
| 43 const std::string& common_name) { | |
| 44 DCHECK(pending_request_canceller_map_.end() == | |
| 45 pending_request_canceller_map_.find(request_id)); | |
| 46 | |
| 47 base::Closure canceller; | |
| 48 bool success = dtls_identity_store_-> | |
| 49 RequestIdentity( | |
|
Ryan Sleevi
2013/06/17 23:08:34
style: Seems this wrapping is over-eager. Perhaps
jiayl
2013/06/18 01:07:55
Done.
| |
| 50 origin, | |
| 51 identity_name, | |
| 52 common_name, | |
| 53 base::Bind(&DTLSIdentityServiceHost::OnComplete, | |
| 54 base::Unretained(this), request_id), | |
| 55 &canceller); | |
| 56 if (success) | |
| 57 pending_request_canceller_map_[request_id] = canceller; | |
| 58 else | |
| 59 OnComplete(request_id, net::ERR_UNEXPECTED, std::string(), std::string()); | |
| 60 } | |
| 61 | |
| 62 void DTLSIdentityServiceHost::OnCancelRequest(int request_id) { | |
| 63 DCHECK(pending_request_canceller_map_.find(request_id) != | |
| 64 pending_request_canceller_map_.end()); | |
| 65 pending_request_canceller_map_[request_id].Run(); | |
| 66 pending_request_canceller_map_.erase(request_id); | |
| 67 } | |
| 68 | |
| 69 void DTLSIdentityServiceHost::OnComplete(int request_id, | |
| 70 int error, | |
| 71 const std::string& certificate, | |
| 72 const std::string& private_key) { | |
| 73 DCHECK(pending_request_canceller_map_.find(request_id) != | |
| 74 pending_request_canceller_map_.end()); | |
| 75 pending_request_canceller_map_.erase(request_id); | |
| 76 if (error == net::OK) { | |
| 77 Send(new DTLSIdentityHostMsg_IdentityReady(request_id, | |
| 78 certificate, | |
| 79 private_key)); | |
| 80 } else { | |
| 81 Send(new DTLSIdentityHostMsg_RequestFailed(request_id, error)); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 } // namespace content | |
| OLD | NEW |