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/cronet_url_request_context_adapter.h" | 5 #include "components/cronet/android/cronet_url_request_context_adapter.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return GetNetworkTaskRunner()->BelongsToCurrentThread(); | 264 return GetNetworkTaskRunner()->BelongsToCurrentThread(); |
265 } | 265 } |
266 | 266 |
267 scoped_refptr<base::SingleThreadTaskRunner> | 267 scoped_refptr<base::SingleThreadTaskRunner> |
268 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const { | 268 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const { |
269 return network_thread_->task_runner(); | 269 return network_thread_->task_runner(); |
270 } | 270 } |
271 | 271 |
272 void CronetURLRequestContextAdapter::StartNetLogToFile(JNIEnv* env, | 272 void CronetURLRequestContextAdapter::StartNetLogToFile(JNIEnv* env, |
273 jobject jcaller, | 273 jobject jcaller, |
274 jstring jfile_name) { | 274 jstring jfile_name, |
| 275 jboolean jlog_all) { |
275 PostTaskToNetworkThread( | 276 PostTaskToNetworkThread( |
276 FROM_HERE, | 277 FROM_HERE, |
277 base::Bind( | 278 base::Bind( |
278 &CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread, | 279 &CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread, |
279 base::Unretained(this), | 280 base::Unretained(this), |
280 base::android::ConvertJavaStringToUTF8(env, jfile_name))); | 281 base::android::ConvertJavaStringToUTF8(env, jfile_name), jlog_all)); |
281 } | 282 } |
282 | 283 |
283 void CronetURLRequestContextAdapter::StopNetLog(JNIEnv* env, jobject jcaller) { | 284 void CronetURLRequestContextAdapter::StopNetLog(JNIEnv* env, jobject jcaller) { |
284 PostTaskToNetworkThread( | 285 PostTaskToNetworkThread( |
285 FROM_HERE, | 286 FROM_HERE, |
286 base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread, | 287 base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread, |
287 base::Unretained(this))); | 288 base::Unretained(this))); |
288 } | 289 } |
289 | 290 |
290 void CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread( | 291 void CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread( |
291 const std::string& file_name) { | 292 const std::string& file_name, bool log_all) { |
292 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 293 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
293 DCHECK(is_context_initialized_); | 294 DCHECK(is_context_initialized_); |
294 DCHECK(context_); | 295 DCHECK(context_); |
295 // Do nothing if already logging to a file. | 296 // Do nothing if already logging to a file. |
296 if (write_to_file_observer_) | 297 if (write_to_file_observer_) |
297 return; | 298 return; |
298 base::FilePath file_path(file_name); | 299 base::FilePath file_path(file_name); |
299 base::ScopedFILE file(base::OpenFile(file_path, "w")); | 300 base::ScopedFILE file(base::OpenFile(file_path, "w")); |
300 if (!file) | 301 if (!file) |
301 return; | 302 return; |
302 | 303 |
303 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); | 304 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); |
| 305 if (log_all) { |
| 306 write_to_file_observer_->set_capture_mode( |
| 307 net::NetLogCaptureMode::IncludeSocketBytes()); |
| 308 } |
304 write_to_file_observer_->StartObserving(context_->net_log(), file.Pass(), | 309 write_to_file_observer_->StartObserving(context_->net_log(), file.Pass(), |
305 nullptr, context_.get()); | 310 nullptr, context_.get()); |
306 } | 311 } |
307 | 312 |
308 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { | 313 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { |
309 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 314 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
310 if (write_to_file_observer_) { | 315 if (write_to_file_observer_) { |
311 write_to_file_observer_->StopObserving(context_.get()); | 316 write_to_file_observer_->StopObserving(context_.get()); |
312 write_to_file_observer_.reset(); | 317 write_to_file_observer_.reset(); |
313 } | 318 } |
(...skipping 17 matching lines...) Expand all Loading... |
331 } | 336 } |
332 | 337 |
333 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { | 338 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { |
334 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 339 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
335 // MinLogLevel is global, shared by all URLRequestContexts. | 340 // MinLogLevel is global, shared by all URLRequestContexts. |
336 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 341 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
337 return old_log_level; | 342 return old_log_level; |
338 } | 343 } |
339 | 344 |
340 } // namespace cronet | 345 } // namespace cronet |
OLD | NEW |