| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/tracing/tracing_controller_impl.h" | 5 #include "content/browser/tracing/tracing_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 path_(path), | 61 path_(path), |
| 62 has_at_least_one_result_(false) { | 62 has_at_least_one_result_(false) { |
| 63 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 63 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 64 base::Bind(&TracingControllerImpl::ResultFile::OpenTask, | 64 base::Bind(&TracingControllerImpl::ResultFile::OpenTask, |
| 65 base::Unretained(this))); | 65 base::Unretained(this))); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void TracingControllerImpl::ResultFile::OpenTask() { | 68 void TracingControllerImpl::ResultFile::OpenTask() { |
| 69 if (path_.empty()) | 69 if (path_.empty()) |
| 70 base::CreateTemporaryFile(&path_); | 70 base::CreateTemporaryFile(&path_); |
| 71 file_ = file_util::OpenFile(path_, "w"); | 71 file_ = base::OpenFile(path_, "w"); |
| 72 if (!file_) { | 72 if (!file_) { |
| 73 LOG(ERROR) << "Failed to open " << path_.value(); | 73 LOG(ERROR) << "Failed to open " << path_.value(); |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 const char* preamble = "{\"traceEvents\": ["; | 76 const char* preamble = "{\"traceEvents\": ["; |
| 77 size_t written = fwrite(preamble, strlen(preamble), 1, file_); | 77 size_t written = fwrite(preamble, strlen(preamble), 1, file_); |
| 78 DCHECK(written == 1); | 78 DCHECK(written == 1); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void TracingControllerImpl::ResultFile::WriteTask( | 81 void TracingControllerImpl::ResultFile::WriteTask( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 void TracingControllerImpl::ResultFile::CloseTask( | 99 void TracingControllerImpl::ResultFile::CloseTask( |
| 100 const base::Closure& callback) { | 100 const base::Closure& callback) { |
| 101 if (!file_) | 101 if (!file_) |
| 102 return; | 102 return; |
| 103 | 103 |
| 104 const char* trailout = "]}"; | 104 const char* trailout = "]}"; |
| 105 size_t written = fwrite(trailout, strlen(trailout), 1, file_); | 105 size_t written = fwrite(trailout, strlen(trailout), 1, file_); |
| 106 DCHECK(written == 1); | 106 DCHECK(written == 1); |
| 107 file_util::CloseFile(file_); | 107 base::CloseFile(file_); |
| 108 file_ = NULL; | 108 file_ = NULL; |
| 109 | 109 |
| 110 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 110 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| 114 TracingControllerImpl::TracingControllerImpl() : | 114 TracingControllerImpl::TracingControllerImpl() : |
| 115 pending_disable_recording_ack_count_(0), | 115 pending_disable_recording_ack_count_(0), |
| 116 pending_capture_monitoring_snapshot_ack_count_(0), | 116 pending_capture_monitoring_snapshot_ack_count_(0), |
| 117 pending_trace_buffer_percent_full_ack_count_(0), | 117 pending_trace_buffer_percent_full_ack_count_(0), |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | 638 base::Bind(&TracingControllerImpl::OnWatchEventMatched, |
| 639 base::Unretained(this))); | 639 base::Unretained(this))); |
| 640 return; | 640 return; |
| 641 } | 641 } |
| 642 | 642 |
| 643 if (!watch_event_callback_.is_null()) | 643 if (!watch_event_callback_.is_null()) |
| 644 watch_event_callback_.Run(); | 644 watch_event_callback_.Run(); |
| 645 } | 645 } |
| 646 | 646 |
| 647 } // namespace content | 647 } // namespace content |
| OLD | NEW |