| 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/browser_shutdown_profile_dumper.h" | 5 #include "content/browser/browser_shutdown_profile_dumper.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/location.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 14 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 15 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 16 #include "base/trace_event/trace_event_impl.h" | 18 #include "base/trace_event/trace_event_impl.h" |
| 17 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 | 22 |
| 21 BrowserShutdownProfileDumper::BrowserShutdownProfileDumper( | 23 BrowserShutdownProfileDumper::BrowserShutdownProfileDumper( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 } | 54 } |
| 53 WriteString("{\"traceEvents\":"); | 55 WriteString("{\"traceEvents\":"); |
| 54 WriteString("["); | 56 WriteString("["); |
| 55 | 57 |
| 56 // TraceLog::Flush() requires the calling thread to have a message loop. | 58 // TraceLog::Flush() requires the calling thread to have a message loop. |
| 57 // As the message loop of the current thread may have quit, start another | 59 // As the message loop of the current thread may have quit, start another |
| 58 // thread for flushing the trace. | 60 // thread for flushing the trace. |
| 59 base::WaitableEvent flush_complete_event(false, false); | 61 base::WaitableEvent flush_complete_event(false, false); |
| 60 base::Thread flush_thread("browser_shutdown_trace_event_flush"); | 62 base::Thread flush_thread("browser_shutdown_trace_event_flush"); |
| 61 flush_thread.Start(); | 63 flush_thread.Start(); |
| 62 flush_thread.message_loop()->PostTask( | 64 flush_thread.task_runner()->PostTask( |
| 63 FROM_HERE, | 65 FROM_HERE, base::Bind(&BrowserShutdownProfileDumper::EndTraceAndFlush, |
| 64 base::Bind(&BrowserShutdownProfileDumper::EndTraceAndFlush, | 66 base::Unretained(this), |
| 65 base::Unretained(this), | 67 base::Unretained(&flush_complete_event))); |
| 66 base::Unretained(&flush_complete_event))); | |
| 67 | 68 |
| 68 bool original_wait_allowed = base::ThreadRestrictions::SetWaitAllowed(true); | 69 bool original_wait_allowed = base::ThreadRestrictions::SetWaitAllowed(true); |
| 69 flush_complete_event.Wait(); | 70 flush_complete_event.Wait(); |
| 70 base::ThreadRestrictions::SetWaitAllowed(original_wait_allowed); | 71 base::ThreadRestrictions::SetWaitAllowed(original_wait_allowed); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void BrowserShutdownProfileDumper::EndTraceAndFlush( | 74 void BrowserShutdownProfileDumper::EndTraceAndFlush( |
| 74 base::WaitableEvent* flush_complete_event) { | 75 base::WaitableEvent* flush_complete_event) { |
| 75 base::trace_event::TraceLog::GetInstance()->SetDisabled(); | 76 base::trace_event::TraceLog::GetInstance()->SetDisabled(); |
| 76 base::trace_event::TraceLog::GetInstance()->Flush( | 77 base::trace_event::TraceLog::GetInstance()->Flush( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 140 } |
| 140 | 141 |
| 141 void BrowserShutdownProfileDumper::CloseFile() { | 142 void BrowserShutdownProfileDumper::CloseFile() { |
| 142 if (!dump_file_) | 143 if (!dump_file_) |
| 143 return; | 144 return; |
| 144 base::CloseFile(dump_file_); | 145 base::CloseFile(dump_file_); |
| 145 dump_file_ = NULL; | 146 dump_file_ = NULL; |
| 146 } | 147 } |
| 147 | 148 |
| 148 } // namespace content | 149 } // namespace content |
| OLD | NEW |