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 CHROME_BROWSER_EXTENSIONS_API_WEBRTC_LOGGING_PRIVATE_WEBRTC_LOGGING_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBRTC_LOGGING_PRIVATE_WEBRTC_LOGGING_PRIVATE_API_H_
8 #include "chrome/browser/extensions/chrome_extension_function.h"
9 #if defined(ENABLE_WEBRTC)
10 #include "chrome/browser/media/webrtc_logging_handler_host.h"
12 #include "chrome/common/extensions/api/webrtc_logging_private.h"
16 class RenderProcessHost
;
20 namespace extensions
{
22 class WebrtcLoggingPrivateFunction
: public ChromeAsyncExtensionFunction
{
24 ~WebrtcLoggingPrivateFunction() override
{}
26 #if defined(ENABLE_WEBRTC)
27 // Returns the RenderProcessHost associated with the given |request|
28 // authorized by the |security_origin|. Returns null if unauthorized or
29 // the RPH does not exist.
30 content::RenderProcessHost
* RphFromRequest(
31 const api::webrtc_logging_private::RequestInfo
& request
,
32 const std::string
& security_origin
);
34 scoped_refptr
<WebRtcLoggingHandlerHost
> LoggingHandlerFromRequest(
35 const api::webrtc_logging_private::RequestInfo
& request
,
36 const std::string
& security_origin
);
40 class WebrtcLoggingPrivateFunctionWithGenericCallback
41 : public WebrtcLoggingPrivateFunction
{
43 ~WebrtcLoggingPrivateFunctionWithGenericCallback() override
{}
45 #if defined(ENABLE_WEBRTC)
46 // Finds the appropriate logging handler for performing the task and prepares
47 // a generic callback object for when the task is completed.
48 // If the logging handler can't be found for the given request+origin, the
49 // returned ptr will be null.
50 scoped_refptr
<WebRtcLoggingHandlerHost
> PrepareTask(
51 const api::webrtc_logging_private::RequestInfo
& request
,
52 const std::string
& security_origin
,
53 WebRtcLoggingHandlerHost::GenericDoneCallback
* callback
);
55 // Must be called on UI thread.
56 void FireCallback(bool success
, const std::string
& error_message
);
60 class WebrtcLoggingPrivateFunctionWithUploadCallback
61 : public WebrtcLoggingPrivateFunction
{
63 ~WebrtcLoggingPrivateFunctionWithUploadCallback() override
{}
65 #if defined(ENABLE_WEBRTC)
66 // Must be called on UI thread.
67 void FireCallback(bool success
, const std::string
& report_id
,
68 const std::string
& error_message
);
72 class WebrtcLoggingPrivateSetMetaDataFunction
73 : public WebrtcLoggingPrivateFunctionWithGenericCallback
{
75 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.setMetaData",
76 WEBRTCLOGGINGPRIVATE_SETMETADATA
)
77 WebrtcLoggingPrivateSetMetaDataFunction() {}
80 ~WebrtcLoggingPrivateSetMetaDataFunction() override
{}
82 // ExtensionFunction overrides.
83 bool RunAsync() override
;
86 class WebrtcLoggingPrivateStartFunction
87 : public WebrtcLoggingPrivateFunctionWithGenericCallback
{
89 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.start",
90 WEBRTCLOGGINGPRIVATE_START
)
91 WebrtcLoggingPrivateStartFunction() {}
94 ~WebrtcLoggingPrivateStartFunction() override
{}
96 // ExtensionFunction overrides.
97 bool RunAsync() override
;
100 class WebrtcLoggingPrivateSetUploadOnRenderCloseFunction
101 : public WebrtcLoggingPrivateFunction
{
103 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.setUploadOnRenderClose",
104 WEBRTCLOGGINGPRIVATE_SETUPLOADONRENDERCLOSE
)
105 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {}
108 ~WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() override
{}
110 // ExtensionFunction overrides.
111 bool RunAsync() override
;
114 class WebrtcLoggingPrivateStopFunction
115 : public WebrtcLoggingPrivateFunctionWithGenericCallback
{
117 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.stop",
118 WEBRTCLOGGINGPRIVATE_STOP
)
119 WebrtcLoggingPrivateStopFunction() {}
122 ~WebrtcLoggingPrivateStopFunction() override
{}
124 // ExtensionFunction overrides.
125 bool RunAsync() override
;
128 class WebrtcLoggingPrivateStoreFunction
129 : public WebrtcLoggingPrivateFunctionWithGenericCallback
{
131 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.store",
132 WEBRTCLOGGINGPRIVATE_STORE
)
133 WebrtcLoggingPrivateStoreFunction() {}
136 ~WebrtcLoggingPrivateStoreFunction() override
{}
138 // ExtensionFunction overrides.
139 bool RunAsync() override
;
142 class WebrtcLoggingPrivateUploadStoredFunction
143 : public WebrtcLoggingPrivateFunctionWithUploadCallback
{
145 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.uploadStored",
146 WEBRTCLOGGINGPRIVATE_UPLOADSTORED
)
147 WebrtcLoggingPrivateUploadStoredFunction() {}
150 ~WebrtcLoggingPrivateUploadStoredFunction() override
{}
152 // ExtensionFunction overrides.
153 bool RunAsync() override
;
156 class WebrtcLoggingPrivateUploadFunction
157 : public WebrtcLoggingPrivateFunctionWithUploadCallback
{
159 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.upload",
160 WEBRTCLOGGINGPRIVATE_UPLOAD
)
161 WebrtcLoggingPrivateUploadFunction() {}
164 ~WebrtcLoggingPrivateUploadFunction() override
{}
166 // ExtensionFunction overrides.
167 bool RunAsync() override
;
170 class WebrtcLoggingPrivateDiscardFunction
171 : public WebrtcLoggingPrivateFunctionWithGenericCallback
{
173 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.discard",
174 WEBRTCLOGGINGPRIVATE_DISCARD
)
175 WebrtcLoggingPrivateDiscardFunction() {}
178 ~WebrtcLoggingPrivateDiscardFunction() override
{}
180 // ExtensionFunction overrides.
181 bool RunAsync() override
;
184 class WebrtcLoggingPrivateStartRtpDumpFunction
185 : public WebrtcLoggingPrivateFunctionWithGenericCallback
{
187 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.startRtpDump",
188 WEBRTCLOGGINGPRIVATE_STARTRTPDUMP
)
189 WebrtcLoggingPrivateStartRtpDumpFunction() {}
192 ~WebrtcLoggingPrivateStartRtpDumpFunction() override
{}
194 // ExtensionFunction overrides.
195 bool RunAsync() override
;
198 class WebrtcLoggingPrivateStopRtpDumpFunction
199 : public WebrtcLoggingPrivateFunctionWithGenericCallback
{
201 DECLARE_EXTENSION_FUNCTION("webrtcLoggingPrivate.stopRtpDump",
202 WEBRTCLOGGINGPRIVATE_STOPRTPDUMP
)
203 WebrtcLoggingPrivateStopRtpDumpFunction() {}
206 ~WebrtcLoggingPrivateStopRtpDumpFunction() override
{}
208 // ExtensionFunction overrides.
209 bool RunAsync() override
;
212 } // namespace extensions
214 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBRTC_LOGGING_PRIVATE_WEBRTC_LOGGING_PRIVATE_API_H_