OLD | NEW |
| (Empty) |
1 // Copyright 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 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_IDENTITY_SERVICE_H_ | |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_IDENTITY_SERVICE_H_ | |
7 | |
8 #include <deque> | |
9 #include <string> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/macros.h" | |
13 #include "content/common/content_export.h" | |
14 #include "content/common/media/webrtc_identity_messages.h" | |
15 #include "content/public/renderer/render_thread_observer.h" | |
16 #include "url/gurl.h" | |
17 | |
18 namespace content { | |
19 | |
20 // This class handles WebRTC DTLS identity requests by sending IPC messages to | |
21 // the browser process. Only one request is sent to the browser at a time; other | |
22 // requests are queued and have to wait for the outstanding request to complete. | |
23 class CONTENT_EXPORT WebRTCIdentityService : public RenderThreadObserver { | |
24 public: | |
25 typedef base::Callback< | |
26 void(const std::string& certificate, const std::string& private_key)> | |
27 SuccessCallback; | |
28 | |
29 typedef base::Callback<void(int error)> FailureCallback; | |
30 | |
31 WebRTCIdentityService(); | |
32 ~WebRTCIdentityService() override; | |
33 | |
34 // Sends an identity request. | |
35 // | |
36 // |url| is the frame url of the caller; | |
37 // |first_party_for_cookies| is the first party url for checking cookie | |
38 // policies. | |
39 // |identity_name| and |common_name| have the same meaning as in | |
40 // webrtc::DTLSIdentityServiceInterface::RequestIdentity; | |
41 // |success_callback| is the callback if the identity is successfully | |
42 // returned; | |
43 // |failure_callback| is the callback if the identity request fails. | |
44 // | |
45 // The request id is returned. It's unique within the renderer and can be used | |
46 // to cancel the request. | |
47 int RequestIdentity(const GURL& url, | |
48 const GURL& first_party_for_cookies, | |
49 const std::string& identity_name, | |
50 const std::string& common_name, | |
51 const SuccessCallback& success_callback, | |
52 const FailureCallback& failure_callback); | |
53 | |
54 // Cancels a previous request and the callbacks will not be called. | |
55 // If the |request_id| is not associated with the | |
56 // outstanding request or any queued request, this method does nothing. | |
57 // | |
58 // |request_id| is the request id returned from RequestIdentity. | |
59 void CancelRequest(int request_id); | |
60 | |
61 protected: | |
62 // For unittest to override. | |
63 virtual bool Send(IPC::Message* message); | |
64 // RenderThreadObserver implementation. Protected for testing. | |
65 bool OnControlMessageReceived(const IPC::Message& message) override; | |
66 | |
67 private: | |
68 struct RequestInfo { | |
69 RequestInfo(const WebRTCIdentityMsg_RequestIdentity_Params& params, | |
70 const SuccessCallback& success_callback, | |
71 const FailureCallback& failure_callback); | |
72 RequestInfo(const RequestInfo& other); | |
73 ~RequestInfo(); | |
74 | |
75 WebRTCIdentityMsg_RequestIdentity_Params params; | |
76 SuccessCallback success_callback; | |
77 FailureCallback failure_callback; | |
78 }; | |
79 | |
80 // IPC message handlers. | |
81 void OnIdentityReady(int request_id, | |
82 const std::string& certificate, | |
83 const std::string& private_key); | |
84 void OnRequestFailed(int request_id, int error); | |
85 | |
86 void SendRequest(const RequestInfo& request_info); | |
87 void OnOutstandingRequestReturned(); | |
88 | |
89 std::deque<RequestInfo> pending_requests_; | |
90 int next_request_id_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(WebRTCIdentityService); | |
93 }; | |
94 | |
95 } // namespace content | |
96 | |
97 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_IDENTITY_SERVICE_H_ | |
OLD | NEW |