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

Unified Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 7866026: Added trace query code and wired tracing through BrowserProxy so tests can run traces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/automation/testing_automation_provider.cc
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 6e45cf21c843601616c89d5d940217dadc784200..b95210950a17289bc6ac1eada8c796601aefee6a 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -251,6 +251,35 @@ void TestingAutomationProvider::Observe(int type,
Release();
}
+void TestingAutomationProvider::OnEndTracingComplete() {
+ IPC::Message* reply_message = tracing_data_.reply_message.release();
+ if (reply_message) {
+ // Finish off JSON string.
+ if (tracing_data_.json_output.empty())
+ tracing_data_.json_output.push_back("[]");
+ else
+ tracing_data_.json_output.push_back("]");
+ AutomationMsg_EndTracing::WriteReplyParams(reply_message, true);
+ Send(reply_message);
+ }
+}
+
+void TestingAutomationProvider::OnTraceDataCollected(
+ const std::string& json_events) {
+ // |json_events| should start with '[' and end with ']'.
+ if (json_events.size() > 2) {
+ std::string chunk;
+ // If this is the first chunk, JSON starts with '['.
+ if (tracing_data_.json_output.empty())
+ chunk += '[';
+ else
+ chunk += ',';
+ chunk += json_events.substr(1, json_events.size() - 2);
+ // Append without the leading and trailing brackets.
+ tracing_data_.json_output.push_back(chunk);
+ }
+}
+
bool TestingAutomationProvider::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
@@ -311,6 +340,9 @@ bool TestingAutomationProvider::OnMessageReceived(
IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType)
IPC_MESSAGE_HANDLER(AutomationMsg_IsBrowserInApplicationMode,
IsBrowserInApplicationMode)
+ IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetTracingOutput, GetTracingOutput)
IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab)
IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID)
IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle)
@@ -1197,6 +1229,45 @@ void TestingAutomationProvider::IsBrowserInApplicationMode(int handle,
}
}
+void TestingAutomationProvider::BeginTracing(
+ const std::vector<std::string>& included_categories,
+ const std::vector<std::string>& excluded_categories,
+ bool* result) {
+ tracing_data_.json_output.clear();
+ *result = TraceController::GetInstance()->BeginTracing(this,
+ included_categories,
+ excluded_categories);
+}
+
+void TestingAutomationProvider::EndTracing(IPC::Message* reply_message) {
+ bool success = false;
+ if (!tracing_data_.reply_message.get()) {
+ success = TraceController::GetInstance()->EndTracingAsync(this);
+ }
+ // If failed to call EndTracingAsync, need to reply with failure now.
+ if (!success) {
+ AutomationMsg_EndTracing::WriteReplyParams(reply_message, false);
+ Send(reply_message);
+ } else {
+ // Defer EndTracing reply until the we are notified by TraceController.
+ tracing_data_.reply_message.reset(reply_message);
+ }
+}
+
+void TestingAutomationProvider::GetTracingOutput(std::string* chunk,
+ int* remaining_chunks) {
+ // The JSON data is sent back to the test in chunks, because IPC sends will
+ // fail if they are too large.
+ if (tracing_data_.json_output.empty()) {
+ *chunk = "";
+ *remaining_chunks = -1;
+ } else {
+ *chunk = tracing_data_.json_output.front();
+ tracing_data_.json_output.pop_front();
+ *remaining_chunks = tracing_data_.json_output.size();
+ }
+}
+
void TestingAutomationProvider::GetTab(int win_handle,
int tab_index,
int* tab_handle) {
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/common/automation_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698