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

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

Issue 1995113002: Rename WebUI::CallJavascriptFunction to WebUI::CallJavascriptFunctionUnsafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 TracingControllerImpl::GetInstance()->RegisterTracingUI(this); 242 TracingControllerImpl::GetInstance()->RegisterTracingUI(this);
243 } 243 }
244 244
245 TracingUI::~TracingUI() { 245 TracingUI::~TracingUI() {
246 TracingControllerImpl::GetInstance()->UnregisterTracingUI(this); 246 TracingControllerImpl::GetInstance()->UnregisterTracingUI(this);
247 } 247 }
248 248
249 void TracingUI::DoUploadBase64Encoded(const base::ListValue* args) { 249 void TracingUI::DoUploadBase64Encoded(const base::ListValue* args) {
250 std::string file_contents_base64; 250 std::string file_contents_base64;
251 if (!args || args->empty() || !args->GetString(0, &file_contents_base64)) { 251 if (!args || args->empty() || !args->GetString(0, &file_contents_base64)) {
252 web_ui()->CallJavascriptFunction("onUploadError", 252 web_ui()->CallJavascriptFunctionUnsafe("onUploadError",
253 base::StringValue("Missing data")); 253 base::StringValue("Missing data"));
254 return; 254 return;
255 } 255 }
256 256
257 std::string file_contents; 257 std::string file_contents;
258 base::Base64Decode(file_contents_base64, &file_contents); 258 base::Base64Decode(file_contents_base64, &file_contents);
259 259
260 // doUploadBase64 is used to upload binary data which is assumed to already 260 // doUploadBase64 is used to upload binary data which is assumed to already
261 // be compressed. 261 // be compressed.
262 DoUploadInternal(file_contents, TraceUploader::UNCOMPRESSED_UPLOAD); 262 DoUploadInternal(file_contents, TraceUploader::UNCOMPRESSED_UPLOAD);
263 } 263 }
264 264
265 void TracingUI::DoUpload(const base::ListValue* args) { 265 void TracingUI::DoUpload(const base::ListValue* args) {
266 std::string file_contents; 266 std::string file_contents;
267 if (!args || args->empty() || !args->GetString(0, &file_contents)) { 267 if (!args || args->empty() || !args->GetString(0, &file_contents)) {
268 web_ui()->CallJavascriptFunction("onUploadError", 268 web_ui()->CallJavascriptFunctionUnsafe("onUploadError",
269 base::StringValue("Missing data")); 269 base::StringValue("Missing data"));
270 return; 270 return;
271 } 271 }
272 272
273 DoUploadInternal(file_contents, TraceUploader::COMPRESSED_UPLOAD); 273 DoUploadInternal(file_contents, TraceUploader::COMPRESSED_UPLOAD);
274 } 274 }
275 275
276 void TracingUI::DoUploadInternal(const std::string& file_contents, 276 void TracingUI::DoUploadInternal(const std::string& file_contents,
277 TraceUploader::UploadMode upload_mode) { 277 TraceUploader::UploadMode upload_mode) {
278 if (!delegate_) { 278 if (!delegate_) {
279 web_ui()->CallJavascriptFunction("onUploadError", 279 web_ui()->CallJavascriptFunctionUnsafe(
280 base::StringValue("Not implemented")); 280 "onUploadError", base::StringValue("Not implemented"));
281 return; 281 return;
282 } 282 }
283 283
284 if (trace_uploader_) { 284 if (trace_uploader_) {
285 web_ui()->CallJavascriptFunction("onUploadError", 285 web_ui()->CallJavascriptFunctionUnsafe(
286 base::StringValue("Upload in progress")); 286 "onUploadError", base::StringValue("Upload in progress"));
287 return; 287 return;
288 } 288 }
289 289
290 TraceUploader::UploadProgressCallback progress_callback = 290 TraceUploader::UploadProgressCallback progress_callback =
291 base::Bind(&TracingUI::OnTraceUploadProgress, 291 base::Bind(&TracingUI::OnTraceUploadProgress,
292 weak_factory_.GetWeakPtr()); 292 weak_factory_.GetWeakPtr());
293 TraceUploader::UploadDoneCallback done_callback = 293 TraceUploader::UploadDoneCallback done_callback =
294 base::Bind(&TracingUI::OnTraceUploadComplete, 294 base::Bind(&TracingUI::OnTraceUploadComplete,
295 weak_factory_.GetWeakPtr()); 295 weak_factory_.GetWeakPtr());
296 296
297 trace_uploader_ = delegate_->GetTraceUploader( 297 trace_uploader_ = delegate_->GetTraceUploader(
298 BrowserContext::GetDefaultStoragePartition( 298 BrowserContext::GetDefaultStoragePartition(
299 web_ui()->GetWebContents()->GetBrowserContext())-> 299 web_ui()->GetWebContents()->GetBrowserContext())->
300 GetURLRequestContext()); 300 GetURLRequestContext());
301 DCHECK(trace_uploader_); 301 DCHECK(trace_uploader_);
302 trace_uploader_->DoUpload(file_contents, upload_mode, nullptr, 302 trace_uploader_->DoUpload(file_contents, upload_mode, nullptr,
303 progress_callback, done_callback); 303 progress_callback, done_callback);
304 // TODO(mmandlis): Add support for stopping the upload in progress. 304 // TODO(mmandlis): Add support for stopping the upload in progress.
305 } 305 }
306 306
307 void TracingUI::OnTraceUploadProgress(int64_t current, int64_t total) { 307 void TracingUI::OnTraceUploadProgress(int64_t current, int64_t total) {
308 DCHECK(current <= total); 308 DCHECK(current <= total);
309 int percent = (current / total) * 100; 309 int percent = (current / total) * 100;
310 web_ui()->CallJavascriptFunction( 310 web_ui()->CallJavascriptFunctionUnsafe(
311 "onUploadProgress", 311 "onUploadProgress", base::FundamentalValue(percent),
312 base::FundamentalValue(percent), 312 base::StringValue(base::StringPrintf("%" PRId64, current)),
313 base::StringValue(base::StringPrintf("%" PRId64, current)), 313 base::StringValue(base::StringPrintf("%" PRId64, total)));
314 base::StringValue(base::StringPrintf("%" PRId64, total)));
315 } 314 }
316 315
317 void TracingUI::OnTraceUploadComplete(bool success, 316 void TracingUI::OnTraceUploadComplete(bool success,
318 const std::string& feedback) { 317 const std::string& feedback) {
319 if (success) { 318 if (success) {
320 web_ui()->CallJavascriptFunction("onUploadComplete", 319 web_ui()->CallJavascriptFunctionUnsafe("onUploadComplete",
321 base::StringValue(feedback)); 320 base::StringValue(feedback));
322 } else { 321 } else {
323 web_ui()->CallJavascriptFunction("onUploadError", 322 web_ui()->CallJavascriptFunctionUnsafe("onUploadError",
324 base::StringValue(feedback)); 323 base::StringValue(feedback));
325 } 324 }
326 trace_uploader_.reset(); 325 trace_uploader_.reset();
327 } 326 }
328 327
329 } // namespace content 328 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_internals_ui.cc ('k') | content/browser/webui/web_ui_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698