OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/tracing/tracing_ui.h" | 5 #include "content/browser/tracing/tracing_ui.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 240 } |
241 | 241 |
242 TracingUI::~TracingUI() { | 242 TracingUI::~TracingUI() { |
243 TracingControllerImpl::GetInstance()->UnregisterTracingUI(this); | 243 TracingControllerImpl::GetInstance()->UnregisterTracingUI(this); |
244 } | 244 } |
245 | 245 |
246 void TracingUI::DoUploadBase64Encoded(const base::ListValue* args) { | 246 void TracingUI::DoUploadBase64Encoded(const base::ListValue* args) { |
247 std::string file_contents_base64; | 247 std::string file_contents_base64; |
248 if (!args || args->empty() || !args->GetString(0, &file_contents_base64)) { | 248 if (!args || args->empty() || !args->GetString(0, &file_contents_base64)) { |
249 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", | 249 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", |
250 base::StringValue("Missing data")); | 250 base::Value("Missing data")); |
251 return; | 251 return; |
252 } | 252 } |
253 | 253 |
254 std::string file_contents; | 254 std::string file_contents; |
255 base::Base64Decode(file_contents_base64, &file_contents); | 255 base::Base64Decode(file_contents_base64, &file_contents); |
256 | 256 |
257 // doUploadBase64 is used to upload binary data which is assumed to already | 257 // doUploadBase64 is used to upload binary data which is assumed to already |
258 // be compressed. | 258 // be compressed. |
259 DoUploadInternal(file_contents, TraceUploader::UNCOMPRESSED_UPLOAD); | 259 DoUploadInternal(file_contents, TraceUploader::UNCOMPRESSED_UPLOAD); |
260 } | 260 } |
261 | 261 |
262 void TracingUI::DoUpload(const base::ListValue* args) { | 262 void TracingUI::DoUpload(const base::ListValue* args) { |
263 std::string file_contents; | 263 std::string file_contents; |
264 if (!args || args->empty() || !args->GetString(0, &file_contents)) { | 264 if (!args || args->empty() || !args->GetString(0, &file_contents)) { |
265 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", | 265 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", |
266 base::StringValue("Missing data")); | 266 base::Value("Missing data")); |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 DoUploadInternal(file_contents, TraceUploader::COMPRESSED_UPLOAD); | 270 DoUploadInternal(file_contents, TraceUploader::COMPRESSED_UPLOAD); |
271 } | 271 } |
272 | 272 |
273 void TracingUI::DoUploadInternal(const std::string& file_contents, | 273 void TracingUI::DoUploadInternal(const std::string& file_contents, |
274 TraceUploader::UploadMode upload_mode) { | 274 TraceUploader::UploadMode upload_mode) { |
275 if (!delegate_) { | 275 if (!delegate_) { |
276 web_ui()->CallJavascriptFunctionUnsafe( | 276 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", |
277 "onUploadError", base::StringValue("Not implemented")); | 277 base::Value("Not implemented")); |
278 return; | 278 return; |
279 } | 279 } |
280 | 280 |
281 if (trace_uploader_) { | 281 if (trace_uploader_) { |
282 web_ui()->CallJavascriptFunctionUnsafe( | 282 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", |
283 "onUploadError", base::StringValue("Upload in progress")); | 283 base::Value("Upload in progress")); |
284 return; | 284 return; |
285 } | 285 } |
286 | 286 |
287 TraceUploader::UploadProgressCallback progress_callback = | 287 TraceUploader::UploadProgressCallback progress_callback = |
288 base::Bind(&TracingUI::OnTraceUploadProgress, | 288 base::Bind(&TracingUI::OnTraceUploadProgress, |
289 weak_factory_.GetWeakPtr()); | 289 weak_factory_.GetWeakPtr()); |
290 TraceUploader::UploadDoneCallback done_callback = | 290 TraceUploader::UploadDoneCallback done_callback = |
291 base::Bind(&TracingUI::OnTraceUploadComplete, | 291 base::Bind(&TracingUI::OnTraceUploadComplete, |
292 weak_factory_.GetWeakPtr()); | 292 weak_factory_.GetWeakPtr()); |
293 | 293 |
294 trace_uploader_ = delegate_->GetTraceUploader( | 294 trace_uploader_ = delegate_->GetTraceUploader( |
295 BrowserContext::GetDefaultStoragePartition( | 295 BrowserContext::GetDefaultStoragePartition( |
296 web_ui()->GetWebContents()->GetBrowserContext())-> | 296 web_ui()->GetWebContents()->GetBrowserContext())-> |
297 GetURLRequestContext()); | 297 GetURLRequestContext()); |
298 DCHECK(trace_uploader_); | 298 DCHECK(trace_uploader_); |
299 trace_uploader_->DoUpload(file_contents, upload_mode, nullptr, | 299 trace_uploader_->DoUpload(file_contents, upload_mode, nullptr, |
300 progress_callback, done_callback); | 300 progress_callback, done_callback); |
301 // TODO(mmandlis): Add support for stopping the upload in progress. | 301 // TODO(mmandlis): Add support for stopping the upload in progress. |
302 } | 302 } |
303 | 303 |
304 void TracingUI::OnTraceUploadProgress(int64_t current, int64_t total) { | 304 void TracingUI::OnTraceUploadProgress(int64_t current, int64_t total) { |
305 DCHECK(current <= total); | 305 DCHECK(current <= total); |
306 int percent = (current / total) * 100; | 306 int percent = (current / total) * 100; |
307 web_ui()->CallJavascriptFunctionUnsafe( | 307 web_ui()->CallJavascriptFunctionUnsafe( |
308 "onUploadProgress", base::Value(percent), | 308 "onUploadProgress", base::Value(percent), |
309 base::StringValue(base::StringPrintf("%" PRId64, current)), | 309 base::Value(base::StringPrintf("%" PRId64, current)), |
310 base::StringValue(base::StringPrintf("%" PRId64, total))); | 310 base::Value(base::StringPrintf("%" PRId64, total))); |
311 } | 311 } |
312 | 312 |
313 void TracingUI::OnTraceUploadComplete(bool success, | 313 void TracingUI::OnTraceUploadComplete(bool success, |
314 const std::string& feedback) { | 314 const std::string& feedback) { |
315 if (success) { | 315 if (success) { |
316 web_ui()->CallJavascriptFunctionUnsafe("onUploadComplete", | 316 web_ui()->CallJavascriptFunctionUnsafe("onUploadComplete", |
317 base::StringValue(feedback)); | 317 base::Value(feedback)); |
318 } else { | 318 } else { |
319 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", | 319 web_ui()->CallJavascriptFunctionUnsafe("onUploadError", |
320 base::StringValue(feedback)); | 320 base::Value(feedback)); |
321 } | 321 } |
322 trace_uploader_.reset(); | 322 trace_uploader_.reset(); |
323 } | 323 } |
324 | 324 |
325 } // namespace content | 325 } // namespace content |
OLD | NEW |