Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | |
| 6 | |
| 7 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr ivate_api.h" | 5 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr ivate_api.h" |
| 8 | 6 |
| 7 #include "base/hash.h" | |
| 9 #include "base/logging.h" | 8 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_number_conversions.h" | |
|
perkj_chrome
2015/02/19 11:55:53
duplicate include
tommi (sloooow) - chröme
2015/02/19 13:31:40
Done.
| |
| 11 #include "base/supports_user_data.h" | 11 #include "base/supports_user_data.h" |
| 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 13 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
| 14 #include "chrome/browser/media/webrtc_logging_handler_host.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/site_instance.h" | 17 #include "content/public/browser/site_instance.h" |
| 19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 20 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 19 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 21 #include "extensions/browser/process_manager.h" | 20 #include "extensions/browser/process_manager.h" |
| 22 #include "extensions/common/error_utils.h" | 21 #include "extensions/common/error_utils.h" |
| 23 | 22 |
| 24 using content::BrowserThread; | |
| 25 | |
| 26 namespace extensions { | 23 namespace extensions { |
| 27 | 24 |
| 28 namespace SetMetaData = api::webrtc_logging_private::SetMetaData; | |
| 29 namespace Start = api::webrtc_logging_private::Start; | |
| 30 namespace SetUploadOnRenderClose = | |
| 31 api::webrtc_logging_private::SetUploadOnRenderClose; | |
| 32 namespace Stop = api::webrtc_logging_private::Stop; | |
| 33 namespace Upload = api::webrtc_logging_private::Upload; | |
| 34 namespace Discard = api::webrtc_logging_private::Discard; | |
| 35 namespace StartRtpDump = api::webrtc_logging_private::StartRtpDump; | |
| 36 namespace StopRtpDump = api::webrtc_logging_private::StopRtpDump; | |
| 37 | |
| 38 using api::webrtc_logging_private::MetaDataEntry; | 25 using api::webrtc_logging_private::MetaDataEntry; |
| 39 using api::webrtc_logging_private::RequestInfo; | 26 using api::webrtc_logging_private::RequestInfo; |
| 27 using content::BrowserThread; | |
| 28 | |
| 29 namespace Discard = api::webrtc_logging_private::Discard; | |
| 30 namespace SetMetaData = api::webrtc_logging_private::SetMetaData; | |
| 31 namespace SetUploadOnRenderClose = | |
| 32 api::webrtc_logging_private::SetUploadOnRenderClose; | |
| 33 namespace Start = api::webrtc_logging_private::Start; | |
| 34 namespace StartRtpDump = api::webrtc_logging_private::StartRtpDump; | |
| 35 namespace Stop = api::webrtc_logging_private::Stop; | |
| 36 namespace StopRtpDump = api::webrtc_logging_private::StopRtpDump; | |
| 37 namespace Store = api::webrtc_logging_private::Store; | |
| 38 namespace Upload = api::webrtc_logging_private::Upload; | |
| 39 namespace UploadStored = api::webrtc_logging_private::UploadStored; | |
| 40 | |
| 41 namespace { | |
| 42 std::string HashIdWithOrigin(const std::string& security_origin, | |
| 43 const std::string& log_id) { | |
| 44 return base::UintToString(base::Hash(security_origin + log_id)); | |
| 45 } | |
| 46 } // namespace | |
| 40 | 47 |
| 41 content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest( | 48 content::RenderProcessHost* WebrtcLoggingPrivateFunction::RphFromRequest( |
| 42 const RequestInfo& request, const std::string& security_origin) { | 49 const RequestInfo& request, const std::string& security_origin) { |
| 43 // If |guest_process_id| is defined, directly use this id to find the | 50 // If |guest_process_id| is defined, directly use this id to find the |
| 44 // corresponding RenderProcessHost. | 51 // corresponding RenderProcessHost. |
| 45 if (request.guest_process_id.get()) | 52 if (request.guest_process_id.get()) |
| 46 return content::RenderProcessHost::FromID(*request.guest_process_id.get()); | 53 return content::RenderProcessHost::FromID(*request.guest_process_id.get()); |
| 47 | 54 |
| 48 // Otherwise, use the |tab_id|. If there's no |tab_id| and no | 55 // Otherwise, use the |tab_id|. If there's no |tab_id| and no |
| 49 // |guest_process_id|, we can't look up the RenderProcessHost. | 56 // |guest_process_id|, we can't look up the RenderProcessHost. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 67 } | 74 } |
| 68 if (contents->GetURL().GetOrigin().spec() != security_origin) { | 75 if (contents->GetURL().GetOrigin().spec() != security_origin) { |
| 69 error_ = extensions::ErrorUtils::FormatErrorMessage( | 76 error_ = extensions::ErrorUtils::FormatErrorMessage( |
| 70 "Invalid security origin", | 77 "Invalid security origin", |
| 71 base::IntToString(tab_id)); | 78 base::IntToString(tab_id)); |
| 72 return NULL; | 79 return NULL; |
| 73 } | 80 } |
| 74 return contents->GetRenderProcessHost(); | 81 return contents->GetRenderProcessHost(); |
| 75 } | 82 } |
| 76 | 83 |
| 77 WebrtcLoggingPrivateSetMetaDataFunction:: | 84 scoped_refptr<WebRtcLoggingHandlerHost> |
| 78 WebrtcLoggingPrivateSetMetaDataFunction() {} | 85 WebrtcLoggingPrivateFunction::LoggingHandlerFromRequest( |
| 86 const api::webrtc_logging_private::RequestInfo& request, | |
| 87 const std::string& security_origin) { | |
| 88 content::RenderProcessHost* host = RphFromRequest(request, security_origin); | |
| 89 if (!host) | |
| 90 return nullptr; | |
| 79 | 91 |
| 80 WebrtcLoggingPrivateSetMetaDataFunction:: | 92 return base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host); |
| 81 ~WebrtcLoggingPrivateSetMetaDataFunction() {} | |
| 82 | |
| 83 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { | |
| 84 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); | |
| 85 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 86 | |
| 87 content::RenderProcessHost* host = | |
| 88 RphFromRequest(params->request, params->security_origin); | |
| 89 if (!host) | |
| 90 return false; | |
| 91 | |
| 92 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | |
| 93 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | |
| 94 | |
| 95 std::map<std::string, std::string> meta_data; | |
| 96 for (std::vector<linked_ptr<MetaDataEntry> >::const_iterator it = | |
| 97 params->meta_data.begin(); it != params->meta_data.end(); ++it) { | |
| 98 meta_data[(*it)->key] = (*it)->value; | |
| 99 } | |
| 100 | |
| 101 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | |
| 102 &WebrtcLoggingPrivateSetMetaDataFunction::SetMetaDataCallback, this); | |
| 103 | |
| 104 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
| 105 &WebRtcLoggingHandlerHost::SetMetaData, webrtc_logging_handler_host, | |
| 106 meta_data, callback)); | |
| 107 | |
| 108 return true; | |
| 109 } | 93 } |
| 110 | 94 |
| 111 void WebrtcLoggingPrivateSetMetaDataFunction::SetMetaDataCallback( | 95 scoped_refptr<WebRtcLoggingHandlerHost> |
| 96 WebrtcLoggingPrivateFunctionWithGenericCallback::PrepareTask( | |
| 97 const RequestInfo& request, const std::string& security_origin, | |
| 98 WebRtcLoggingHandlerHost::GenericDoneCallback* callback) { | |
| 99 *callback = base::Bind( | |
| 100 &WebrtcLoggingPrivateFunctionWithGenericCallback::FireCallback, this); | |
| 101 return LoggingHandlerFromRequest(request, security_origin); | |
| 102 } | |
| 103 | |
| 104 void WebrtcLoggingPrivateFunctionWithGenericCallback::FireCallback( | |
| 112 bool success, const std::string& error_message) { | 105 bool success, const std::string& error_message) { |
| 113 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 106 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 114 if (!success) | 107 if (!success) |
| 115 SetError(error_message); | 108 SetError(error_message); |
| 116 SendResponse(success); | 109 SendResponse(success); |
| 117 } | 110 } |
| 118 | 111 |
| 119 WebrtcLoggingPrivateStartFunction::WebrtcLoggingPrivateStartFunction() {} | 112 void WebrtcLoggingPrivateFunctionWithUploadCallback::FireCallback( |
| 113 bool success, const std::string& report_id, | |
| 114 const std::string& error_message) { | |
| 115 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 116 if (success) { | |
| 117 api::webrtc_logging_private::UploadResult result; | |
| 118 result.report_id = report_id; | |
| 119 SetResult(result.ToValue().release()); | |
| 120 } else { | |
| 121 SetError(error_message); | |
| 122 } | |
| 123 SendResponse(success); | |
| 124 } | |
| 120 | 125 |
| 121 WebrtcLoggingPrivateStartFunction::~WebrtcLoggingPrivateStartFunction() {} | 126 bool WebrtcLoggingPrivateSetMetaDataFunction::RunAsync() { |
| 127 scoped_ptr<SetMetaData::Params> params(SetMetaData::Params::Create(*args_)); | |
| 128 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 129 | |
| 130 WebRtcLoggingHandlerHost::GenericDoneCallback callback; | |
| 131 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = | |
| 132 PrepareTask(params->request, params->security_origin, &callback); | |
| 133 if (!webrtc_logging_handler_host.get()) | |
| 134 return false; | |
| 135 | |
| 136 scoped_ptr<MetaDataMap> meta_data(new MetaDataMap()); | |
| 137 for (const linked_ptr<MetaDataEntry>& entry : params->meta_data) | |
| 138 (*meta_data.get())[entry->key] = entry->value; | |
| 139 | |
| 140 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
| 141 &WebRtcLoggingHandlerHost::SetMetaData, webrtc_logging_handler_host, | |
| 142 base::Passed(&meta_data), callback)); | |
| 143 | |
| 144 return true; | |
| 145 } | |
| 122 | 146 |
| 123 bool WebrtcLoggingPrivateStartFunction::RunAsync() { | 147 bool WebrtcLoggingPrivateStartFunction::RunAsync() { |
| 124 scoped_ptr<Start::Params> params(Start::Params::Create(*args_)); | 148 scoped_ptr<Start::Params> params(Start::Params::Create(*args_)); |
| 125 EXTENSION_FUNCTION_VALIDATE(params.get()); | 149 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 126 | 150 |
| 127 content::RenderProcessHost* host = | 151 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
| 128 RphFromRequest(params->request, params->security_origin); | 152 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
| 129 if (!host) | 153 PrepareTask(params->request, params->security_origin, &callback); |
| 154 if (!webrtc_logging_handler_host.get()) | |
| 130 return false; | 155 return false; |
| 131 | 156 |
| 132 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | |
| 133 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | |
| 134 | |
| 135 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | |
| 136 &WebrtcLoggingPrivateStartFunction::StartCallback, this); | |
| 137 | |
| 138 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 157 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 139 &WebRtcLoggingHandlerHost::StartLogging, webrtc_logging_handler_host, | 158 &WebRtcLoggingHandlerHost::StartLogging, webrtc_logging_handler_host, |
| 140 callback)); | 159 callback)); |
| 141 | 160 |
| 142 return true; | 161 return true; |
| 143 } | 162 } |
| 144 | 163 |
| 145 void WebrtcLoggingPrivateStartFunction::StartCallback( | |
| 146 bool success, const std::string& error_message) { | |
| 147 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 148 if (!success) | |
| 149 SetError(error_message); | |
| 150 SendResponse(success); | |
| 151 } | |
| 152 | |
| 153 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: | |
| 154 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} | |
| 155 | |
| 156 WebrtcLoggingPrivateSetUploadOnRenderCloseFunction:: | |
| 157 ~WebrtcLoggingPrivateSetUploadOnRenderCloseFunction() {} | |
| 158 | |
| 159 bool WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::RunAsync() { | 164 bool WebrtcLoggingPrivateSetUploadOnRenderCloseFunction::RunAsync() { |
| 160 scoped_ptr<SetUploadOnRenderClose::Params> params( | 165 scoped_ptr<SetUploadOnRenderClose::Params> params( |
| 161 SetUploadOnRenderClose::Params::Create(*args_)); | 166 SetUploadOnRenderClose::Params::Create(*args_)); |
| 162 EXTENSION_FUNCTION_VALIDATE(params.get()); | 167 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 163 | 168 |
| 164 content::RenderProcessHost* host = | 169 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 165 RphFromRequest(params->request, params->security_origin); | 170 LoggingHandlerFromRequest(params->request, params->security_origin)); |
| 166 if (!host) | 171 if (!webrtc_logging_handler_host.get()) |
| 167 return false; | 172 return false; |
| 168 | 173 |
| 169 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | |
| 170 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | |
| 171 | |
| 172 webrtc_logging_handler_host->set_upload_log_on_render_close( | 174 webrtc_logging_handler_host->set_upload_log_on_render_close( |
| 173 params->should_upload); | 175 params->should_upload); |
| 174 | 176 |
| 175 return true; | 177 return true; |
| 176 } | 178 } |
| 177 | 179 |
| 178 WebrtcLoggingPrivateStopFunction::WebrtcLoggingPrivateStopFunction() {} | |
| 179 | |
| 180 WebrtcLoggingPrivateStopFunction::~WebrtcLoggingPrivateStopFunction() {} | |
| 181 | |
| 182 bool WebrtcLoggingPrivateStopFunction::RunAsync() { | 180 bool WebrtcLoggingPrivateStopFunction::RunAsync() { |
| 183 scoped_ptr<Stop::Params> params(Stop::Params::Create(*args_)); | 181 scoped_ptr<Stop::Params> params(Stop::Params::Create(*args_)); |
| 184 EXTENSION_FUNCTION_VALIDATE(params.get()); | 182 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 185 | 183 |
| 186 content::RenderProcessHost* host = | 184 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
| 187 RphFromRequest(params->request, params->security_origin); | 185 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
| 188 if (!host) | 186 PrepareTask(params->request, params->security_origin, &callback); |
| 187 if (!webrtc_logging_handler_host.get()) | |
| 189 return false; | 188 return false; |
| 190 | 189 |
| 191 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | |
| 192 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | |
| 193 | |
| 194 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | |
| 195 &WebrtcLoggingPrivateStopFunction::StopCallback, this); | |
| 196 | |
| 197 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 190 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 198 &WebRtcLoggingHandlerHost::StopLogging, webrtc_logging_handler_host, | 191 &WebRtcLoggingHandlerHost::StopLogging, webrtc_logging_handler_host, |
| 199 callback)); | 192 callback)); |
| 200 | 193 |
| 201 return true; | 194 return true; |
| 202 } | 195 } |
| 203 | 196 |
| 204 void WebrtcLoggingPrivateStopFunction::StopCallback( | 197 bool WebrtcLoggingPrivateStoreFunction::RunAsync() { |
| 205 bool success, const std::string& error_message) { | 198 scoped_ptr<Store::Params> params(Store::Params::Create(*args_)); |
| 206 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 199 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 207 if (!success) | 200 |
| 208 SetError(error_message); | 201 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
| 209 SendResponse(success); | 202 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
| 203 PrepareTask(params->request, params->security_origin, &callback); | |
| 204 if (!webrtc_logging_handler_host.get()) | |
| 205 return false; | |
| 206 | |
| 207 const std::string local_log_id(HashIdWithOrigin(params->security_origin, | |
| 208 params->log_id)); | |
| 209 | |
| 210 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
| 211 &WebRtcLoggingHandlerHost::StoreLog, | |
| 212 webrtc_logging_handler_host, local_log_id, callback)); | |
| 213 | |
| 214 return true; | |
| 210 } | 215 } |
| 211 | 216 |
| 212 WebrtcLoggingPrivateUploadFunction::WebrtcLoggingPrivateUploadFunction() {} | 217 bool WebrtcLoggingPrivateUploadStoredFunction::RunAsync() { |
| 218 scoped_ptr<UploadStored::Params> params(UploadStored::Params::Create(*args_)); | |
| 219 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 213 | 220 |
| 214 WebrtcLoggingPrivateUploadFunction::~WebrtcLoggingPrivateUploadFunction() {} | 221 scoped_refptr<WebRtcLoggingHandlerHost> logging_handler( |
| 222 LoggingHandlerFromRequest(params->request, params->security_origin)); | |
| 223 if (!logging_handler.get()) | |
| 224 return false; | |
| 225 | |
| 226 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( | |
| 227 &WebrtcLoggingPrivateUploadStoredFunction::FireCallback, this); | |
| 228 | |
| 229 const std::string local_log_id(HashIdWithOrigin(params->security_origin, | |
| 230 params->log_id)); | |
| 231 | |
| 232 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
| 233 &WebRtcLoggingHandlerHost::UploadStoredLog, logging_handler, local_log_id, | |
| 234 callback)); | |
| 235 | |
| 236 return true; | |
| 237 } | |
| 215 | 238 |
| 216 bool WebrtcLoggingPrivateUploadFunction::RunAsync() { | 239 bool WebrtcLoggingPrivateUploadFunction::RunAsync() { |
| 217 scoped_ptr<Upload::Params> params(Upload::Params::Create(*args_)); | 240 scoped_ptr<Upload::Params> params(Upload::Params::Create(*args_)); |
| 218 EXTENSION_FUNCTION_VALIDATE(params.get()); | 241 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 219 | 242 |
| 220 content::RenderProcessHost* host = | 243 scoped_refptr<WebRtcLoggingHandlerHost> logging_handler( |
| 221 RphFromRequest(params->request, params->security_origin); | 244 LoggingHandlerFromRequest(params->request, params->security_origin)); |
| 222 if (!host) | 245 if (!logging_handler.get()) |
| 223 return false; | 246 return false; |
| 224 | 247 |
| 225 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | |
| 226 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | |
| 227 | |
| 228 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( | 248 WebRtcLoggingHandlerHost::UploadDoneCallback callback = base::Bind( |
| 229 &WebrtcLoggingPrivateUploadFunction::UploadCallback, this); | 249 &WebrtcLoggingPrivateUploadFunction::FireCallback, this); |
| 230 | 250 |
| 231 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 251 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 232 &WebRtcLoggingHandlerHost::UploadLog, webrtc_logging_handler_host, | 252 &WebRtcLoggingHandlerHost::UploadLog, logging_handler, callback)); |
| 233 callback)); | |
| 234 | 253 |
| 235 return true; | 254 return true; |
| 236 } | 255 } |
| 237 | 256 |
| 238 void WebrtcLoggingPrivateUploadFunction::UploadCallback( | |
| 239 bool success, const std::string& report_id, | |
| 240 const std::string& error_message) { | |
| 241 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 242 if (success) { | |
| 243 api::webrtc_logging_private::UploadResult result; | |
| 244 result.report_id = report_id; | |
| 245 SetResult(result.ToValue().release()); | |
| 246 } else { | |
| 247 SetError(error_message); | |
| 248 } | |
| 249 SendResponse(success); | |
| 250 } | |
| 251 | |
| 252 WebrtcLoggingPrivateDiscardFunction::WebrtcLoggingPrivateDiscardFunction() {} | |
| 253 | |
| 254 WebrtcLoggingPrivateDiscardFunction::~WebrtcLoggingPrivateDiscardFunction() {} | |
| 255 | |
| 256 bool WebrtcLoggingPrivateDiscardFunction::RunAsync() { | 257 bool WebrtcLoggingPrivateDiscardFunction::RunAsync() { |
| 257 scoped_ptr<Discard::Params> params(Discard::Params::Create(*args_)); | 258 scoped_ptr<Discard::Params> params(Discard::Params::Create(*args_)); |
| 258 EXTENSION_FUNCTION_VALIDATE(params.get()); | 259 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 259 | 260 |
| 260 content::RenderProcessHost* host = | 261 WebRtcLoggingHandlerHost::GenericDoneCallback callback; |
| 261 RphFromRequest(params->request, params->security_origin); | 262 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host = |
| 262 if (!host) | 263 PrepareTask(params->request, params->security_origin, &callback); |
| 264 if (!webrtc_logging_handler_host.get()) | |
| 263 return false; | 265 return false; |
| 264 | 266 |
| 265 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | |
| 266 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | |
| 267 | |
| 268 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | |
| 269 &WebrtcLoggingPrivateDiscardFunction::DiscardCallback, this); | |
| 270 | |
| 271 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 267 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
| 272 &WebRtcLoggingHandlerHost::DiscardLog, webrtc_logging_handler_host, | 268 &WebRtcLoggingHandlerHost::DiscardLog, webrtc_logging_handler_host, |
| 273 callback)); | 269 callback)); |
| 274 | 270 |
| 275 return true; | 271 return true; |
| 276 } | 272 } |
| 277 | 273 |
| 278 void WebrtcLoggingPrivateDiscardFunction::DiscardCallback( | |
| 279 bool success, const std::string& error_message) { | |
| 280 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 281 if (!success) | |
| 282 SetError(error_message); | |
| 283 SendResponse(success); | |
| 284 } | |
| 285 | |
| 286 WebrtcLoggingPrivateStartRtpDumpFunction:: | |
| 287 WebrtcLoggingPrivateStartRtpDumpFunction() {} | |
| 288 | |
| 289 WebrtcLoggingPrivateStartRtpDumpFunction:: | |
| 290 ~WebrtcLoggingPrivateStartRtpDumpFunction() {} | |
| 291 | |
| 292 bool WebrtcLoggingPrivateStartRtpDumpFunction::RunAsync() { | 274 bool WebrtcLoggingPrivateStartRtpDumpFunction::RunAsync() { |
| 293 scoped_ptr<StartRtpDump::Params> params(StartRtpDump::Params::Create(*args_)); | 275 scoped_ptr<StartRtpDump::Params> params(StartRtpDump::Params::Create(*args_)); |
| 294 EXTENSION_FUNCTION_VALIDATE(params.get()); | 276 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 295 | 277 |
| 296 if (!params->incoming && !params->outgoing) { | 278 if (!params->incoming && !params->outgoing) { |
| 297 StartRtpDumpCallback(false, "Either incoming or outgoing must be true."); | 279 FireCallback(false, "Either incoming or outgoing must be true."); |
| 298 return true; | 280 return true; |
| 299 } | 281 } |
| 300 | 282 |
| 301 RtpDumpType type = | 283 RtpDumpType type = |
| 302 (params->incoming && params->outgoing) | 284 (params->incoming && params->outgoing) |
| 303 ? RTP_DUMP_BOTH | 285 ? RTP_DUMP_BOTH |
| 304 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); | 286 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); |
| 305 | 287 |
| 306 content::RenderProcessHost* host = | 288 content::RenderProcessHost* host = |
| 307 RphFromRequest(params->request, params->security_origin); | 289 RphFromRequest(params->request, params->security_origin); |
| 308 if (!host) | 290 if (!host) |
| 309 return false; | 291 return false; |
| 310 | 292 |
| 311 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 293 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 312 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 294 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 313 | 295 |
| 314 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | 296 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 315 &WebrtcLoggingPrivateStartRtpDumpFunction::StartRtpDumpCallback, this); | 297 &WebrtcLoggingPrivateStartRtpDumpFunction::FireCallback, this); |
| 316 | 298 |
| 317 // This call cannot fail. | 299 // This call cannot fail. |
| 318 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback = | 300 content::RenderProcessHost::WebRtcStopRtpDumpCallback stop_callback = |
| 319 host->StartRtpDump(params->incoming, | 301 host->StartRtpDump(params->incoming, |
| 320 params->outgoing, | 302 params->outgoing, |
| 321 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket, | 303 base::Bind(&WebRtcLoggingHandlerHost::OnRtpPacket, |
| 322 webrtc_logging_handler_host)); | 304 webrtc_logging_handler_host)); |
| 323 | 305 |
| 324 BrowserThread::PostTask(BrowserThread::IO, | 306 BrowserThread::PostTask(BrowserThread::IO, |
| 325 FROM_HERE, | 307 FROM_HERE, |
| 326 base::Bind(&WebRtcLoggingHandlerHost::StartRtpDump, | 308 base::Bind(&WebRtcLoggingHandlerHost::StartRtpDump, |
| 327 webrtc_logging_handler_host, | 309 webrtc_logging_handler_host, |
| 328 type, | 310 type, |
| 329 callback, | 311 callback, |
| 330 stop_callback)); | 312 stop_callback)); |
| 331 return true; | 313 return true; |
| 332 } | 314 } |
| 333 | 315 |
| 334 void WebrtcLoggingPrivateStartRtpDumpFunction::StartRtpDumpCallback( | |
| 335 bool success, | |
| 336 const std::string& error_message) { | |
| 337 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 338 if (!success) | |
| 339 SetError(error_message); | |
| 340 SendResponse(success); | |
| 341 } | |
| 342 | |
| 343 WebrtcLoggingPrivateStopRtpDumpFunction:: | |
| 344 WebrtcLoggingPrivateStopRtpDumpFunction() {} | |
| 345 | |
| 346 WebrtcLoggingPrivateStopRtpDumpFunction:: | |
| 347 ~WebrtcLoggingPrivateStopRtpDumpFunction() {} | |
| 348 | |
| 349 bool WebrtcLoggingPrivateStopRtpDumpFunction::RunAsync() { | 316 bool WebrtcLoggingPrivateStopRtpDumpFunction::RunAsync() { |
| 350 scoped_ptr<StopRtpDump::Params> params(StopRtpDump::Params::Create(*args_)); | 317 scoped_ptr<StopRtpDump::Params> params(StopRtpDump::Params::Create(*args_)); |
| 351 EXTENSION_FUNCTION_VALIDATE(params.get()); | 318 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 352 | 319 |
| 353 if (!params->incoming && !params->outgoing) { | 320 if (!params->incoming && !params->outgoing) { |
| 354 StopRtpDumpCallback(false, "Either incoming or outgoing must be true."); | 321 FireCallback(false, "Either incoming or outgoing must be true."); |
| 355 return true; | 322 return true; |
| 356 } | 323 } |
| 357 | 324 |
| 358 RtpDumpType type = | 325 RtpDumpType type = |
| 359 (params->incoming && params->outgoing) | 326 (params->incoming && params->outgoing) |
| 360 ? RTP_DUMP_BOTH | 327 ? RTP_DUMP_BOTH |
| 361 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); | 328 : (params->incoming ? RTP_DUMP_INCOMING : RTP_DUMP_OUTGOING); |
| 362 | 329 |
| 363 content::RenderProcessHost* host = | 330 content::RenderProcessHost* host = |
| 364 RphFromRequest(params->request, params->security_origin); | 331 RphFromRequest(params->request, params->security_origin); |
| 365 if (!host) | 332 if (!host) |
| 366 return false; | 333 return false; |
| 367 | 334 |
| 368 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( | 335 scoped_refptr<WebRtcLoggingHandlerHost> webrtc_logging_handler_host( |
| 369 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); | 336 base::UserDataAdapter<WebRtcLoggingHandlerHost>::Get(host, host)); |
| 370 | 337 |
| 371 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( | 338 WebRtcLoggingHandlerHost::GenericDoneCallback callback = base::Bind( |
| 372 &WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback, this); | 339 &WebrtcLoggingPrivateStopRtpDumpFunction::FireCallback, this); |
| 373 | 340 |
| 374 BrowserThread::PostTask(BrowserThread::IO, | 341 BrowserThread::PostTask(BrowserThread::IO, |
| 375 FROM_HERE, | 342 FROM_HERE, |
| 376 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, | 343 base::Bind(&WebRtcLoggingHandlerHost::StopRtpDump, |
| 377 webrtc_logging_handler_host, | 344 webrtc_logging_handler_host, |
| 378 type, | 345 type, |
| 379 callback)); | 346 callback)); |
| 380 return true; | 347 return true; |
| 381 } | 348 } |
| 382 | 349 |
| 383 void WebrtcLoggingPrivateStopRtpDumpFunction::StopRtpDumpCallback( | |
| 384 bool success, | |
| 385 const std::string& error_message) { | |
| 386 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 387 if (!success) | |
| 388 SetError(error_message); | |
| 389 SendResponse(success); | |
| 390 } | |
| 391 | |
| 392 } // namespace extensions | 350 } // namespace extensions |
| OLD | NEW |