Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: content/browser/tracing/tracing_ui.cc

Issue 1225923003: Make compression optional in TraceUploader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
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 trace_uploader_->DoUpload(file_contents, compress_on_upload, nullptr,
357 done_callback); 358 progress_callback, done_callback);
358 // TODO(mmandlis): Add support for stopping the upload in progress. 359 // TODO(mmandlis): Add support for stopping the upload in progress.
359 } 360 }
360 361
361 void TracingUI::OnTraceUploadProgress(int64 current, int64 total) { 362 void TracingUI::OnTraceUploadProgress(int64 current, int64 total) {
362 DCHECK(current <= total); 363 DCHECK(current <= total);
363 int percent = (current / total) * 100; 364 int percent = (current / total) * 100;
364 web_ui()->CallJavascriptFunction( 365 web_ui()->CallJavascriptFunction(
365 "onUploadProgress", 366 "onUploadProgress",
366 base::FundamentalValue(percent), 367 base::FundamentalValue(percent),
367 base::StringValue(base::StringPrintf("%" PRId64, current)), 368 base::StringValue(base::StringPrintf("%" PRId64, current)),
368 base::StringValue(base::StringPrintf("%" PRId64, total))); 369 base::StringValue(base::StringPrintf("%" PRId64, total)));
369 } 370 }
370 371
371 void TracingUI::OnTraceUploadComplete(bool success, 372 void TracingUI::OnTraceUploadComplete(bool success,
372 const std::string& feedback) { 373 const std::string& feedback) {
373 if (success) { 374 if (success) {
374 web_ui()->CallJavascriptFunction("onUploadComplete", 375 web_ui()->CallJavascriptFunction("onUploadComplete",
375 base::StringValue(feedback)); 376 base::StringValue(feedback));
376 } else { 377 } else {
377 web_ui()->CallJavascriptFunction("onUploadError", 378 web_ui()->CallJavascriptFunction("onUploadError",
378 base::StringValue(feedback)); 379 base::StringValue(feedback));
379 } 380 }
380 trace_uploader_.reset(); 381 trace_uploader_.reset();
381 } 382 }
382 383
383 } // namespace content 384 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698