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

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: Forgot to update comment for StopNetLog() 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.
101 //
102 // |context_getters| is an optional list of URLRequestContextGetters used only
103 // to add log entries for ongoing events when logging starts. They are not
104 // used for retrieving polled data.
100 void StartNetLog(const base::FilePath& log_path, 105 void StartNetLog(const base::FilePath& log_path,
101 net::NetLogCaptureMode capture_mode); 106 net::NetLogCaptureMode capture_mode,
107 const URLRequestContextGetterList& context_getters);
102 108
103 // Stops collecting NetLog data into the file. It is a no-op if 109 // Stops collecting NetLog data into the file. It is a no-op if
104 // NetLogFileWriter is currently not logging. 110 // NetLogFileWriter is currently not logging.
105 // 111 //
106 // |polled_data| is a JSON dictionary that will be appended to the end of the 112 // |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. 113 // 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 114 // If |context_getter| is not null, then StopNetLog() will automatically
109 // append net info (from net::GetNetInfo() retrieved using |context_getter|) 115 // append net info (from net::GetNetInfo() retrieved using |context_getter|)
110 // to |polled_data|. 116 // to |polled_data|.
117 // Note that StopNetLog() accepts (optionally) only one context getter for
118 // retrieving net polled data as opposed to StartNetLog() which accepts zero
119 // or more context getters for retrieving ongoing net events.
111 void StopNetLog(std::unique_ptr<base::DictionaryValue> polled_data, 120 void StopNetLog(std::unique_ptr<base::DictionaryValue> polled_data,
112 scoped_refptr<net::URLRequestContextGetter> context_getter); 121 scoped_refptr<net::URLRequestContextGetter> context_getter);
113 122
114 // Creates a DictionaryValue summary of the state of the NetLogFileWriter 123 // Creates a DictionaryValue summary of the state of the NetLogFileWriter
115 std::unique_ptr<base::DictionaryValue> GetState() const; 124 std::unique_ptr<base::DictionaryValue> GetState() const;
116 125
117 // Gets the log filepath. |path_callback| will be used to notify the caller 126 // Gets the log filepath. |path_callback| will be used to notify the caller
118 // when the filepath is retrieved. |path_callback| will be executed with an 127 // when the filepath is retrieved. |path_callback| will be executed with an
119 // empty filepath if any of the following occurs: 128 // empty filepath if any of the following occurs:
120 // (1) The NetLogFileWriter is not initialized. 129 // (1) The NetLogFileWriter is not initialized.
(...skipping 26 matching lines...) Expand all
147 friend class ChromeNetLog; 156 friend class ChromeNetLog;
148 friend class NetLogFileWriterTest; 157 friend class NetLogFileWriterTest;
149 158
150 // The possible logging states of NetLogFileWriter. 159 // The possible logging states of NetLogFileWriter.
151 enum State { 160 enum State {
152 STATE_UNINITIALIZED, 161 STATE_UNINITIALIZED,
153 // Currently in the process of initializing. 162 // Currently in the process of initializing.
154 STATE_INITIALIZING, 163 STATE_INITIALIZING,
155 // Not currently logging to file. 164 // Not currently logging to file.
156 STATE_NOT_LOGGING, 165 STATE_NOT_LOGGING,
166 // Currently in the process of starting the log.
167 STATE_STARTING_LOG,
157 // Currently logging to file. 168 // Currently logging to file.
158 STATE_LOGGING, 169 STATE_LOGGING,
159 // Currently in the process of stopping the log. 170 // Currently in the process of stopping the log.
160 STATE_STOPPING_LOG, 171 STATE_STOPPING_LOG,
161 }; 172 };
162 173
163 void NotifyStateObservers(); 174 void NotifyStateObservers();
164 175
165 // Posts NotifyStateObservers() to the current thread. 176 // Posts NotifyStateObservers() to the current thread.
166 void NotifyStateObserversAsync(); 177 void NotifyStateObserversAsync();
167 178
168 // Called internally by Initialize(). Will initialize NetLogFileWriter's state 179 // Called internally by Initialize(). Will initialize NetLogFileWriter's state
169 // variables after the default log directory is set up and the default log 180 // variables after the default log directory is set up and the default log
170 // path is determined. 181 // path is determined on the |file_task_runner_|.
171 void SetStateAfterSetUpDefaultLogPath( 182 void SetStateAfterSetUpDefaultLogPath(
172 const DefaultLogPathResults& set_up_default_log_path_results); 183 const DefaultLogPathResults& set_up_default_log_path_results);
173 184
174 // Called internally by StopNetLog(). Does the actual work needed by 185 // Called internally by StartNetLog(). Contains tasks to be done to start
175 // StopNetLog() outside of retrieving the net info. 186 // logging after net log entries for ongoing events are added to the log from
187 // the |net_task_runner_|.
188 void StartNetLogAfterCreateEntriesForActiveObjects(
189 net::NetLogCaptureMode capture_mode);
190
191 // Called internally by StopNetLog(). Contains tasks to be done to stop
192 // logging after net-thread polled data is retrieved on the
193 // |net_task_runner_|.
176 void StopNetLogAfterAddNetInfo( 194 void StopNetLogAfterAddNetInfo(
177 std::unique_ptr<base::DictionaryValue> polled_data); 195 std::unique_ptr<base::DictionaryValue> polled_data);
178 196
179 // Contains tasks to be done after |file_net_log_observer_| has completely 197 // Contains tasks to be done after |file_net_log_observer_| has completely
180 // stopped writing. 198 // stopped writing.
181 void ResetObserverThenSetStateNotLogging(); 199 void ResetObserverThenSetStateNotLogging();
182 200
183 // All members are accessed solely from the main thread (the thread that 201 // All members are accessed solely from the main thread (the thread that
184 // |thread_checker_| is bound to). 202 // |thread_checker_| is bound to).
185 203
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 DirectoryGetter default_log_base_dir_getter_; 235 DirectoryGetter default_log_base_dir_getter_;
218 236
219 base::WeakPtrFactory<NetLogFileWriter> weak_ptr_factory_; 237 base::WeakPtrFactory<NetLogFileWriter> weak_ptr_factory_;
220 238
221 DISALLOW_COPY_AND_ASSIGN(NetLogFileWriter); 239 DISALLOW_COPY_AND_ASSIGN(NetLogFileWriter);
222 }; 240 };
223 241
224 } // namespace net_log 242 } // namespace net_log
225 243
226 #endif // COMPONENTS_NET_LOG_NET_LOG_FILE_WRITER_H_ 244 #endif // COMPONENTS_NET_LOG_NET_LOG_FILE_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698