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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_
6 #define CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/ref_counted_memory.h"
13 #include "content/common/content_export.h"
22 // This class is intended to dump the tracing results of the shutdown process
23 // to a file before the browser process exits.
24 // It will save the file either into the command line passed
25 // "--trace-shutdown-file=<name>" parameter - or - to "chrometrace.log" in the
27 // Use the class with a scoped_ptr to get files written in the destructor.
28 // Note that we cannot use the asynchronous file writer since the
29 // |SequencedWorkerPool| will get killed in the shutdown process.
30 class BrowserShutdownProfileDumper
{
32 BrowserShutdownProfileDumper();
34 ~BrowserShutdownProfileDumper();
37 // Writes all traces which happened to disk.
38 void WriteTracesToDisc(const base::FilePath
& file_name
);
40 void EndTraceAndFlush(base::WaitableEvent
* flush_complete_event
);
42 // Returns the file name where we should save the trace dump to.
43 base::FilePath
GetFileName();
45 // The callback for the |TraceLog::Flush| function. It saves all traces to
47 void WriteTraceDataCollected(
48 base::WaitableEvent
* flush_complete_event
,
49 const scoped_refptr
<base::RefCountedString
>& events_str
,
50 bool has_more_events
);
52 // Returns true if the dump file is valid.
55 // Writes a string to the dump file.
56 void WriteString(const std::string
& string
);
58 // Write a buffer to the dump file.
59 void WriteChars(const char* chars
, size_t size
);
61 // Closes the dump file.
64 // The number of blocks we have already written.
66 // For dumping the content to disc.
69 DISALLOW_COPY_AND_ASSIGN(BrowserShutdownProfileDumper
);
72 } // namespace content
74 #endif // CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_