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

Side by Side Diff: components/net_log/chrome_net_log.h

Issue 2973673003: Use FileNetLogObserver for implementing --log-net-log. (Closed)
Patch Set: check for null Created 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 COMPONENTS_NET_LOG_CHROME_NET_LOG_H_ 5 #ifndef COMPONENTS_NET_LOG_CHROME_NET_LOG_H_
6 #define COMPONENTS_NET_LOG_CHROME_NET_LOG_H_ 6 #define COMPONENTS_NET_LOG_CHROME_NET_LOG_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "net/log/net_log.h" 13 #include "net/log/net_log.h"
14 14
15 namespace base { 15 namespace base {
16 class FilePath; 16 class FilePath;
17 class Value; 17 class Value;
18 } 18 }
19 19
20 namespace net { 20 namespace net {
21 class WriteToFileNetLogObserver; 21 class FileNetLogObserver;
22 class TraceNetLogObserver; 22 class TraceNetLogObserver;
23 } 23 }
24 24
25 namespace net_log { 25 namespace net_log {
26 26
27 class NetExportFileWriter; 27 class NetExportFileWriter;
28 28
29 // ChromeNetLog is an implementation of NetLog that manages common observers 29 // ChromeNetLog is an implementation of NetLog that manages common observers
30 // (for --log-net-log, chrome://net-export/, tracing), as well as acting as the 30 // (for --log-net-log, chrome://net-export/, tracing), as well as acting as the
31 // entry point for other consumers. 31 // entry point for other consumers.
32 //
33 // Threading: the underlying net::NetLog is threadsafe. Whereas the methods
34 // added by ChromeNetLog must be sequenced.
mmenke 2017/07/06 21:31:29 Remove Whereas? At least I can't recall seeing us
eroman 2017/07/06 21:57:54 Done.
32 class ChromeNetLog : public net::NetLog { 35 class ChromeNetLog : public net::NetLog {
33 public: 36 public:
34 ChromeNetLog(); 37 ChromeNetLog();
35 ~ChromeNetLog() override; 38 ~ChromeNetLog() override;
36 39
37 // Starts streaming the NetLog events to a file on disk. This will continue 40 // Starts streaming the NetLog events to a file on disk. This will continue
38 // until the application shuts down. 41 // until the application shuts down.
39 // * |log_file| - path to write the file. 42 // * |path| - destination file path of the log file.
40 // * |log_file_mode| - capture mode for event granularity. 43 // * |capture_mode| - capture mode for event granularity.
41 void StartWritingToFile( 44 void StartWritingToFile(
42 const base::FilePath& log_file, 45 const base::FilePath& path,
43 net::NetLogCaptureMode log_file_mode, 46 net::NetLogCaptureMode capture_mode,
44 const base::CommandLine::StringType& command_line_string, 47 const base::CommandLine::StringType& command_line_string,
45 const std::string& channel_string); 48 const std::string& channel_string);
46 49
47 NetExportFileWriter* net_export_file_writer(); 50 NetExportFileWriter* net_export_file_writer();
48 51
49 // Returns a Value containing constants needed to load a log file. 52 // Returns a Value containing constants needed to load a log file.
50 // Safe to call on any thread. 53 // Safe to call on any thread.
51 static std::unique_ptr<base::Value> GetConstants( 54 static std::unique_ptr<base::Value> GetConstants(
52 const base::CommandLine::StringType& command_line_string, 55 const base::CommandLine::StringType& command_line_string,
53 const std::string& channel_string); 56 const std::string& channel_string);
54 57
58 // Notify the ChromeNetLog that things are shutting-down.
59 //
60 // If ChromeNetLog does not outlive the TaskScheduler, there is no need to
61 // call this.
62 //
63 // However, if it can outlive the TaskScheduler, this should be called
64 // before the TaskScheduler is shutdown. This allows for any file writers
65 // using the BLOCK_SHUTDOWN to finish posting their writes.
mmenke 2017/07/06 21:31:29 -the
eroman 2017/07/06 21:57:54 Done.
66 //
67 // Not calling this is not a fatal error, however may result in an incomplete
68 // NetLog file being written to disk.
69 void ShutdownBeforeTaskScheduler();
70
55 private: 71 private:
56 std::unique_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; 72 // Deletes file_net_log_observer_.
73 void ClearFileNetLogObserver();
74
75 // This observer handles writing NetLogs specified via StartWritingToFile()
76 // (In Chrome this corresponds to the --log-net-log command line).
77 std::unique_ptr<net::FileNetLogObserver> file_net_log_observer_;
mmenke 2017/07/06 21:31:29 I hadn't realized we had three different file writ
eroman 2017/07/06 21:57:54 There are 3 observers here, but technically only 2
mmenke 2017/07/06 22:03:48 I was counting NetExportFileWriter, actually. Had
78
79 // This observer handles writing NetLogs started by chrome://net-export/
57 std::unique_ptr<NetExportFileWriter> net_export_file_writer_; 80 std::unique_ptr<NetExportFileWriter> net_export_file_writer_;
81
82 // This observer forwards NetLog events to the chrome://tracing system.
58 std::unique_ptr<net::TraceNetLogObserver> trace_net_log_observer_; 83 std::unique_ptr<net::TraceNetLogObserver> trace_net_log_observer_;
59 84
60 DISALLOW_COPY_AND_ASSIGN(ChromeNetLog); 85 DISALLOW_COPY_AND_ASSIGN(ChromeNetLog);
61 }; 86 };
62 87
63 } // namespace net_log 88 } // namespace net_log
64 89
65 #endif // COMPONENTS_NET_LOG_CHROME_NET_LOG_H_ 90 #endif // COMPONENTS_NET_LOG_CHROME_NET_LOG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698