blob: 859811a6501433e3aaf3d6ac58783ca5758e9976 [file] [log] [blame]
[email protected]89af4002013-09-06 07:47:071// 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
avib7348942015-12-25 20:57:108#include <stddef.h>
9
[email protected]89af4002013-09-06 07:47:0710#include <string>
11
[email protected]cec95632014-07-02 18:01:5012#include "base/files/file_path.h"
avib7348942015-12-25 20:57:1013#include "base/macros.h"
[email protected]89af4002013-09-06 07:47:0714#include "base/memory/ref_counted.h"
15#include "base/memory/ref_counted_memory.h"
16#include "content/common/content_export.h"
17
18namespace base {
19class FilePath;
[email protected]f9be10532013-09-18 08:15:4620class WaitableEvent;
[email protected]89af4002013-09-06 07:47:0721}
22
23namespace 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.
33class BrowserShutdownProfileDumper {
34 public:
[email protected]cec95632014-07-02 18:01:5035 explicit BrowserShutdownProfileDumper(const base::FilePath& dump_file_name);
[email protected]89af4002013-09-06 07:47:0736
37 ~BrowserShutdownProfileDumper();
38
[email protected]cec95632014-07-02 18:01:5039 // Returns the file name where we should save the shutdown trace dump to.
40 static base::FilePath GetShutdownProfileFileName();
41
[email protected]89af4002013-09-06 07:47:0742 private:
43 // Writes all traces which happened to disk.
[email protected]cec95632014-07-02 18:01:5044 void WriteTracesToDisc();
[email protected]89af4002013-09-06 07:47:0745
[email protected]f9be10532013-09-18 08:15:4646 void EndTraceAndFlush(base::WaitableEvent* flush_complete_event);
47
[email protected]89af4002013-09-06 07:47:0748 // The callback for the |TraceLog::Flush| function. It saves all traces to
49 // disc.
50 void WriteTraceDataCollected(
[email protected]f9be10532013-09-18 08:15:4651 base::WaitableEvent* flush_complete_event,
[email protected]07b87732013-09-06 20:18:0552 const scoped_refptr<base::RefCountedString>& events_str,
53 bool has_more_events);
[email protected]89af4002013-09-06 07:47:0754
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]cec95632014-07-02 18:01:5067 // The name of the dump file.
68 const base::FilePath dump_file_name_;
69
[email protected]89af4002013-09-06 07:47:0770 // 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_