Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ios/cronet_environment.h" | 5 #include "components/cronet/ios/cronet_environment.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 DCHECK(!base::MessageLoop::current()); | 137 DCHECK(!base::MessageLoop::current()); |
| 138 DCHECK(!g_main_message_loop); | 138 DCHECK(!g_main_message_loop); |
| 139 g_main_message_loop = new base::MessageLoopForUI(); | 139 g_main_message_loop = new base::MessageLoopForUI(); |
| 140 base::MessageLoopForUI::current()->Attach(); | 140 base::MessageLoopForUI::current()->Attach(); |
| 141 // The network change notifier must be initialized so that registered | 141 // The network change notifier must be initialized so that registered |
| 142 // delegates will receive callbacks. | 142 // delegates will receive callbacks. |
| 143 DCHECK(!g_network_change_notifier); | 143 DCHECK(!g_network_change_notifier); |
| 144 g_network_change_notifier = net::NetworkChangeNotifier::Create(); | 144 g_network_change_notifier = net::NetworkChangeNotifier::Create(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void CronetEnvironment::StartNetLog(base::FilePath::StringType file_name, | 147 bool CronetEnvironment::StartNetLog(base::FilePath::StringType file_name, |
| 148 bool log_bytes) { | 148 bool log_bytes) { |
| 149 DCHECK(file_name.length()); | 149 if (!file_name.length()) |
| 150 PostToNetworkThread(FROM_HERE, | 150 return false; |
| 151 base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread, | 151 |
| 152 base::Unretained(this), file_name, log_bytes)); | 152 base::FilePath full_path(file_name); |
| 153 | |
| 154 if (!full_path.IsAbsolute()) { | |
|
mef
2016/12/09 18:30:41
This seems redundant now that we get absolute path
lilyhoughton
2016/12/09 19:42:50
The only reason I left it was because I wasn't sur
| |
| 155 if (!PathService::Get(base::DIR_HOME, &full_path)) | |
| 156 return false; | |
| 157 | |
| 158 full_path = full_path.Append(file_name); | |
| 159 } | |
| 160 | |
| 161 base::ScopedFILE file(base::OpenFile(full_path, "w")); | |
| 162 if (!file) { | |
| 163 LOG(ERROR) << "Can not start NetLog to " << full_path.value() << ": " | |
| 164 << strerror(errno); | |
| 165 return false; | |
| 166 } | |
| 167 | |
| 168 LOG(WARNING) << "Starting NetLog to " << full_path.value(); | |
| 169 PostToNetworkThread( | |
| 170 FROM_HERE, | |
| 171 base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread, | |
| 172 base::Unretained(this), base::Passed(&file), log_bytes)); | |
| 173 | |
| 174 return true; | |
| 153 } | 175 } |
| 154 | 176 |
| 155 void CronetEnvironment::StartNetLogOnNetworkThread( | 177 void CronetEnvironment::StartNetLogOnNetworkThread(base::ScopedFILE file, |
| 156 const base::FilePath::StringType& file_name, | 178 bool log_bytes) { |
| 157 bool log_bytes) { | |
| 158 DCHECK(file_name.length()); | |
| 159 DCHECK(net_log_); | 179 DCHECK(net_log_); |
| 160 | 180 |
| 161 if (net_log_observer_) | 181 if (net_log_observer_) |
| 162 return; | 182 return; |
| 163 | 183 |
| 164 base::FilePath files_root; | |
| 165 if (!PathService::Get(base::DIR_HOME, &files_root)) | |
| 166 return; | |
| 167 | |
| 168 base::FilePath full_path = files_root.Append(file_name); | |
| 169 base::ScopedFILE file(base::OpenFile(full_path, "w")); | |
| 170 if (!file) { | |
| 171 LOG(ERROR) << "Can not start NetLog to " << full_path.value(); | |
| 172 return; | |
| 173 } | |
| 174 | |
| 175 net::NetLogCaptureMode capture_mode = | 184 net::NetLogCaptureMode capture_mode = |
| 176 log_bytes ? net::NetLogCaptureMode::IncludeSocketBytes() | 185 log_bytes ? net::NetLogCaptureMode::IncludeSocketBytes() |
| 177 : net::NetLogCaptureMode::Default(); | 186 : net::NetLogCaptureMode::Default(); |
| 178 | 187 |
| 179 net_log_observer_.reset(new net::WriteToFileNetLogObserver()); | 188 net_log_observer_.reset(new net::WriteToFileNetLogObserver()); |
| 180 net_log_observer_->set_capture_mode(capture_mode); | 189 net_log_observer_->set_capture_mode(capture_mode); |
| 181 net_log_observer_->StartObserving(main_context_->net_log(), std::move(file), | 190 net_log_observer_->StartObserving(main_context_->net_log(), std::move(file), |
| 182 nullptr, main_context_.get()); | 191 nullptr, main_context_.get()); |
| 183 LOG(WARNING) << "Started NetLog to " << full_path.value(); | 192 |
|
mef
2016/12/09 18:30:40
nit: spurious nl
lilyhoughton
2016/12/09 19:42:50
Done.
| |
| 193 LOG(WARNING) << "Started NetLog"; | |
| 184 } | 194 } |
| 185 | 195 |
| 186 void CronetEnvironment::StopNetLog() { | 196 void CronetEnvironment::StopNetLog() { |
| 187 base::WaitableEvent log_stopped_event( | 197 base::WaitableEvent log_stopped_event( |
| 188 base::WaitableEvent::ResetPolicy::MANUAL, | 198 base::WaitableEvent::ResetPolicy::MANUAL, |
| 189 base::WaitableEvent::InitialState::NOT_SIGNALED); | 199 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 190 PostToNetworkThread(FROM_HERE, | 200 PostToNetworkThread(FROM_HERE, |
| 191 base::Bind(&CronetEnvironment::StopNetLogOnNetworkThread, | 201 base::Bind(&CronetEnvironment::StopNetLogOnNetworkThread, |
| 192 base::Unretained(this), &log_stopped_event)); | 202 base::Unretained(this), &log_stopped_event)); |
| 193 log_stopped_event.Wait(); | 203 log_stopped_event.Wait(); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 | 423 |
| 414 void CronetEnvironment::SetHostResolverRulesOnNetworkThread( | 424 void CronetEnvironment::SetHostResolverRulesOnNetworkThread( |
| 415 const std::string& rules, | 425 const std::string& rules, |
| 416 base::WaitableEvent* event) { | 426 base::WaitableEvent* event) { |
| 417 static_cast<net::MappedHostResolver*>(main_context_->host_resolver()) | 427 static_cast<net::MappedHostResolver*>(main_context_->host_resolver()) |
| 418 ->SetRulesFromString(rules); | 428 ->SetRulesFromString(rules); |
| 419 event->Signal(); | 429 event->Signal(); |
| 420 } | 430 } |
| 421 | 431 |
| 422 } // namespace cronet | 432 } // namespace cronet |
| OLD | NEW |