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

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: Added comment for clarification. 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
« no previous file with comments | « content/browser/tracing/tracing_ui.h ('k') | content/public/browser/trace_uploader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // doUploadBase64 is used to upload binary data which is assumed to already
320 // be compressed.
321 DoUploadInternal(file_contents, TraceUploader::UNCOMPRESSED_UPLOAD);
320 } 322 }
321 323
322 void TracingUI::DoUpload(const base::ListValue* args) { 324 void TracingUI::DoUpload(const base::ListValue* args) {
323 std::string file_contents; 325 std::string file_contents;
324 if (!args || args->empty() || !args->GetString(0, &file_contents)) { 326 if (!args || args->empty() || !args->GetString(0, &file_contents)) {
325 web_ui()->CallJavascriptFunction("onUploadError", 327 web_ui()->CallJavascriptFunction("onUploadError",
326 base::StringValue("Missing data")); 328 base::StringValue("Missing data"));
327 return; 329 return;
328 } 330 }
329 331
330 DoUploadInternal(file_contents); 332 DoUploadInternal(file_contents, TraceUploader::COMPRESSED_UPLOAD);
331 } 333 }
332 334
333 void TracingUI::DoUploadInternal(const std::string& file_contents) { 335 void TracingUI::DoUploadInternal(const std::string& file_contents,
336 TraceUploader::UploadMode upload_mode) {
334 if (!delegate_) { 337 if (!delegate_) {
335 web_ui()->CallJavascriptFunction("onUploadError", 338 web_ui()->CallJavascriptFunction("onUploadError",
336 base::StringValue("Not implemented")); 339 base::StringValue("Not implemented"));
337 return; 340 return;
338 } 341 }
339 342
340 if (trace_uploader_) { 343 if (trace_uploader_) {
341 web_ui()->CallJavascriptFunction("onUploadError", 344 web_ui()->CallJavascriptFunction("onUploadError",
342 base::StringValue("Upload in progress")); 345 base::StringValue("Upload in progress"));
343 return; 346 return;
344 } 347 }
345 348
346 TraceUploader::UploadProgressCallback progress_callback = 349 TraceUploader::UploadProgressCallback progress_callback =
347 base::Bind(&TracingUI::OnTraceUploadProgress, 350 base::Bind(&TracingUI::OnTraceUploadProgress,
348 weak_factory_.GetWeakPtr()); 351 weak_factory_.GetWeakPtr());
349 TraceUploader::UploadDoneCallback done_callback = 352 TraceUploader::UploadDoneCallback done_callback =
350 base::Bind(&TracingUI::OnTraceUploadComplete, 353 base::Bind(&TracingUI::OnTraceUploadComplete,
351 weak_factory_.GetWeakPtr()); 354 weak_factory_.GetWeakPtr());
352 355
353 trace_uploader_ = delegate_->GetTraceUploader( 356 trace_uploader_ = delegate_->GetTraceUploader(
354 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext()); 357 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext());
355 DCHECK(trace_uploader_); 358 DCHECK(trace_uploader_);
356 trace_uploader_->DoUpload(file_contents, nullptr, progress_callback, 359 trace_uploader_->DoUpload(file_contents, upload_mode, nullptr,
357 done_callback); 360 progress_callback, done_callback);
358 // TODO(mmandlis): Add support for stopping the upload in progress. 361 // TODO(mmandlis): Add support for stopping the upload in progress.
359 } 362 }
360 363
361 void TracingUI::OnTraceUploadProgress(int64 current, int64 total) { 364 void TracingUI::OnTraceUploadProgress(int64 current, int64 total) {
362 DCHECK(current <= total); 365 DCHECK(current <= total);
363 int percent = (current / total) * 100; 366 int percent = (current / total) * 100;
364 web_ui()->CallJavascriptFunction( 367 web_ui()->CallJavascriptFunction(
365 "onUploadProgress", 368 "onUploadProgress",
366 base::FundamentalValue(percent), 369 base::FundamentalValue(percent),
367 base::StringValue(base::StringPrintf("%" PRId64, current)), 370 base::StringValue(base::StringPrintf("%" PRId64, current)),
368 base::StringValue(base::StringPrintf("%" PRId64, total))); 371 base::StringValue(base::StringPrintf("%" PRId64, total)));
369 } 372 }
370 373
371 void TracingUI::OnTraceUploadComplete(bool success, 374 void TracingUI::OnTraceUploadComplete(bool success,
372 const std::string& feedback) { 375 const std::string& feedback) {
373 if (success) { 376 if (success) {
374 web_ui()->CallJavascriptFunction("onUploadComplete", 377 web_ui()->CallJavascriptFunction("onUploadComplete",
375 base::StringValue(feedback)); 378 base::StringValue(feedback));
376 } else { 379 } else {
377 web_ui()->CallJavascriptFunction("onUploadError", 380 web_ui()->CallJavascriptFunction("onUploadError",
378 base::StringValue(feedback)); 381 base::StringValue(feedback));
379 } 382 }
380 trace_uploader_.reset(); 383 trace_uploader_.reset();
381 } 384 }
382 385
383 } // namespace content 386 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/tracing_ui.h ('k') | content/public/browser/trace_uploader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698