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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 std::string file_contents_base64; | 309 std::string file_contents_base64; |
310 if (!args || args->empty() || !args->GetString(0, &file_contents_base64)) { | 310 if (!args || args->empty() || !args->GetString(0, &file_contents_base64)) { |
311 web_ui()->CallJavascriptFunction("onUploadError", | 311 web_ui()->CallJavascriptFunction("onUploadError", |
312 base::StringValue("Missing data")); | 312 base::StringValue("Missing data")); |
313 return; | 313 return; |
314 } | 314 } |
315 | 315 |
316 std::string file_contents; | 316 std::string file_contents; |
317 base::Base64Decode(file_contents_base64, &file_contents); | 317 base::Base64Decode(file_contents_base64, &file_contents); |
318 | 318 |
319 DoUploadInternal(file_contents); | 319 DoUploadInternal(file_contents, false); |
dsinclair
2015/07/07 18:36:37
Can these pass the enum as well?
shatch
2015/07/07 19:26:00
Done.
| |
320 } | 320 } |
321 | 321 |
322 void TracingUI::DoUpload(const base::ListValue* args) { | 322 void TracingUI::DoUpload(const base::ListValue* args) { |
323 std::string file_contents; | 323 std::string file_contents; |
324 if (!args || args->empty() || !args->GetString(0, &file_contents)) { | 324 if (!args || args->empty() || !args->GetString(0, &file_contents)) { |
325 web_ui()->CallJavascriptFunction("onUploadError", | 325 web_ui()->CallJavascriptFunction("onUploadError", |
326 base::StringValue("Missing data")); | 326 base::StringValue("Missing data")); |
327 return; | 327 return; |
328 } | 328 } |
329 | 329 |
330 DoUploadInternal(file_contents); | 330 DoUploadInternal(file_contents, true); |
331 } | 331 } |
332 | 332 |
333 void TracingUI::DoUploadInternal(const std::string& file_contents) { | 333 void TracingUI::DoUploadInternal(const std::string& file_contents, |
334 bool compress_on_upload) { | |
334 if (!delegate_) { | 335 if (!delegate_) { |
335 web_ui()->CallJavascriptFunction("onUploadError", | 336 web_ui()->CallJavascriptFunction("onUploadError", |
336 base::StringValue("Not implemented")); | 337 base::StringValue("Not implemented")); |
337 return; | 338 return; |
338 } | 339 } |
339 | 340 |
340 if (trace_uploader_) { | 341 if (trace_uploader_) { |
341 web_ui()->CallJavascriptFunction("onUploadError", | 342 web_ui()->CallJavascriptFunction("onUploadError", |
342 base::StringValue("Upload in progress")); | 343 base::StringValue("Upload in progress")); |
343 return; | 344 return; |
344 } | 345 } |
345 | 346 |
346 TraceUploader::UploadProgressCallback progress_callback = | 347 TraceUploader::UploadProgressCallback progress_callback = |
347 base::Bind(&TracingUI::OnTraceUploadProgress, | 348 base::Bind(&TracingUI::OnTraceUploadProgress, |
348 weak_factory_.GetWeakPtr()); | 349 weak_factory_.GetWeakPtr()); |
349 TraceUploader::UploadDoneCallback done_callback = | 350 TraceUploader::UploadDoneCallback done_callback = |
350 base::Bind(&TracingUI::OnTraceUploadComplete, | 351 base::Bind(&TracingUI::OnTraceUploadComplete, |
351 weak_factory_.GetWeakPtr()); | 352 weak_factory_.GetWeakPtr()); |
352 | 353 |
353 trace_uploader_ = delegate_->GetTraceUploader( | 354 trace_uploader_ = delegate_->GetTraceUploader( |
354 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext()); | 355 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext()); |
355 DCHECK(trace_uploader_); | 356 DCHECK(trace_uploader_); |
356 trace_uploader_->DoUpload(file_contents, nullptr, progress_callback, | 357 TraceUploader::UploadMode upload_mode = |
357 done_callback); | 358 compress_on_upload ? TraceUploader::COMPRESSED_UPLOAD |
359 : content::TraceUploader::UNCOMPRESSED_UPLOAD; | |
360 trace_uploader_->DoUpload(file_contents, upload_mode, nullptr, | |
361 progress_callback, done_callback); | |
358 // TODO(mmandlis): Add support for stopping the upload in progress. | 362 // TODO(mmandlis): Add support for stopping the upload in progress. |
359 } | 363 } |
360 | 364 |
361 void TracingUI::OnTraceUploadProgress(int64 current, int64 total) { | 365 void TracingUI::OnTraceUploadProgress(int64 current, int64 total) { |
362 DCHECK(current <= total); | 366 DCHECK(current <= total); |
363 int percent = (current / total) * 100; | 367 int percent = (current / total) * 100; |
364 web_ui()->CallJavascriptFunction( | 368 web_ui()->CallJavascriptFunction( |
365 "onUploadProgress", | 369 "onUploadProgress", |
366 base::FundamentalValue(percent), | 370 base::FundamentalValue(percent), |
367 base::StringValue(base::StringPrintf("%" PRId64, current)), | 371 base::StringValue(base::StringPrintf("%" PRId64, current)), |
368 base::StringValue(base::StringPrintf("%" PRId64, total))); | 372 base::StringValue(base::StringPrintf("%" PRId64, total))); |
369 } | 373 } |
370 | 374 |
371 void TracingUI::OnTraceUploadComplete(bool success, | 375 void TracingUI::OnTraceUploadComplete(bool success, |
372 const std::string& feedback) { | 376 const std::string& feedback) { |
373 if (success) { | 377 if (success) { |
374 web_ui()->CallJavascriptFunction("onUploadComplete", | 378 web_ui()->CallJavascriptFunction("onUploadComplete", |
375 base::StringValue(feedback)); | 379 base::StringValue(feedback)); |
376 } else { | 380 } else { |
377 web_ui()->CallJavascriptFunction("onUploadError", | 381 web_ui()->CallJavascriptFunction("onUploadError", |
378 base::StringValue(feedback)); | 382 base::StringValue(feedback)); |
379 } | 383 } |
380 trace_uploader_.reset(); | 384 trace_uploader_.reset(); |
381 } | 385 } |
382 | 386 |
383 } // namespace content | 387 } // namespace content |
OLD | NEW |