[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / browser_shutdown_profile_dumper.h
blobcc8666ef69daa5c825c36a3f4ba67fb65d0aa877
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/ref_counted_memory.h"
14 #include "content/common/content_export.h"
16 namespace base {
17 class FilePath;
18 class WaitableEvent;
21 namespace content {
23 // This class is intended to dump the tracing results of the shutdown process
24 // to a file before the browser process exits.
25 // It will save the file either into the command line passed
26 // "--trace-shutdown-file=<name>" parameter - or - to "chrometrace.log" in the
27 // current directory.
28 // Use the class with a scoped_ptr to get files written in the destructor.
29 // Note that we cannot use the asynchronous file writer since the
30 // |SequencedWorkerPool| will get killed in the shutdown process.
31 class BrowserShutdownProfileDumper {
32 public:
33 explicit BrowserShutdownProfileDumper(const base::FilePath& dump_file_name);
35 ~BrowserShutdownProfileDumper();
37 // Returns the file name where we should save the shutdown trace dump to.
38 static base::FilePath GetShutdownProfileFileName();
40 private:
41 // Writes all traces which happened to disk.
42 void WriteTracesToDisc();
44 void EndTraceAndFlush(base::WaitableEvent* flush_complete_event);
46 // The callback for the |TraceLog::Flush| function. It saves all traces to
47 // disc.
48 void WriteTraceDataCollected(
49 base::WaitableEvent* flush_complete_event,
50 const scoped_refptr<base::RefCountedString>& events_str,
51 bool has_more_events);
53 // Returns true if the dump file is valid.
54 bool IsFileValid();
56 // Writes a string to the dump file.
57 void WriteString(const std::string& string);
59 // Write a buffer to the dump file.
60 void WriteChars(const char* chars, size_t size);
62 // Closes the dump file.
63 void CloseFile();
65 // The name of the dump file.
66 const base::FilePath dump_file_name_;
68 // The number of blocks we have already written.
69 int blocks_;
70 // For dumping the content to disc.
71 FILE* dump_file_;
73 DISALLOW_COPY_AND_ASSIGN(BrowserShutdownProfileDumper);
76 } // namespace content
78 #endif // CONTENT_BROWSER_BROWSER_SHUTDOWN_PROFILE_DUMPER_H_