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

Side by Side Diff: chrome/browser/ui/webui/tracing_ui.cc

Issue 8355024: Internalize JSON chunk management to trace_event.h API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/tracing_ui.h" 5 #include "chrome/browser/ui/webui/tracing_ui.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // WebUIMessageHandler implementation. 56 // WebUIMessageHandler implementation.
57 virtual WebUIMessageHandler* Attach(WebUI* web_ui); 57 virtual WebUIMessageHandler* Attach(WebUI* web_ui);
58 virtual void RegisterMessages(); 58 virtual void RegisterMessages();
59 59
60 // SelectFileDialog::Listener implementation 60 // SelectFileDialog::Listener implementation
61 virtual void FileSelected(const FilePath& path, int index, void* params); 61 virtual void FileSelected(const FilePath& path, int index, void* params);
62 virtual void FileSelectionCanceled(void* params); 62 virtual void FileSelectionCanceled(void* params);
63 63
64 // TraceSubscriber implementation. 64 // TraceSubscriber implementation.
65 virtual void OnEndTracingComplete(); 65 virtual void OnEndTracingComplete();
66 virtual void OnTraceDataCollected(const std::string& json_events); 66 virtual void OnTraceDataCollected(const std::string& trace_fragment);
67 virtual void OnTraceBufferPercentFullReply(float percent_full); 67 virtual void OnTraceBufferPercentFullReply(float percent_full);
68 68
69 // Messages. 69 // Messages.
70 void OnTracingControllerInitialized(const ListValue* list); 70 void OnTracingControllerInitialized(const ListValue* list);
71 void OnBeginTracing(const ListValue* list); 71 void OnBeginTracing(const ListValue* list);
72 void OnEndTracingAsync(const ListValue* list); 72 void OnEndTracingAsync(const ListValue* list);
73 void OnBeginRequestBufferPercentFull(const ListValue* list); 73 void OnBeginRequestBufferPercentFull(const ListValue* list);
74 void OnLoadTraceFile(const ListValue* list); 74 void OnLoadTraceFile(const ListValue* list);
75 void OnSaveTraceFile(const ListValue* list); 75 void OnSaveTraceFile(const ListValue* list);
76 76
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 412 }
413 } 413 }
414 414
415 void TracingMessageHandler::OnEndTracingComplete() { 415 void TracingMessageHandler::OnEndTracingComplete() {
416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
417 trace_enabled_ = false; 417 trace_enabled_ = false;
418 web_ui_->CallJavascriptFunction("tracingController.onEndTracingComplete"); 418 web_ui_->CallJavascriptFunction("tracingController.onEndTracingComplete");
419 } 419 }
420 420
421 void TracingMessageHandler::OnTraceDataCollected( 421 void TracingMessageHandler::OnTraceDataCollected(
422 const std::string& json_events) { 422 const std::string& trace_fragment) {
423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
424 std::string javascript = "tracingController.onTraceDataCollected(" 424
425 + json_events + ");"; 425 base::debug::TraceResultBuffer::SimpleOutput output;
426 base::debug::TraceResultBuffer trace_buffer;
427 trace_buffer.SetOutputCallback(output.GetCallback());
428 output.Append("tracingController.onTraceDataCollected(");
429 trace_buffer.Start();
430 trace_buffer.AddFragment(trace_fragment);
431 trace_buffer.Finish();
432 output.Append(");");
426 433
427 web_ui_->tab_contents()->render_view_host()-> 434 web_ui_->tab_contents()->render_view_host()->
428 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(javascript)); 435 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(output.json_output));
429 } 436 }
430 437
431 void TracingMessageHandler::OnTraceBufferPercentFullReply(float percent_full) { 438 void TracingMessageHandler::OnTraceBufferPercentFullReply(float percent_full) {
432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
433 web_ui_->CallJavascriptFunction( 440 web_ui_->CallJavascriptFunction(
434 "tracingController.onRequestBufferPercentFullComplete", 441 "tracingController.onRequestBufferPercentFullComplete",
435 *scoped_ptr<Value>(Value::CreateDoubleValue(percent_full))); 442 *scoped_ptr<Value>(Value::CreateDoubleValue(percent_full)));
436 } 443 }
437 444
438 } // namespace 445 } // namespace
439 446
440 447
441 //////////////////////////////////////////////////////////////////////////////// 448 ////////////////////////////////////////////////////////////////////////////////
442 // 449 //
443 // TracingUI 450 // TracingUI
444 // 451 //
445 //////////////////////////////////////////////////////////////////////////////// 452 ////////////////////////////////////////////////////////////////////////////////
446 453
447 TracingUI::TracingUI(TabContents* contents) : ChromeWebUI(contents) { 454 TracingUI::TracingUI(TabContents* contents) : ChromeWebUI(contents) {
448 AddMessageHandler((new TracingMessageHandler())->Attach(this)); 455 AddMessageHandler((new TracingMessageHandler())->Attach(this));
449 456
450 // Set up the chrome://tracing/ source. 457 // Set up the chrome://tracing/ source.
451 Profile::FromBrowserContext(contents->browser_context())-> 458 Profile::FromBrowserContext(contents->browser_context())->
452 GetChromeURLDataManager()->AddDataSource(CreateTracingHTMLSource()); 459 GetChromeURLDataManager()->AddDataSource(CreateTracingHTMLSource());
453 } 460 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698