Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / renderer / media / webrtc_identity_service.h
blob33bbfb264bf153df605fc4960243c83a3a6d454f
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_
8 #include <deque>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "content/common/content_export.h"
14 #include "content/common/media/webrtc_identity_messages.h"
15 #include "content/public/renderer/render_process_observer.h"
16 #include "url/gurl.h"
18 namespace content {
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 RenderProcessObserver {
24 public:
25 typedef base::Callback<
26 void(const std::string& certificate, const std::string& private_key)>
27 SuccessCallback;
29 typedef base::Callback<void(int error)> FailureCallback;
31 WebRTCIdentityService();
32 ~WebRTCIdentityService() override;
34 // Sends an identity request.
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.
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);
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.
58 // |request_id| is the request id returned from RequestIdentity.
59 void CancelRequest(int request_id);
61 protected:
62 // For unittest to override.
63 virtual bool Send(IPC::Message* message);
64 // RenderProcessObserver implementation. Protected for testing.
65 bool OnControlMessageReceived(const IPC::Message& message) override;
67 private:
68 struct RequestInfo {
69 RequestInfo(const WebRTCIdentityMsg_RequestIdentity_Params& params,
70 const SuccessCallback& success_callback,
71 const FailureCallback& failure_callback);
72 ~RequestInfo();
74 WebRTCIdentityMsg_RequestIdentity_Params params;
75 SuccessCallback success_callback;
76 FailureCallback failure_callback;
79 // IPC message handlers.
80 void OnIdentityReady(int request_id,
81 const std::string& certificate,
82 const std::string& private_key);
83 void OnRequestFailed(int request_id, int error);
85 void SendRequest(const RequestInfo& request_info);
86 void OnOutstandingRequestReturned();
88 std::deque<RequestInfo> pending_requests_;
89 int next_request_id_;
91 DISALLOW_COPY_AND_ASSIGN(WebRTCIdentityService);
94 } // namespace content
96 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_IDENTITY_SERVICE_H_