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

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

Issue 2973673003: Use FileNetLogObserver for implementing --log-net-log. (Closed)
Patch Set: address comments 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
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | components/net_log/chrome_net_log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
34 // * The methods on net::NetLog are threadsafe
35 // * The methods defined by ChromeNetLog must be sequenced.
32 class ChromeNetLog : public net::NetLog { 36 class ChromeNetLog : public net::NetLog {
33 public: 37 public:
34 ChromeNetLog(); 38 ChromeNetLog();
35 ~ChromeNetLog() override; 39 ~ChromeNetLog() override;
36 40
37 // Starts streaming the NetLog events to a file on disk. This will continue 41 // Starts streaming the NetLog events to a file on disk. This will continue
38 // until the application shuts down. 42 // until the application shuts down.
39 // * |log_file| - path to write the file. 43 // * |path| - destination file path of the log file.
40 // * |log_file_mode| - capture mode for event granularity. 44 // * |capture_mode| - capture mode for event granularity.
41 void StartWritingToFile( 45 void StartWritingToFile(
42 const base::FilePath& log_file, 46 const base::FilePath& path,
43 net::NetLogCaptureMode log_file_mode, 47 net::NetLogCaptureMode capture_mode,
44 const base::CommandLine::StringType& command_line_string, 48 const base::CommandLine::StringType& command_line_string,
45 const std::string& channel_string); 49 const std::string& channel_string);
46 50
47 NetExportFileWriter* net_export_file_writer(); 51 NetExportFileWriter* net_export_file_writer();
48 52
49 // Returns a Value containing constants needed to load a log file. 53 // Returns a Value containing constants needed to load a log file.
50 // Safe to call on any thread. 54 // Safe to call on any thread.
51 static std::unique_ptr<base::Value> GetConstants( 55 static std::unique_ptr<base::Value> GetConstants(
52 const base::CommandLine::StringType& command_line_string, 56 const base::CommandLine::StringType& command_line_string,
53 const std::string& channel_string); 57 const std::string& channel_string);
54 58
59 // Notify the ChromeNetLog that things are shutting-down.
60 //
61 // If ChromeNetLog does not outlive the TaskScheduler, there is no need to
62 // call this.
63 //
64 // However, if it can outlive the TaskScheduler, this should be called
65 // before the TaskScheduler is shutdown. This allows for any file writers
66 // using BLOCK_SHUTDOWN to finish posting their writes.
67 //
68 // Not calling this is not a fatal error, however may result in an incomplete
69 // NetLog file being written to disk.
70 void ShutDownBeforeTaskScheduler();
71
55 private: 72 private:
56 std::unique_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; 73 // Deletes file_net_log_observer_.
74 void ClearFileNetLogObserver();
75
76 // This observer handles writing NetLogs specified via StartWritingToFile()
77 // (In Chrome this corresponds to the --log-net-log command line).
78 std::unique_ptr<net::FileNetLogObserver> file_net_log_observer_;
79
80 // This observer handles writing NetLogs started by chrome://net-export/
57 std::unique_ptr<NetExportFileWriter> net_export_file_writer_; 81 std::unique_ptr<NetExportFileWriter> net_export_file_writer_;
82
83 // This observer forwards NetLog events to the chrome://tracing system.
58 std::unique_ptr<net::TraceNetLogObserver> trace_net_log_observer_; 84 std::unique_ptr<net::TraceNetLogObserver> trace_net_log_observer_;
59 85
60 DISALLOW_COPY_AND_ASSIGN(ChromeNetLog); 86 DISALLOW_COPY_AND_ASSIGN(ChromeNetLog);
61 }; 87 };
62 88
63 } // namespace net_log 89 } // namespace net_log
64 90
65 #endif // COMPONENTS_NET_LOG_CHROME_NET_LOG_H_ 91 #endif // COMPONENTS_NET_LOG_CHROME_NET_LOG_H_
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | components/net_log/chrome_net_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698