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.
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_IDENTITY_SERVICE_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_IDENTITY_SERVICE_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "content/common/content_export.h"
14 #include "content/public/renderer/render_process_observer.h"
19 // This class handles WebRTC DTLS identity requests by sending IPC messages to
20 // the browser process. Only one request is sent to the browser at a time; other
21 // requests are queued and have to wait for the outstanding request to complete.
22 class CONTENT_EXPORT WebRTCIdentityService
: public RenderProcessObserver
{
24 typedef base::Callback
<
25 void(const std::string
& certificate
, const std::string
& private_key
)>
28 typedef base::Callback
<void(int error
)> FailureCallback
;
30 WebRTCIdentityService();
31 ~WebRTCIdentityService() override
;
33 // Sends an identity request.
35 // |origin| is the origin of the caller;
36 // |identity_name| and |common_name| have the same meaning as in
37 // webrtc::DTLSIdentityServiceInterface::RequestIdentity;
38 // |success_callback| is the callback if the identity is successfully
40 // |failure_callback| is the callback if the identity request fails.
42 // The request id is returned. It's unique within the renderer and can be used
43 // to cancel the request.
44 int RequestIdentity(const GURL
& origin
,
45 const std::string
& identity_name
,
46 const std::string
& common_name
,
47 const SuccessCallback
& success_callback
,
48 const FailureCallback
& failure_callback
);
50 // Cancels a previous request and the callbacks will not be called.
51 // If the |request_id| is not associated with the
52 // outstanding request or any queued request, this method does nothing.
54 // |request_id| is the request id returned from RequestIdentity.
55 void CancelRequest(int request_id
);
58 // For unittest to override.
59 virtual bool Send(IPC::Message
* message
);
60 // RenderProcessObserver implementation. Protected for testing.
61 bool OnControlMessageReceived(const IPC::Message
& message
) override
;
65 RequestInfo(int request_id
,
67 const std::string
& identity_name
,
68 const std::string
& common_name
,
69 const SuccessCallback
& success_callback
,
70 const FailureCallback
& failure_callback
);
75 std::string identity_name
;
76 std::string common_name
;
77 SuccessCallback success_callback
;
78 FailureCallback failure_callback
;
81 // IPC message handlers.
82 void OnIdentityReady(int request_id
,
83 const std::string
& certificate
,
84 const std::string
& private_key
);
85 void OnRequestFailed(int request_id
, int error
);
87 void SendRequest(const RequestInfo
& request_info
);
88 void OnOutstandingRequestReturned();
90 std::deque
<RequestInfo
> pending_requests_
;
93 DISALLOW_COPY_AND_ASSIGN(WebRTCIdentityService
);
96 } // namespace content
98 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_IDENTITY_SERVICE_H_