OLD | NEW |
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/test/automation/automation_proxy.h" | 5 #include "chrome/test/automation/automation_proxy.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_util.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
15 #include "chrome/common/automation_constants.h" | 15 #include "chrome/common/automation_constants.h" |
16 #include "chrome/common/automation_messages.h" | 16 #include "chrome/common/automation_messages.h" |
17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
18 #include "chrome/test/automation/browser_proxy.h" | 18 #include "chrome/test/automation/browser_proxy.h" |
19 #include "chrome/test/automation/tab_proxy.h" | 19 #include "chrome/test/automation/tab_proxy.h" |
20 #include "chrome/test/automation/window_proxy.h" | 20 #include "chrome/test/automation/window_proxy.h" |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 403 |
404 bool AutomationProxy::BeginTracing(const std::string& category_patterns) { | 404 bool AutomationProxy::BeginTracing(const std::string& category_patterns) { |
405 bool result = false; | 405 bool result = false; |
406 bool send_success = Send(new AutomationMsg_BeginTracing(category_patterns, | 406 bool send_success = Send(new AutomationMsg_BeginTracing(category_patterns, |
407 &result)); | 407 &result)); |
408 return send_success && result; | 408 return send_success && result; |
409 } | 409 } |
410 | 410 |
411 bool AutomationProxy::EndTracing(std::string* json_trace_output) { | 411 bool AutomationProxy::EndTracing(std::string* json_trace_output) { |
412 bool success = false; | 412 bool success = false; |
413 base::FilePath path; | 413 size_t num_trace_chunks = 0; |
414 if (!Send(new AutomationMsg_EndTracing(&path, &success)) || !success) | 414 if (!Send(new AutomationMsg_EndTracing(&num_trace_chunks, &success)) || |
| 415 !success) |
415 return false; | 416 return false; |
416 | 417 |
417 bool ok = base::ReadFileToString(path, json_trace_output); | 418 std::string chunk; |
418 DCHECK(ok); | 419 base::debug::TraceResultBuffer buffer; |
419 base::DeleteFile(path, false); | 420 base::debug::TraceResultBuffer::SimpleOutput output; |
| 421 buffer.SetOutputCallback(output.GetCallback()); |
| 422 |
| 423 // TODO(jbates): See bug 100255, IPC send fails if message is too big. This |
| 424 // code can be simplified if that limitation is fixed. |
| 425 // Workaround IPC payload size limitation by getting chunks. |
| 426 buffer.Start(); |
| 427 for (size_t i = 0; i < num_trace_chunks; ++i) { |
| 428 // The broswer side AutomationProvider resets state at BeginTracing, |
| 429 // so it can recover even after this fails mid-way. |
| 430 if (!Send(new AutomationMsg_GetTracingOutput(&chunk, &success)) || |
| 431 !success) |
| 432 return false; |
| 433 buffer.AddFragment(chunk); |
| 434 } |
| 435 buffer.Finish(); |
| 436 |
| 437 *json_trace_output = output.json_output; |
420 return true; | 438 return true; |
421 } | 439 } |
422 | 440 |
423 bool AutomationProxy::SendJSONRequest(const std::string& request, | 441 bool AutomationProxy::SendJSONRequest(const std::string& request, |
424 int timeout_ms, | 442 int timeout_ms, |
425 std::string* response) { | 443 std::string* response) { |
426 bool result = false; | 444 bool result = false; |
427 if (!Send(new AutomationMsg_SendJSONRequest(-1, request, response, &result), | 445 if (!Send(new AutomationMsg_SendJSONRequest(-1, request, response, &result), |
428 timeout_ms)) | 446 timeout_ms)) |
429 return false; | 447 return false; |
430 return result; | 448 return result; |
431 } | 449 } |
OLD | NEW |