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

Side by Side Diff: chrome/browser/automation/automation_provider.cc

Issue 67683003: Remove TraceController (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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) 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 "chrome/browser/automation/automation_provider.h" 5 #include "chrome/browser/automation/automation_provider.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "chrome/common/chrome_paths.h" 59 #include "chrome/common/chrome_paths.h"
60 #include "chrome/common/chrome_switches.h" 60 #include "chrome/common/chrome_switches.h"
61 #include "chrome/common/chrome_version_info.h" 61 #include "chrome/common/chrome_version_info.h"
62 #include "chrome/common/pref_names.h" 62 #include "chrome/common/pref_names.h"
63 #include "chrome/common/render_messages.h" 63 #include "chrome/common/render_messages.h"
64 #include "chrome/common/url_constants.h" 64 #include "chrome/common/url_constants.h"
65 #include "content/public/browser/browser_thread.h" 65 #include "content/public/browser/browser_thread.h"
66 #include "content/public/browser/download_item.h" 66 #include "content/public/browser/download_item.h"
67 #include "content/public/browser/native_web_keyboard_event.h" 67 #include "content/public/browser/native_web_keyboard_event.h"
68 #include "content/public/browser/render_view_host.h" 68 #include "content/public/browser/render_view_host.h"
69 #include "content/public/browser/trace_controller.h" 69 #include "content/public/browser/tracing_controller.h"
70 #include "content/public/browser/web_contents.h" 70 #include "content/public/browser/web_contents.h"
71 #include "content/public/browser/web_contents_view.h" 71 #include "content/public/browser/web_contents_view.h"
72 #include "net/proxy/proxy_config_service_fixed.h" 72 #include "net/proxy/proxy_config_service_fixed.h"
73 #include "net/proxy/proxy_service.h" 73 #include "net/proxy/proxy_service.h"
74 #include "net/url_request/url_request_context.h" 74 #include "net/url_request/url_request_context.h"
75 #include "net/url_request/url_request_context_getter.h" 75 #include "net/url_request/url_request_context_getter.h"
76 #include "third_party/WebKit/public/web/WebFindOptions.h" 76 #include "third_party/WebKit/public/web/WebFindOptions.h"
77 77
78 #if defined(OS_CHROMEOS) 78 #if defined(OS_CHROMEOS)
79 #include "chromeos/chromeos_switches.h" 79 #include "chromeos/chromeos_switches.h"
80 #include "chromeos/login/login_state.h" 80 #include "chromeos/login/login_state.h"
81 #endif // defined(OS_CHROMEOS) 81 #endif // defined(OS_CHROMEOS)
82 82
83 using blink::WebFindOptions; 83 using blink::WebFindOptions;
84 using base::Time; 84 using base::Time;
85 using content::BrowserThread; 85 using content::BrowserThread;
86 using content::DownloadItem; 86 using content::DownloadItem;
87 using content::NavigationController; 87 using content::NavigationController;
88 using content::RenderViewHost; 88 using content::RenderViewHost;
89 using content::TraceController; 89 using content::TracingController;
90 using content::WebContents; 90 using content::WebContents;
91 91
92 namespace { 92 namespace {
93 93
94 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { 94 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) {
95 DCHECK(pc); 95 DCHECK(pc);
96 bool no_proxy = false; 96 bool no_proxy = false;
97 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { 97 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) {
98 // Make no changes to the ProxyConfig. 98 // Make no changes to the ProxyConfig.
99 return; 99 return;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 void AutomationProvider::OnChannelConnected(int pid) { 369 void AutomationProvider::OnChannelConnected(int pid) {
370 is_connected_ = true; 370 is_connected_ = true;
371 371
372 // Send a hello message with our current automation protocol version. 372 // Send a hello message with our current automation protocol version.
373 VLOG(2) << "Testing channel connected, sending hello message"; 373 VLOG(2) << "Testing channel connected, sending hello message";
374 channel_->Send(new AutomationMsg_Hello(GetProtocolVersion())); 374 channel_->Send(new AutomationMsg_Hello(GetProtocolVersion()));
375 375
376 SendInitialLoadMessage(); 376 SendInitialLoadMessage();
377 } 377 }
378 378
379 void AutomationProvider::OnEndTracingComplete() {
380 IPC::Message* reply_message = tracing_data_.reply_message.release();
381 if (reply_message) {
382 AutomationMsg_EndTracing::WriteReplyParams(
383 reply_message, tracing_data_.trace_output.size(), true);
384 Send(reply_message);
385 }
386 }
387
388 void AutomationProvider::OnTraceDataCollected(
389 const scoped_refptr<base::RefCountedString>& trace_fragment) {
390 tracing_data_.trace_output.push_back(trace_fragment->data());
391 }
392
393 bool AutomationProvider::OnMessageReceived(const IPC::Message& message) { 379 bool AutomationProvider::OnMessageReceived(const IPC::Message& message) {
394 bool handled = true; 380 bool handled = true;
395 bool deserialize_success = true; 381 bool deserialize_success = true;
396 IPC_BEGIN_MESSAGE_MAP_EX(AutomationProvider, message, deserialize_success) 382 IPC_BEGIN_MESSAGE_MAP_EX(AutomationProvider, message, deserialize_success)
397 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) 383 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused)
398 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig) 384 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig)
399 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) 385 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync)
400 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) 386 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest)
401 IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding) 387 IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding)
402 IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll) 388 IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll)
403 IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut) 389 IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut)
404 IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy) 390 IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy)
405 IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste) 391 IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste)
406 IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) 392 IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync)
407 IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) 393 IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync)
408 IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) 394 IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize)
409 IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync) 395 IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync)
410 IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData) 396 IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData)
411 IPC_MESSAGE_HANDLER(AutomationMsg_JavaScriptStressTestControl, 397 IPC_MESSAGE_HANDLER(AutomationMsg_JavaScriptStressTestControl,
412 JavaScriptStressTestControl) 398 JavaScriptStressTestControl)
413 IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing) 399 IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing)
414 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing) 400 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing)
415 IPC_MESSAGE_HANDLER(AutomationMsg_GetTracingOutput, GetTracingOutput)
416 #if defined(OS_WIN) 401 #if defined(OS_WIN)
417 // These are for use with external tabs. 402 // These are for use with external tabs.
418 IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab) 403 IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab)
419 IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator, 404 IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator,
420 ProcessUnhandledAccelerator) 405 ProcessUnhandledAccelerator)
421 IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus) 406 IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus)
422 IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition) 407 IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition)
423 IPC_MESSAGE_HANDLER(AutomationMsg_ForwardContextMenuCommandToChrome, 408 IPC_MESSAGE_HANDLER(AutomationMsg_ForwardContextMenuCommandToChrome,
424 OnForwardContextMenuCommandToChrome) 409 OnForwardContextMenuCommandToChrome)
425 IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab, 410 IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab,
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 NOTREACHED(); 700 NOTREACHED();
716 return; 701 return;
717 } 702 }
718 703
719 view->Send(new ChromeViewMsg_JavaScriptStressTestControl( 704 view->Send(new ChromeViewMsg_JavaScriptStressTestControl(
720 view->GetRoutingID(), cmd, param)); 705 view->GetRoutingID(), cmd, param));
721 } 706 }
722 707
723 void AutomationProvider::BeginTracing(const std::string& category_patterns, 708 void AutomationProvider::BeginTracing(const std::string& category_patterns,
724 bool* success) { 709 bool* success) {
725 tracing_data_.trace_output.clear(); 710 *success = TracingController::GetInstance()->EnableRecording(
726 *success = TraceController::GetInstance()->BeginTracing( 711 category_patterns, TracingController::DEFAULT_OPTIONS,
727 this, 712 TracingController::EnableRecordingDoneCallback());
728 category_patterns,
729 base::debug::TraceLog::RECORD_UNTIL_FULL);
730 } 713 }
731 714
732 void AutomationProvider::EndTracing(IPC::Message* reply_message) { 715 void AutomationProvider::EndTracing(IPC::Message* reply_message) {
733 bool success = false; 716 base::FilePath path;
734 if (!tracing_data_.reply_message.get()) 717 if (!TracingController::GetInstance()->DisableRecording(
735 success = TraceController::GetInstance()->EndTracingAsync(this); 718 path, base::Bind(&AutomationProvider::OnTraceDataCollected, this,
736 if (success) { 719 reply_message))) {
737 // Defer EndTracing reply until TraceController calls us back with all the
738 // events.
739 tracing_data_.reply_message.reset(reply_message);
740 } else {
741 // If failed to call EndTracingAsync, need to reply with failure now. 720 // If failed to call EndTracingAsync, need to reply with failure now.
742 AutomationMsg_EndTracing::WriteReplyParams(reply_message, size_t(0), false); 721 AutomationMsg_EndTracing::WriteReplyParams(reply_message, path, false);
722 Send(reply_message);
723 }
724 // Otherwise defer EndTracing reply until TraceController calls us back.
725 }
726
727 void AutomationProvider::OnTraceDataCollected(IPC::Message* reply_message,
728 const base::FilePath& path) {
729 if (reply_message) {
730 AutomationMsg_EndTracing::WriteReplyParams(reply_message, path, true);
743 Send(reply_message); 731 Send(reply_message);
744 } 732 }
745 } 733 }
746 734
747 void AutomationProvider::GetTracingOutput(std::string* chunk,
748 bool* success) {
749 // The JSON data is sent back to the test in chunks, because IPC sends will
750 // fail if they are too large.
751 if (tracing_data_.trace_output.empty()) {
752 *chunk = "";
753 *success = false;
754 } else {
755 *chunk = tracing_data_.trace_output.front();
756 tracing_data_.trace_output.pop_front();
757 *success = true;
758 }
759 }
760
761 RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { 735 RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) {
762 if (tab_tracker_->ContainsHandle(tab_handle)) { 736 if (tab_tracker_->ContainsHandle(tab_handle)) {
763 NavigationController* tab = tab_tracker_->GetResource(tab_handle); 737 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
764 if (!tab) { 738 if (!tab) {
765 NOTREACHED(); 739 NOTREACHED();
766 return NULL; 740 return NULL;
767 } 741 }
768 742
769 WebContents* web_contents = tab->GetWebContents(); 743 WebContents* web_contents = tab->GetWebContents();
770 if (!web_contents) { 744 if (!web_contents) {
771 NOTREACHED(); 745 NOTREACHED();
772 return NULL; 746 return NULL;
773 } 747 }
774 748
775 RenderViewHost* view_host = web_contents->GetRenderViewHost(); 749 RenderViewHost* view_host = web_contents->GetRenderViewHost();
776 return view_host; 750 return view_host;
777 } 751 }
778 752
779 return NULL; 753 return NULL;
780 } 754 }
781 755
782 void AutomationProvider::SaveAsAsync(int tab_handle) { 756 void AutomationProvider::SaveAsAsync(int tab_handle) {
783 NavigationController* tab = NULL; 757 NavigationController* tab = NULL;
784 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab); 758 WebContents* web_contents = GetWebContentsForHandle(tab_handle, &tab);
785 if (web_contents) 759 if (web_contents)
786 web_contents->OnSavePage(); 760 web_contents->OnSavePage();
787 } 761 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698