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/debug/trace_event.h" | 10 #include "base/file_util.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 size_t num_trace_chunks = 0; | 413 base::FilePath path; |
414 if (!Send(new AutomationMsg_EndTracing(&num_trace_chunks, &success)) || | 414 if (!Send(new AutomationMsg_EndTracing(&path, &success)) || !success) |
415 !success) | |
416 return false; | 415 return false; |
417 | 416 |
418 std::string chunk; | 417 bool ok = base::ReadFileToString(path, json_trace_output); |
419 base::debug::TraceResultBuffer buffer; | 418 DCHECK(ok); |
420 base::debug::TraceResultBuffer::SimpleOutput output; | 419 base::DeleteFile(path, false); |
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; | |
438 return true; | 420 return true; |
439 } | 421 } |
440 | 422 |
441 bool AutomationProxy::SendJSONRequest(const std::string& request, | 423 bool AutomationProxy::SendJSONRequest(const std::string& request, |
442 int timeout_ms, | 424 int timeout_ms, |
443 std::string* response) { | 425 std::string* response) { |
444 bool result = false; | 426 bool result = false; |
445 if (!Send(new AutomationMsg_SendJSONRequest(-1, request, response, &result), | 427 if (!Send(new AutomationMsg_SendJSONRequest(-1, request, response, &result), |
446 timeout_ms)) | 428 timeout_ms)) |
447 return false; | 429 return false; |
448 return result; | 430 return result; |
449 } | 431 } |
OLD | NEW |