Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 976483002: Add ability for NetLogLogger to gather data from more than just NetLog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/files/scoped_file.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "components/cronet/url_request_context_config.h" 15 #include "components/cronet/url_request_context_config.h"
15 #include "jni/CronetUrlRequestContext_jni.h" 16 #include "jni/CronetUrlRequestContext_jni.h"
16 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
17 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
18 #include "net/base/net_log_logger.h" 19 #include "net/base/net_log_logger.h"
19 #include "net/base/network_delegate_impl.h" 20 #include "net/base/network_delegate_impl.h"
20 #include "net/http/http_auth_handler_factory.h" 21 #include "net/http/http_auth_handler_factory.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread, 279 base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread,
279 base::Unretained(this))); 280 base::Unretained(this)));
280 } 281 }
281 282
282 void CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread( 283 void CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread(
283 const std::string& file_name) { 284 const std::string& file_name) {
284 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 285 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
285 // Do nothing if already logging to a file. 286 // Do nothing if already logging to a file.
286 if (net_log_logger_) 287 if (net_log_logger_)
287 return; 288 return;
288
289 base::FilePath file_path(file_name); 289 base::FilePath file_path(file_name);
290 FILE* file = base::OpenFile(file_path, "w"); 290 base::ScopedFILE file(base::OpenFile(file_path, "w"));
291 if (!file) 291 if (!file)
292 return; 292 return;
293 293
294 scoped_ptr<base::Value> constants(net::NetLogLogger::GetConstants()); 294 net_log_logger_.reset(new net::NetLogLogger());
295 net_log_logger_.reset(new net::NetLogLogger(file, *constants)); 295 net_log_logger_->StartObserving(context_->net_log(), file.Pass(), nullptr,
296 net_log_logger_->StartObserving(context_->net_log()); 296 context_.get());
297 } 297 }
298 298
299 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { 299 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() {
300 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 300 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
301 if (net_log_logger_) { 301 if (net_log_logger_) {
302 net_log_logger_->StopObserving(); 302 net_log_logger_->StopObserving(context_.get());
303 net_log_logger_.reset(); 303 net_log_logger_.reset();
304 } 304 }
305 } 305 }
306 306
307 // Creates RequestContextAdater if config is valid URLRequestContextConfig, 307 // Creates RequestContextAdater if config is valid URLRequestContextConfig,
308 // returns 0 otherwise. 308 // returns 0 otherwise.
309 static jlong CreateRequestContextAdapter(JNIEnv* env, 309 static jlong CreateRequestContextAdapter(JNIEnv* env,
310 jclass jcaller, 310 jclass jcaller,
311 jstring jconfig) { 311 jstring jconfig) {
312 std::string config_string = 312 std::string config_string =
313 base::android::ConvertJavaStringToUTF8(env, jconfig); 313 base::android::ConvertJavaStringToUTF8(env, jconfig);
314 scoped_ptr<URLRequestContextConfig> context_config( 314 scoped_ptr<URLRequestContextConfig> context_config(
315 new URLRequestContextConfig()); 315 new URLRequestContextConfig());
316 if (!context_config->LoadFromJSON(config_string)) 316 if (!context_config->LoadFromJSON(config_string))
317 return 0; 317 return 0;
318 318
319 CronetURLRequestContextAdapter* context_adapter = 319 CronetURLRequestContextAdapter* context_adapter =
320 new CronetURLRequestContextAdapter(context_config.Pass()); 320 new CronetURLRequestContextAdapter(context_config.Pass());
321 return reinterpret_cast<jlong>(context_adapter); 321 return reinterpret_cast<jlong>(context_adapter);
322 } 322 }
323 323
324 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { 324 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) {
325 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 325 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
326 // MinLogLevel is global, shared by all URLRequestContexts. 326 // MinLogLevel is global, shared by all URLRequestContexts.
327 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 327 logging::SetMinLogLevel(static_cast<int>(jlog_level));
328 return old_log_level; 328 return old_log_level;
329 } 329 }
330 330
331 } // namespace cronet 331 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698