[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #ifndef CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ | ||||
6 | #define CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ | ||||
7 | |||||
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include <stddef.h> |
9 | |||||
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 10 | #include <string> |
11 | |||||
[email protected] | cec9563 | 2014-07-02 18:01:50 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
15 | #include "base/memory/ref_counted_memory.h" | ||||
16 | #include "content/common/content_export.h" | ||||
17 | |||||
18 | namespace base { | ||||
19 | class FilePath; | ||||
[email protected] | f9be1053 | 2013-09-18 08:15:46 | [diff] [blame] | 20 | class WaitableEvent; |
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 21 | } |
22 | |||||
23 | namespace content { | ||||
24 | |||||
25 | // This class is intended to dump the tracing results of the shutdown process | ||||
26 | // to a file before the browser process exits. | ||||
27 | // It will save the file either into the command line passed | ||||
28 | // "--trace-shutdown-file=<name>" parameter - or - to "chrometrace.log" in the | ||||
29 | // current directory. | ||||
30 | // Use the class with a scoped_ptr to get files written in the destructor. | ||||
31 | // Note that we cannot use the asynchronous file writer since the | ||||
32 | // |SequencedWorkerPool| will get killed in the shutdown process. | ||||
33 | class BrowserShutdownProfileDumper { | ||||
34 | public: | ||||
[email protected] | cec9563 | 2014-07-02 18:01:50 | [diff] [blame] | 35 | explicit BrowserShutdownProfileDumper(const base::FilePath& dump_file_name); |
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 36 | |
37 | ~BrowserShutdownProfileDumper(); | ||||
38 | |||||
[email protected] | cec9563 | 2014-07-02 18:01:50 | [diff] [blame] | 39 | // Returns the file name where we should save the shutdown trace dump to. |
40 | static base::FilePath GetShutdownProfileFileName(); | ||||
41 | |||||
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 42 | private: |
43 | // Writes all traces which happened to disk. | ||||
[email protected] | cec9563 | 2014-07-02 18:01:50 | [diff] [blame] | 44 | void WriteTracesToDisc(); |
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 45 | |
[email protected] | f9be1053 | 2013-09-18 08:15:46 | [diff] [blame] | 46 | void EndTraceAndFlush(base::WaitableEvent* flush_complete_event); |
47 | |||||
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 48 | // The callback for the |TraceLog::Flush| function. It saves all traces to |
49 | // disc. | ||||
50 | void WriteTraceDataCollected( | ||||
[email protected] | f9be1053 | 2013-09-18 08:15:46 | [diff] [blame] | 51 | base::WaitableEvent* flush_complete_event, |
[email protected] | 07b8773 | 2013-09-06 20:18:05 | [diff] [blame] | 52 | const scoped_refptr<base::RefCountedString>& events_str, |
53 | bool has_more_events); | ||||
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 54 | |
55 | // Returns true if the dump file is valid. | ||||
56 | bool IsFileValid(); | ||||
57 | |||||
58 | // Writes a string to the dump file. | ||||
59 | void WriteString(const std::string& string); | ||||
60 | |||||
61 | // Write a buffer to the dump file. | ||||
62 | void WriteChars(const char* chars, size_t size); | ||||
63 | |||||
64 | // Closes the dump file. | ||||
65 | void CloseFile(); | ||||
66 | |||||
[email protected] | cec9563 | 2014-07-02 18:01:50 | [diff] [blame] | 67 | // The name of the dump file. |
68 | const base::FilePath dump_file_name_; | ||||
69 | |||||
[email protected] | 89af400 | 2013-09-06 07:47:07 | [diff] [blame] | 70 | // The number of blocks we have already written. |
71 | int blocks_; | ||||
72 | // For dumping the content to disc. | ||||
73 | FILE* dump_file_; | ||||
74 | |||||
75 | DISALLOW_COPY_AND_ASSIGN(BrowserShutdownProfileDumper); | ||||
76 | }; | ||||
77 | |||||
78 | } // namespace content | ||||
79 | |||||
80 | #endif // CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ |