| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 LOG(ERROR) << "URLRequestContext is not set up"; | 254 LOG(ERROR) << "URLRequestContext is not set up"; |
| 255 } | 255 } |
| 256 return context_.get(); | 256 return context_.get(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 scoped_refptr<base::SingleThreadTaskRunner> | 259 scoped_refptr<base::SingleThreadTaskRunner> |
| 260 URLRequestContextAdapter::GetNetworkTaskRunner() const { | 260 URLRequestContextAdapter::GetNetworkTaskRunner() const { |
| 261 return network_thread_->message_loop_proxy(); | 261 return network_thread_->message_loop_proxy(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void URLRequestContextAdapter::StartNetLogToFile(const std::string& file_name) { | 264 void URLRequestContextAdapter::StartNetLogToFile(const std::string& file_name, |
| 265 bool log_all) { |
| 265 PostTaskToNetworkThread( | 266 PostTaskToNetworkThread( |
| 266 FROM_HERE, | 267 FROM_HERE, |
| 267 base::Bind( | 268 base::Bind(&URLRequestContextAdapter::StartNetLogToFileHelper, this, |
| 268 &URLRequestContextAdapter::StartNetLogToFileHelper, this, file_name)); | 269 file_name, log_all)); |
| 269 } | 270 } |
| 270 | 271 |
| 271 void URLRequestContextAdapter::StopNetLog() { | 272 void URLRequestContextAdapter::StopNetLog() { |
| 272 PostTaskToNetworkThread( | 273 PostTaskToNetworkThread( |
| 273 FROM_HERE, base::Bind(&URLRequestContextAdapter::StopNetLogHelper, this)); | 274 FROM_HERE, base::Bind(&URLRequestContextAdapter::StopNetLogHelper, this)); |
| 274 } | 275 } |
| 275 | 276 |
| 276 void URLRequestContextAdapter::StartNetLogToFileHelper( | 277 void URLRequestContextAdapter::StartNetLogToFileHelper( |
| 277 const std::string& file_name) { | 278 const std::string& file_name, bool log_all) { |
| 278 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 279 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 279 // Do nothing if already logging to a file. | 280 // Do nothing if already logging to a file. |
| 280 if (net_log_logger_) | 281 if (net_log_logger_) |
| 281 return; | 282 return; |
| 282 | 283 |
| 283 base::FilePath file_path(file_name); | 284 base::FilePath file_path(file_name); |
| 284 base::ScopedFILE file(base::OpenFile(file_path, "w")); | 285 base::ScopedFILE file(base::OpenFile(file_path, "w")); |
| 285 if (!file) | 286 if (!file) |
| 286 return; | 287 return; |
| 287 | 288 |
| 288 net_log_logger_.reset(new net::NetLogLogger()); | 289 net_log_logger_.reset(new net::NetLogLogger()); |
| 290 if (log_all) |
| 291 net_log_logger_->set_log_level(net::NetLog::LogLevel::LOG_ALL); |
| 289 net_log_logger_->StartObserving(context_->net_log(), file.Pass(), nullptr, | 292 net_log_logger_->StartObserving(context_->net_log(), file.Pass(), nullptr, |
| 290 context_.get()); | 293 context_.get()); |
| 291 } | 294 } |
| 292 | 295 |
| 293 void URLRequestContextAdapter::StopNetLogHelper() { | 296 void URLRequestContextAdapter::StopNetLogHelper() { |
| 294 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 297 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 295 if (net_log_logger_) { | 298 if (net_log_logger_) { |
| 296 net_log_logger_->StopObserving(context_.get()); | 299 net_log_logger_->StopObserving(context_.get()); |
| 297 net_log_logger_.reset(); | 300 net_log_logger_.reset(); |
| 298 } | 301 } |
| 299 } | 302 } |
| 300 | 303 |
| 301 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 304 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
| 302 VLOG(2) << "Net log entry: type=" << entry.type() | 305 VLOG(2) << "Net log entry: type=" << entry.type() |
| 303 << ", source=" << entry.source().type << ", phase=" << entry.phase(); | 306 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
| 304 } | 307 } |
| 305 | 308 |
| 306 } // namespace cronet | 309 } // namespace cronet |
| OLD | NEW |