Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: content/browser/browser_shutdown_profile_dumper.h

Issue 359473006: Store unsaved trace data on exit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ 5 #ifndef CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_
6 #define CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ 6 #define CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
13 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
14 15
15 namespace base { 16 namespace base {
16 class FilePath; 17 class FilePath;
17 class WaitableEvent; 18 class WaitableEvent;
18 } 19 }
19 20
20 namespace content { 21 namespace content {
21 22
22 // This class is intended to dump the tracing results of the shutdown process 23 // This class is intended to dump the tracing results of the shutdown process
23 // to a file before the browser process exits. 24 // to a file before the browser process exits.
24 // It will save the file either into the command line passed 25 // It will save the file either into the command line passed
25 // "--trace-shutdown-file=<name>" parameter - or - to "chrometrace.log" in the 26 // "--trace-shutdown-file=<name>" parameter - or - to "chrometrace.log" in the
26 // current directory. 27 // current directory.
27 // Use the class with a scoped_ptr to get files written in the destructor. 28 // 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 // Note that we cannot use the asynchronous file writer since the
29 // |SequencedWorkerPool| will get killed in the shutdown process. 30 // |SequencedWorkerPool| will get killed in the shutdown process.
30 class BrowserShutdownProfileDumper { 31 class BrowserShutdownProfileDumper {
31 public: 32 public:
32 BrowserShutdownProfileDumper(); 33 explicit BrowserShutdownProfileDumper(const base::FilePath& dump_file_name);
33 34
34 ~BrowserShutdownProfileDumper(); 35 ~BrowserShutdownProfileDumper();
35 36
37 // Returns the file name where we should save the shutdown trace dump to.
38 static base::FilePath GetShutdownProfileFileName();
39
36 private: 40 private:
37 // Writes all traces which happened to disk. 41 // Writes all traces which happened to disk.
38 void WriteTracesToDisc(const base::FilePath& file_name); 42 void WriteTracesToDisc();
39 43
40 void EndTraceAndFlush(base::WaitableEvent* flush_complete_event); 44 void EndTraceAndFlush(base::WaitableEvent* flush_complete_event);
41 45
42 // Returns the file name where we should save the trace dump to.
43 base::FilePath GetFileName();
44
45 // The callback for the |TraceLog::Flush| function. It saves all traces to 46 // The callback for the |TraceLog::Flush| function. It saves all traces to
46 // disc. 47 // disc.
47 void WriteTraceDataCollected( 48 void WriteTraceDataCollected(
48 base::WaitableEvent* flush_complete_event, 49 base::WaitableEvent* flush_complete_event,
49 const scoped_refptr<base::RefCountedString>& events_str, 50 const scoped_refptr<base::RefCountedString>& events_str,
50 bool has_more_events); 51 bool has_more_events);
51 52
52 // Returns true if the dump file is valid. 53 // Returns true if the dump file is valid.
53 bool IsFileValid(); 54 bool IsFileValid();
54 55
55 // Writes a string to the dump file. 56 // Writes a string to the dump file.
56 void WriteString(const std::string& string); 57 void WriteString(const std::string& string);
57 58
58 // Write a buffer to the dump file. 59 // Write a buffer to the dump file.
59 void WriteChars(const char* chars, size_t size); 60 void WriteChars(const char* chars, size_t size);
60 61
61 // Closes the dump file. 62 // Closes the dump file.
62 void CloseFile(); 63 void CloseFile();
63 64
65 // The name of the dump file.
66 const base::FilePath dump_file_name_;
67
64 // The number of blocks we have already written. 68 // The number of blocks we have already written.
65 int blocks_; 69 int blocks_;
66 // For dumping the content to disc. 70 // For dumping the content to disc.
67 FILE* dump_file_; 71 FILE* dump_file_;
68 72
69 DISALLOW_COPY_AND_ASSIGN(BrowserShutdownProfileDumper); 73 DISALLOW_COPY_AND_ASSIGN(BrowserShutdownProfileDumper);
70 }; 74 };
71 75
72 } // namespace content 76 } // namespace content
73 77
74 #endif // CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_ 78 #endif // CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_
OLDNEW
« no previous file with comments | « content/browser/browser_main_runner.cc ('k') | content/browser/browser_shutdown_profile_dumper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698