| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "content/browser/tracing/tracing_controller_impl.h" | 4 #include "content/browser/tracing/tracing_controller_impl.h" |
| 5 | 5 |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 LAZY_INSTANCE_INITIALIZER; | 36 LAZY_INSTANCE_INITIALIZER; |
| 37 | 37 |
| 38 class FileTraceDataSink : public TracingController::TraceDataSink { | 38 class FileTraceDataSink : public TracingController::TraceDataSink { |
| 39 public: | 39 public: |
| 40 explicit FileTraceDataSink(const base::FilePath& trace_file_path, | 40 explicit FileTraceDataSink(const base::FilePath& trace_file_path, |
| 41 const base::Closure& callback) | 41 const base::Closure& callback) |
| 42 : file_path_(trace_file_path), | 42 : file_path_(trace_file_path), |
| 43 completion_callback_(callback), | 43 completion_callback_(callback), |
| 44 file_(NULL) {} | 44 file_(NULL) {} |
| 45 | 45 |
| 46 virtual void AddTraceChunk(const std::string& chunk) OVERRIDE { | 46 virtual void AddTraceChunk(const std::string& chunk) override { |
| 47 std::string tmp = chunk; | 47 std::string tmp = chunk; |
| 48 scoped_refptr<base::RefCountedString> chunk_ptr = | 48 scoped_refptr<base::RefCountedString> chunk_ptr = |
| 49 base::RefCountedString::TakeString(&tmp); | 49 base::RefCountedString::TakeString(&tmp); |
| 50 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
| 51 BrowserThread::FILE, | 51 BrowserThread::FILE, |
| 52 FROM_HERE, | 52 FROM_HERE, |
| 53 base::Bind( | 53 base::Bind( |
| 54 &FileTraceDataSink::AddTraceChunkOnFileThread, this, chunk_ptr)); | 54 &FileTraceDataSink::AddTraceChunkOnFileThread, this, chunk_ptr)); |
| 55 } | 55 } |
| 56 virtual void SetSystemTrace(const std::string& data) OVERRIDE { | 56 virtual void SetSystemTrace(const std::string& data) override { |
| 57 system_trace_ = data; | 57 system_trace_ = data; |
| 58 } | 58 } |
| 59 virtual void Close() OVERRIDE { | 59 virtual void Close() override { |
| 60 BrowserThread::PostTask( | 60 BrowserThread::PostTask( |
| 61 BrowserThread::FILE, | 61 BrowserThread::FILE, |
| 62 FROM_HERE, | 62 FROM_HERE, |
| 63 base::Bind(&FileTraceDataSink::CloseOnFileThread, this)); | 63 base::Bind(&FileTraceDataSink::CloseOnFileThread, this)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 virtual ~FileTraceDataSink() { DCHECK(file_ == NULL); } | 67 virtual ~FileTraceDataSink() { DCHECK(file_ == NULL); } |
| 68 | 68 |
| 69 void AddTraceChunkOnFileThread( | 69 void AddTraceChunkOnFileThread( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 class StringTraceDataSink : public TracingController::TraceDataSink { | 122 class StringTraceDataSink : public TracingController::TraceDataSink { |
| 123 public: | 123 public: |
| 124 typedef base::Callback<void(base::RefCountedString*)> CompletionCallback; | 124 typedef base::Callback<void(base::RefCountedString*)> CompletionCallback; |
| 125 | 125 |
| 126 explicit StringTraceDataSink(CompletionCallback callback) | 126 explicit StringTraceDataSink(CompletionCallback callback) |
| 127 : completion_callback_(callback) {} | 127 : completion_callback_(callback) {} |
| 128 | 128 |
| 129 // TracingController::TraceDataSink implementation | 129 // TracingController::TraceDataSink implementation |
| 130 virtual void AddTraceChunk(const std::string& chunk) OVERRIDE { | 130 virtual void AddTraceChunk(const std::string& chunk) override { |
| 131 if (!trace_.empty()) | 131 if (!trace_.empty()) |
| 132 trace_ += ","; | 132 trace_ += ","; |
| 133 trace_ += chunk; | 133 trace_ += chunk; |
| 134 } | 134 } |
| 135 virtual void SetSystemTrace(const std::string& data) OVERRIDE { | 135 virtual void SetSystemTrace(const std::string& data) override { |
| 136 system_trace_ = data; | 136 system_trace_ = data; |
| 137 } | 137 } |
| 138 virtual void Close() OVERRIDE { | 138 virtual void Close() override { |
| 139 std::string result = "{\"traceEvents\":[" + trace_ + "]"; | 139 std::string result = "{\"traceEvents\":[" + trace_ + "]"; |
| 140 if (!system_trace_.empty()) | 140 if (!system_trace_.empty()) |
| 141 result += ",\"systemTraceEvents\": " + system_trace_; | 141 result += ",\"systemTraceEvents\": " + system_trace_; |
| 142 result += "}"; | 142 result += "}"; |
| 143 | 143 |
| 144 scoped_refptr<base::RefCountedString> str = | 144 scoped_refptr<base::RefCountedString> str = |
| 145 base::RefCountedString::TakeString(&result); | 145 base::RefCountedString::TakeString(&result); |
| 146 completion_callback_.Run(str.get()); | 146 completion_callback_.Run(str.get()); |
| 147 } | 147 } |
| 148 | 148 |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 is_monitoring_ = is_monitoring; | 877 is_monitoring_ = is_monitoring; |
| 878 #if !defined(OS_ANDROID) | 878 #if !defined(OS_ANDROID) |
| 879 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 879 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
| 880 it != tracing_uis_.end(); it++) { | 880 it != tracing_uis_.end(); it++) { |
| 881 (*it)->OnMonitoringStateChanged(is_monitoring); | 881 (*it)->OnMonitoringStateChanged(is_monitoring); |
| 882 } | 882 } |
| 883 #endif | 883 #endif |
| 884 } | 884 } |
| 885 | 885 |
| 886 } // namespace content | 886 } // namespace content |
| OLD | NEW |