OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/cronet/android/url_request_context_adapter.h" | 5 #include "components/cronet/android/url_request_context_adapter.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 LOG(ERROR) << "URLRequestContext is not set up"; | 262 LOG(ERROR) << "URLRequestContext is not set up"; |
263 } | 263 } |
264 return context_.get(); | 264 return context_.get(); |
265 } | 265 } |
266 | 266 |
267 scoped_refptr<base::SingleThreadTaskRunner> | 267 scoped_refptr<base::SingleThreadTaskRunner> |
268 URLRequestContextAdapter::GetNetworkTaskRunner() const { | 268 URLRequestContextAdapter::GetNetworkTaskRunner() const { |
269 return network_thread_->message_loop_proxy(); | 269 return network_thread_->message_loop_proxy(); |
270 } | 270 } |
271 | 271 |
272 void URLRequestContextAdapter::StartNetLogToFile(const std::string& file_name) { | 272 void URLRequestContextAdapter::StartNetLogToFile(const std::string& file_name, |
| 273 bool log_all) { |
273 PostTaskToNetworkThread( | 274 PostTaskToNetworkThread( |
274 FROM_HERE, | 275 FROM_HERE, |
275 base::Bind( | 276 base::Bind(&URLRequestContextAdapter::StartNetLogToFileHelper, this, |
276 &URLRequestContextAdapter::StartNetLogToFileHelper, this, file_name)); | 277 file_name, log_all)); |
277 } | 278 } |
278 | 279 |
279 void URLRequestContextAdapter::StopNetLog() { | 280 void URLRequestContextAdapter::StopNetLog() { |
280 PostTaskToNetworkThread( | 281 PostTaskToNetworkThread( |
281 FROM_HERE, base::Bind(&URLRequestContextAdapter::StopNetLogHelper, this)); | 282 FROM_HERE, base::Bind(&URLRequestContextAdapter::StopNetLogHelper, this)); |
282 } | 283 } |
283 | 284 |
284 void URLRequestContextAdapter::StartNetLogToFileHelper( | 285 void URLRequestContextAdapter::StartNetLogToFileHelper( |
285 const std::string& file_name) { | 286 const std::string& file_name, bool log_all) { |
286 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 287 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
287 // Do nothing if already logging to a file. | 288 // Do nothing if already logging to a file. |
288 if (write_to_file_observer_) | 289 if (write_to_file_observer_) |
289 return; | 290 return; |
290 | 291 |
291 base::FilePath file_path(file_name); | 292 base::FilePath file_path(file_name); |
292 base::ScopedFILE file(base::OpenFile(file_path, "w")); | 293 base::ScopedFILE file(base::OpenFile(file_path, "w")); |
293 if (!file) | 294 if (!file) |
294 return; | 295 return; |
295 | 296 |
296 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); | 297 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); |
| 298 if (log_all) { |
| 299 write_to_file_observer_->set_capture_mode( |
| 300 net::NetLogCaptureMode::IncludeSocketBytes()); |
| 301 } |
297 write_to_file_observer_->StartObserving(context_->net_log(), file.Pass(), | 302 write_to_file_observer_->StartObserving(context_->net_log(), file.Pass(), |
298 nullptr, context_.get()); | 303 nullptr, context_.get()); |
299 } | 304 } |
300 | 305 |
301 void URLRequestContextAdapter::StopNetLogHelper() { | 306 void URLRequestContextAdapter::StopNetLogHelper() { |
302 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 307 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
303 if (write_to_file_observer_) { | 308 if (write_to_file_observer_) { |
304 write_to_file_observer_->StopObserving(context_.get()); | 309 write_to_file_observer_->StopObserving(context_.get()); |
305 write_to_file_observer_.reset(); | 310 write_to_file_observer_.reset(); |
306 } | 311 } |
307 } | 312 } |
308 | 313 |
309 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 314 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
310 VLOG(2) << "Net log entry: type=" << entry.type() | 315 VLOG(2) << "Net log entry: type=" << entry.type() |
311 << ", source=" << entry.source().type << ", phase=" << entry.phase(); | 316 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
312 } | 317 } |
313 | 318 |
314 } // namespace cronet | 319 } // namespace cronet |
OLD | NEW |