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