Chromium Code Reviews| Index: ios/crnet/crnet_environment.mm |
| diff --git a/ios/crnet/crnet_environment.mm b/ios/crnet/crnet_environment.mm |
| index d216159005e32badc7ec32531358694e6ba0f0c1..96bfac0d311bd02afd2ec960e5815e7e5911ac6e 100644 |
| --- a/ios/crnet/crnet_environment.mm |
| +++ b/ios/crnet/crnet_environment.mm |
| @@ -8,6 +8,9 @@ |
| #include "base/at_exit.h" |
| #include "base/command_line.h" |
| +#include "base/files/file_path.h" |
| +#include "base/files/file_util.h" |
| +#include "base/files/scoped_file.h" |
| #include "base/i18n/icu_util.h" |
| #include "base/json/json_writer.h" |
| #include "base/mac/bind_objc_block.h" |
| @@ -15,6 +18,7 @@ |
| #include "base/mac/scoped_block.h" |
| #include "base/path_service.h" |
| #include "base/threading/worker_pool.h" |
| +#include "base/values.h" |
| #import "components/webp_transcode/webp_network_client_factory.h" |
| #include "crypto/nss_util.h" |
| #include "ios/net/cookies/cookie_store_ios.h" |
| @@ -32,6 +36,9 @@ |
| #include "net/http/http_server_properties_impl.h" |
| #include "net/http/http_stream_factory.h" |
| #include "net/http/http_util.h" |
| +#include "net/log/net_log.h" |
| +#include "net/log/net_log_util.h" |
| +#include "net/log/write_to_file_net_log_observer.h" |
| #include "net/proxy/proxy_service.h" |
| #include "net/socket/next_proto.h" |
| #include "net/ssl/channel_id_service.h" |
| @@ -154,11 +161,6 @@ void CrNetEnvironment::Initialize() { |
| void CrNetEnvironment::StartNetLog(base::FilePath::StringType file_name, |
| bool log_bytes) { |
| DCHECK(file_name.length()); |
| - base::AutoLock lock(net_log_lock_); |
| - if (net_log_started_) { |
| - return; |
| - } |
| - net_log_started_ = true; |
| PostToFileUserBlockingThread(FROM_HERE, |
| base::Bind(&CrNetEnvironment::StartNetLogInternal, |
| base::Unretained(this), file_name, log_bytes)); |
| @@ -169,21 +171,32 @@ void CrNetEnvironment::StartNetLogInternal( |
| DCHECK(base::MessageLoop::current() == |
| file_user_blocking_thread_->message_loop()); |
| DCHECK(file_name.length()); |
| - if (!net_log_.get()) { |
| - net_log_.reset(new CrNetNetLog()); |
| - main_context_.get()->set_net_log(net_log_.get()); |
| - } |
| - CrNetNetLog::Mode mode = log_bytes ? CrNetNetLog::LOG_ALL_BYTES : |
| - CrNetNetLog::LOG_STRIP_PRIVATE_DATA; |
| - net_log_->Start(base::FilePath(file_name), mode); |
| + DCHECK(net_log_.get()); |
|
mmenke
2015/06/05 18:56:49
nit: get not needed.
mef
2015/06/05 19:52:06
Done.
|
| + |
| + if (net_log_observer_.get()) |
|
mmenke
2015/06/05 18:56:49
nit: get not needed.
mef
2015/06/05 19:52:06
Done.
|
| + return; |
| + |
| + base::FilePath temp_dir; |
| + if (!base::GetTempDir(&temp_dir)) |
| + return; |
| + |
| + base::FilePath full_path = temp_dir.Append(file_name); |
| + base::ScopedFILE file(base::OpenFile(full_path, "w")); |
| + if (!file) |
| + return; |
| + |
| + scoped_ptr<base::Value> constants(net::GetNetConstants().Pass()); |
|
mmenke
2015/06/05 18:56:49
This isn't needed - can just pass in a null pointe
mef
2015/06/05 19:52:06
Done.
|
| + net::NetLogCaptureMode capture_mode = log_bytes ? |
| + net::NetLogCaptureMode::IncludeSocketBytes() : |
| + net::NetLogCaptureMode::Default(); |
| + |
| + net_log_observer_.reset(new net::WriteToFileNetLogObserver()); |
| + net_log_observer_->set_capture_mode(capture_mode); |
| + net_log_observer_->StartObserving(net_log_.get(), file.Pass(), |
| + constants.get(), nullptr); |
| } |
| void CrNetEnvironment::StopNetLog() { |
| - base::AutoLock lock(net_log_lock_); |
| - if (!net_log_started_) { |
| - return; |
| - } |
| - net_log_started_ = false; |
| PostToFileUserBlockingThread(FROM_HERE, |
| base::Bind(&CrNetEnvironment::StopNetLogInternal, |
| base::Unretained(this))); |
| @@ -192,8 +205,9 @@ void CrNetEnvironment::StopNetLog() { |
| void CrNetEnvironment::StopNetLogInternal() { |
| DCHECK(base::MessageLoop::current() == |
| file_user_blocking_thread_->message_loop()); |
| - if (net_log_.get()) { |
| - net_log_->Stop(); |
| + if (net_log_observer_.get()) { |
| + net_log_observer_->StopObserving(nullptr); |
| + net_log_observer_.reset(); |
| } |
| } |
| @@ -270,7 +284,6 @@ void CrNetEnvironment::Install() { |
| main_context_getter_ = new CrNetURLRequestContextGetter( |
| main_context_.get(), network_io_thread_->message_loop_proxy()); |
| SetRequestFilterBlock(nil); |
| - net_log_started_ = false; |
| } |
| void CrNetEnvironment::InstallIntoSessionConfiguration( |
| @@ -423,6 +436,9 @@ void CrNetEnvironment::InitializeOnNetworkThread() { |
| job_factory->SetProtocolHandler( |
| "file", new net::FileProtocolHandler(file_thread_->message_loop_proxy())); |
| main_context_->set_job_factory(job_factory); |
| + |
| + net_log_.reset(new net::NetLog()); |
| + main_context_->set_net_log(net_log_.get()); |
| } |
| std::string CrNetEnvironment::user_agent() { |