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

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

Issue 2698143004: Add ongoing events to net-export log when logging starts (Closed)
Patch Set: Added/improved some comments Created 3 years, 10 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 COMPONENTS_NET_LOG_NET_LOG_FILE_WRITER_H_ 5 #ifndef COMPONENTS_NET_LOG_NET_LOG_FILE_WRITER_H_
6 #define COMPONENTS_NET_LOG_NET_LOG_FILE_WRITER_H_ 6 #define COMPONENTS_NET_LOG_NET_LOG_FILE_WRITER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 // Struct used to store the results of setting up the default log directory 65 // Struct used to store the results of setting up the default log directory
66 // and log path. 66 // and log path.
67 struct DefaultLogPathResults { 67 struct DefaultLogPathResults {
68 bool default_log_path_success; 68 bool default_log_path_success;
69 base::FilePath default_log_path; 69 base::FilePath default_log_path;
70 bool log_exists; 70 bool log_exists;
71 }; 71 };
72 72
73 using FilePathCallback = base::Callback<void(const base::FilePath&)>; 73 using FilePathCallback = base::Callback<void(const base::FilePath&)>;
74
75 using DirectoryGetter = base::Callback<bool(base::FilePath*)>; 74 using DirectoryGetter = base::Callback<bool(base::FilePath*)>;
75 using URLRequestContextGetterList =
76 std::vector<scoped_refptr<net::URLRequestContextGetter>>;
76 77
77 ~NetLogFileWriter(); 78 ~NetLogFileWriter();
78 79
79 // Attaches a StateObserver. |observer| will be notified of state changes to 80 // Attaches a StateObserver. |observer| will be notified of state changes to
80 // NetLogFileWriter. State changes may occur in response to Initiailze(), 81 // NetLogFileWriter. State changes may occur in response to Initiailze(),
81 // StartNetLog(), or StopNetLog(). StateObserver::OnNewState() will be called 82 // StartNetLog(), or StopNetLog(). StateObserver::OnNewState() will be called
82 // asynchronously relative to the command that caused the state change. 83 // asynchronously relative to the command that caused the state change.
83 // |observer| must remain alive until RemoveObserver() is called. 84 // |observer| must remain alive until RemoveObserver() is called.
84 void AddObserver(StateObserver* observer); 85 void AddObserver(StateObserver* observer);
85 86
86 // Detaches a StateObserver. 87 // Detaches a StateObserver.
87 void RemoveObserver(StateObserver* observer); 88 void RemoveObserver(StateObserver* observer);
88 89
89 // Initializes NetLogFileWriter if not initialized. 90 // Initializes NetLogFileWriter if not initialized.
90 // 91 //
91 // Also sets the task runners used by NetLogFileWriter for doing file I/O and 92 // Also sets the task runners used by NetLogFileWriter for doing file I/O and
92 // network I/O respectively. The task runners must not be changed once set. 93 // network I/O respectively. The task runners must not be changed once set.
93 // However, calling this function again with the same parameters is OK. 94 // However, calling this function again with the same parameters is OK.
94 void Initialize(scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, 95 void Initialize(scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
95 scoped_refptr<base::SingleThreadTaskRunner> net_task_runner); 96 scoped_refptr<base::SingleThreadTaskRunner> net_task_runner);
96 97
97 // Starts collecting NetLog data into the file at |log_path|. If |log_path| is 98 // Starts collecting NetLog data into the file at |log_path|. If |log_path| is
98 // empty, the default log path is used. If NetLogFileWriter is already 99 // empty, the default log path is used. If NetLogFileWriter is already
99 // logging, this is a no-op and |capture_mode| is ignored. 100 // logging, this is a no-op and |capture_mode| is ignored.
100 void StartNetLog(const base::FilePath& log_path, 101 void StartNetLog(const base::FilePath& log_path,
101 net::NetLogCaptureMode capture_mode); 102 net::NetLogCaptureMode capture_mode,
103 const URLRequestContextGetterList& context_getters);
eroman 2017/02/21 22:14:23 Please update the comments to mention what this do
102 104
103 // Stops collecting NetLog data into the file. It is a no-op if 105 // Stops collecting NetLog data into the file. It is a no-op if
104 // NetLogFileWriter is currently not logging. 106 // NetLogFileWriter is currently not logging.
105 // 107 //
106 // |polled_data| is a JSON dictionary that will be appended to the end of the 108 // |polled_data| is a JSON dictionary that will be appended to the end of the
107 // log; it's for adding additional info to the log that aren't events. 109 // log; it's for adding additional info to the log that aren't events.
108 // If |context_getter| is not null, then StopNetLog() will automatically 110 // If |context_getter| is not null, then StopNetLog() will automatically
109 // append net info (from net::GetNetInfo() retrieved using |context_getter|) 111 // append net info (from net::GetNetInfo() retrieved using |context_getter|)
110 // to |polled_data|. 112 // to |polled_data|.
111 void StopNetLog(std::unique_ptr<base::DictionaryValue> polled_data, 113 void StopNetLog(std::unique_ptr<base::DictionaryValue> polled_data,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 friend class ChromeNetLog; 149 friend class ChromeNetLog;
148 friend class NetLogFileWriterTest; 150 friend class NetLogFileWriterTest;
149 151
150 // The possible logging states of NetLogFileWriter. 152 // The possible logging states of NetLogFileWriter.
151 enum State { 153 enum State {
152 STATE_UNINITIALIZED, 154 STATE_UNINITIALIZED,
153 // Currently in the process of initializing. 155 // Currently in the process of initializing.
154 STATE_INITIALIZING, 156 STATE_INITIALIZING,
155 // Not currently logging to file. 157 // Not currently logging to file.
156 STATE_NOT_LOGGING, 158 STATE_NOT_LOGGING,
159 // Currently in the process of starting the log.
160 STATE_STARTING_LOG,
157 // Currently logging to file. 161 // Currently logging to file.
158 STATE_LOGGING, 162 STATE_LOGGING,
159 // Currently in the process of stopping the log. 163 // Currently in the process of stopping the log.
160 STATE_STOPPING_LOG, 164 STATE_STOPPING_LOG,
161 }; 165 };
162 166
163 void NotifyStateObservers(); 167 void NotifyStateObservers();
164 168
165 // Posts NotifyStateObservers() to the current thread. 169 // Posts NotifyStateObservers() to the current thread.
166 void NotifyStateObserversAsync(); 170 void NotifyStateObserversAsync();
167 171
168 // Called internally by Initialize(). Will initialize NetLogFileWriter's state 172 // Called internally by Initialize(). Will initialize NetLogFileWriter's state
169 // variables after the default log directory is set up and the default log 173 // variables after the default log directory is set up and the default log
170 // path is determined. 174 // path is determined on the |file_task_runner_|.
171 void SetStateAfterSetUpDefaultLogPath( 175 void SetStateAfterSetUpDefaultLogPath(
172 const DefaultLogPathResults& set_up_default_log_path_results); 176 const DefaultLogPathResults& set_up_default_log_path_results);
173 177
174 // Called internally by StopNetLog(). Does the actual work needed by 178 // Called internally by StartNetLog(). Contains tasks to be done to start
175 // StopNetLog() outside of retrieving the net info. 179 // logging after net log entries for ongoing events are added to the log from
180 // the |net_task_runner_|.
181 void StartNetLogAfterCreateEntriesForActiveObjects(
182 net::NetLogCaptureMode capture_mode);
183
184 // Called internally by StopNetLog(). Contains tasks to be done to stop
185 // logging after net-thread polled data is retrieved on the
186 // |net_task_runner_|.
176 void StopNetLogAfterAddNetInfo( 187 void StopNetLogAfterAddNetInfo(
177 std::unique_ptr<base::DictionaryValue> polled_data); 188 std::unique_ptr<base::DictionaryValue> polled_data);
178 189
179 // Contains tasks to be done after |file_net_log_observer_| has completely 190 // Contains tasks to be done after |file_net_log_observer_| has completely
180 // stopped writing. 191 // stopped writing.
181 void ResetObserverThenSetStateNotLogging(); 192 void ResetObserverThenSetStateNotLogging();
182 193
183 // All members are accessed solely from the main thread (the thread that 194 // All members are accessed solely from the main thread (the thread that
184 // |thread_checker_| is bound to). 195 // |thread_checker_| is bound to).
185 196
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 DirectoryGetter default_log_base_dir_getter_; 228 DirectoryGetter default_log_base_dir_getter_;
218 229
219 base::WeakPtrFactory<NetLogFileWriter> weak_ptr_factory_; 230 base::WeakPtrFactory<NetLogFileWriter> weak_ptr_factory_;
220 231
221 DISALLOW_COPY_AND_ASSIGN(NetLogFileWriter); 232 DISALLOW_COPY_AND_ASSIGN(NetLogFileWriter);
222 }; 233 };
223 234
224 } // namespace net_log 235 } // namespace net_log
225 236
226 #endif // COMPONENTS_NET_LOG_NET_LOG_FILE_WRITER_H_ 237 #endif // COMPONENTS_NET_LOG_NET_LOG_FILE_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698