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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 DCHECK(!base::MessageLoop::current()); | 139 DCHECK(!base::MessageLoop::current()); |
| 140 DCHECK(!g_main_message_loop); | 140 DCHECK(!g_main_message_loop); |
| 141 g_main_message_loop = new base::MessageLoopForUI(); | 141 g_main_message_loop = new base::MessageLoopForUI(); |
| 142 base::MessageLoopForUI::current()->Attach(); | 142 base::MessageLoopForUI::current()->Attach(); |
| 143 // The network change notifier must be initialized so that registered | 143 // The network change notifier must be initialized so that registered |
| 144 // delegates will receive callbacks. | 144 // delegates will receive callbacks. |
| 145 DCHECK(!g_network_change_notifier); | 145 DCHECK(!g_network_change_notifier); |
| 146 g_network_change_notifier = net::NetworkChangeNotifier::Create(); | 146 g_network_change_notifier = net::NetworkChangeNotifier::Create(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void CronetEnvironment::StartNetLog(base::FilePath::StringType file_name, | 149 bool CronetEnvironment::StartNetLog(base::FilePath::StringType file_name, |
| 150 bool log_bytes) { | 150 bool log_bytes) { |
| 151 DCHECK(file_name.length()); | 151 if (!file_name.length()) |
| 152 PostToNetworkThread(FROM_HERE, | 152 return false; |
| 153 base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread, | 153 |
| 154 base::Unretained(this), file_name, log_bytes)); | 154 base::FilePath full_path(file_name); |
| 155 | |
| 156 if (!full_path.IsAbsolute()) { | |
| 157 if (!PathService::Get(base::DIR_HOME, &full_path)) | |
|
kapishnikov
2016/11/10 20:52:17
What is the value of base::DIR_HOME on iOS? Can ap
lilyhoughton
2016/11/16 16:04:10
iOS apps definitely can't write to it, per bug 616
| |
| 158 return false; | |
| 159 | |
| 160 full_path = full_path.Append(file_name); | |
| 161 } | |
| 162 | |
| 163 base::ScopedFILE file(base::OpenFile(full_path, "w")); | |
| 164 if (!file) { | |
| 165 LOG(ERROR) << "Can not start NetLog to " << full_path.value(); | |
| 166 return false; | |
| 167 } | |
| 168 | |
| 169 LOG(WARNING) << "Starting NetLog to " << full_path.value(); | |
| 170 PostToNetworkThread( | |
| 171 FROM_HERE, | |
| 172 base::Bind(&CronetEnvironment::StartNetLogOnNetworkThread, | |
| 173 base::Unretained(this), base::Passed(&file), log_bytes)); | |
|
kapishnikov
2016/11/10 20:52:17
Why do we need base::Passes here?
lilyhoughton
2016/11/16 16:04:10
Because `base::Bind` will not accept an undecorate
| |
| 174 | |
| 175 return true; | |
| 155 } | 176 } |
| 156 | 177 |
| 157 void CronetEnvironment::StartNetLogOnNetworkThread( | 178 void CronetEnvironment::StartNetLogOnNetworkThread(base::ScopedFILE file, |
| 158 const base::FilePath::StringType& file_name, | 179 bool log_bytes) { |
| 159 bool log_bytes) { | |
| 160 DCHECK(file_name.length()); | |
| 161 DCHECK(net_log_); | 180 DCHECK(net_log_); |
| 162 | 181 |
| 163 if (net_log_observer_) | 182 if (net_log_observer_) |
| 164 return; | 183 return; |
| 165 | 184 |
| 166 base::FilePath files_root; | |
| 167 if (!PathService::Get(base::DIR_HOME, &files_root)) | |
| 168 return; | |
| 169 | |
| 170 base::FilePath full_path = files_root.Append(file_name); | |
| 171 base::ScopedFILE file(base::OpenFile(full_path, "w")); | |
| 172 if (!file) { | |
| 173 LOG(ERROR) << "Can not start NetLog to " << full_path.value(); | |
| 174 return; | |
| 175 } | |
| 176 | |
| 177 net::NetLogCaptureMode capture_mode = | 185 net::NetLogCaptureMode capture_mode = |
| 178 log_bytes ? net::NetLogCaptureMode::IncludeSocketBytes() | 186 log_bytes ? net::NetLogCaptureMode::IncludeSocketBytes() |
| 179 : net::NetLogCaptureMode::Default(); | 187 : net::NetLogCaptureMode::Default(); |
| 180 | 188 |
| 181 net_log_observer_.reset(new net::WriteToFileNetLogObserver()); | 189 net_log_observer_.reset(new net::WriteToFileNetLogObserver()); |
| 182 net_log_observer_->set_capture_mode(capture_mode); | 190 net_log_observer_->set_capture_mode(capture_mode); |
| 183 net_log_observer_->StartObserving(main_context_->net_log(), std::move(file), | 191 net_log_observer_->StartObserving(main_context_->net_log(), std::move(file), |
| 184 nullptr, main_context_.get()); | 192 nullptr, main_context_.get()); |
| 185 LOG(WARNING) << "Started NetLog to " << full_path.value(); | 193 |
| 194 LOG(WARNING) << "Started NetLog"; | |
|
kapishnikov
2016/11/10 20:52:17
We already logging a message in StartNetLog(). I t
lilyhoughton
2016/11/16 16:04:10
I wanted to include both whether or not `startNetL
kapishnikov
2016/11/18 22:17:27
If StartNetLogOnNetworkThread is called, this line
| |
| 186 } | 195 } |
| 187 | 196 |
| 188 void CronetEnvironment::StopNetLog() { | 197 void CronetEnvironment::StopNetLog() { |
| 189 base::WaitableEvent log_stopped_event( | 198 base::WaitableEvent log_stopped_event( |
| 190 base::WaitableEvent::ResetPolicy::MANUAL, | 199 base::WaitableEvent::ResetPolicy::MANUAL, |
| 191 base::WaitableEvent::InitialState::NOT_SIGNALED); | 200 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 192 PostToNetworkThread(FROM_HERE, | 201 PostToNetworkThread(FROM_HERE, |
| 193 base::Bind(&CronetEnvironment::StopNetLogOnNetworkThread, | 202 base::Bind(&CronetEnvironment::StopNetLogOnNetworkThread, |
| 194 base::Unretained(this), &log_stopped_event)); | 203 base::Unretained(this), &log_stopped_event)); |
| 195 log_stopped_event.Wait(); | 204 log_stopped_event.Wait(); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 | 403 |
| 395 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { | 404 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { |
| 396 base::StatisticsRecorder::Initialize(); | 405 base::StatisticsRecorder::Initialize(); |
| 397 std::vector<uint8_t> data; | 406 std::vector<uint8_t> data; |
| 398 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 407 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 399 return std::vector<uint8_t>(); | 408 return std::vector<uint8_t>(); |
| 400 return data; | 409 return data; |
| 401 } | 410 } |
| 402 | 411 |
| 403 } // namespace cronet | 412 } // namespace cronet |
| OLD | NEW |