| OLD | NEW |
| 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 Loading... |
| 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& trace_fragment); | 66 virtual void OnTraceDataCollected(const std::string& json_events); |
| 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 Loading... |
| 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& trace_fragment) { | 422 const std::string& json_events) { |
| 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 424 | 424 std::string javascript = "tracingController.onTraceDataCollected(" |
| 425 base::debug::TraceResultBuffer::SimpleOutput output; | 425 + json_events + ");"; |
| 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(");"); | |
| 433 | 426 |
| 434 web_ui_->tab_contents()->render_view_host()-> | 427 web_ui_->tab_contents()->render_view_host()-> |
| 435 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(output.json_output)); | 428 ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(javascript)); |
| 436 } | 429 } |
| 437 | 430 |
| 438 void TracingMessageHandler::OnTraceBufferPercentFullReply(float percent_full) { | 431 void TracingMessageHandler::OnTraceBufferPercentFullReply(float percent_full) { |
| 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 440 web_ui_->CallJavascriptFunction( | 433 web_ui_->CallJavascriptFunction( |
| 441 "tracingController.onRequestBufferPercentFullComplete", | 434 "tracingController.onRequestBufferPercentFullComplete", |
| 442 *scoped_ptr<Value>(Value::CreateDoubleValue(percent_full))); | 435 *scoped_ptr<Value>(Value::CreateDoubleValue(percent_full))); |
| 443 } | 436 } |
| 444 | 437 |
| 445 } // namespace | 438 } // namespace |
| 446 | 439 |
| 447 | 440 |
| 448 //////////////////////////////////////////////////////////////////////////////// | 441 //////////////////////////////////////////////////////////////////////////////// |
| 449 // | 442 // |
| 450 // TracingUI | 443 // TracingUI |
| 451 // | 444 // |
| 452 //////////////////////////////////////////////////////////////////////////////// | 445 //////////////////////////////////////////////////////////////////////////////// |
| 453 | 446 |
| 454 TracingUI::TracingUI(TabContents* contents) : ChromeWebUI(contents) { | 447 TracingUI::TracingUI(TabContents* contents) : ChromeWebUI(contents) { |
| 455 AddMessageHandler((new TracingMessageHandler())->Attach(this)); | 448 AddMessageHandler((new TracingMessageHandler())->Attach(this)); |
| 456 | 449 |
| 457 // Set up the chrome://tracing/ source. | 450 // Set up the chrome://tracing/ source. |
| 458 Profile::FromBrowserContext(contents->browser_context())-> | 451 Profile::FromBrowserContext(contents->browser_context())-> |
| 459 GetChromeURLDataManager()->AddDataSource(CreateTracingHTMLSource()); | 452 GetChromeURLDataManager()->AddDataSource(CreateTracingHTMLSource()); |
| 460 } | 453 } |
| OLD | NEW |