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

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

Issue 1868433003: [Cronet] Leak NetLog instance used by CronetUrlRequestContextAdapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed flake Created 4 years, 8 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 <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <map> 10 #include <map>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/android/jni_android.h" 13 #include "base/android/jni_android.h"
14 #include "base/android/jni_array.h" 14 #include "base/android/jni_array.h"
15 #include "base/android/jni_string.h" 15 #include "base/android/jni_string.h"
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
19 #include "base/files/scoped_file.h" 19 #include "base/files/scoped_file.h"
20 #include "base/lazy_instance.h"
20 #include "base/logging.h" 21 #include "base/logging.h"
21 #include "base/macros.h" 22 #include "base/macros.h"
22 #include "base/memory/scoped_vector.h" 23 #include "base/memory/scoped_vector.h"
23 #include "base/message_loop/message_loop.h" 24 #include "base/message_loop/message_loop.h"
24 #include "base/metrics/statistics_recorder.h" 25 #include "base/metrics/statistics_recorder.h"
25 #include "base/single_thread_task_runner.h" 26 #include "base/single_thread_task_runner.h"
26 #include "base/time/time.h" 27 #include "base/time/time.h"
27 #include "base/values.h" 28 #include "base/values.h"
28 #include "components/cronet/histogram_manager.h" 29 #include "components/cronet/histogram_manager.h"
29 #include "components/cronet/url_request_context_config.h" 30 #include "components/cronet/url_request_context_config.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 if (!base::CreateDirectory(prefs_dir)) { 337 if (!base::CreateDirectory(prefs_dir)) {
337 DLOG(WARNING) << "Cannot create prefs directory"; 338 DLOG(WARNING) << "Cannot create prefs directory";
338 return; 339 return;
339 } 340 }
340 } 341 }
341 342
342 } // namespace 343 } // namespace
343 344
344 namespace cronet { 345 namespace cronet {
345 346
347 // Use a global NetLog instance. See crbug.com/486120.
348 static base::LazyInstance<net::NetLog>::Leaky g_net_log =
349 LAZY_INSTANCE_INITIALIZER;
mmenke 2016/04/07 19:55:13 This should be in the anonymous namespace above.
xunjieli 2016/04/07 21:34:01 Done.
350
346 // Explicitly register static JNI functions. 351 // Explicitly register static JNI functions.
347 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env) { 352 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env) {
348 return RegisterNativesImpl(env); 353 return RegisterNativesImpl(env);
349 } 354 }
350 355
351 CronetURLRequestContextAdapter::CronetURLRequestContextAdapter( 356 CronetURLRequestContextAdapter::CronetURLRequestContextAdapter(
352 scoped_ptr<URLRequestContextConfig> context_config) 357 scoped_ptr<URLRequestContextConfig> context_config)
353 : network_thread_(new base::Thread("network")), 358 : network_thread_(new base::Thread("network")),
354 http_server_properties_manager_(nullptr), 359 http_server_properties_manager_(nullptr),
355 context_config_(std::move(context_config)), 360 context_config_(std::move(context_config)),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // TODO(mmenke): Add method to have the builder enable SPDY. 478 // TODO(mmenke): Add method to have the builder enable SPDY.
474 net::URLRequestContextBuilder context_builder; 479 net::URLRequestContextBuilder context_builder;
475 480
476 // TODO(mef): Remove this work around for crbug.com/543366 once it is fixed. 481 // TODO(mef): Remove this work around for crbug.com/543366 once it is fixed.
477 net::URLRequestContextBuilder::HttpNetworkSessionParams 482 net::URLRequestContextBuilder::HttpNetworkSessionParams
478 custom_http_network_session_params; 483 custom_http_network_session_params;
479 custom_http_network_session_params.parse_alternative_services = false; 484 custom_http_network_session_params.parse_alternative_services = false;
480 context_builder.set_http_network_session_params( 485 context_builder.set_http_network_session_params(
481 custom_http_network_session_params); 486 custom_http_network_session_params);
482 487
483 net_log_.reset(new net::NetLog);
484 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate()); 488 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate());
485 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 489 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
486 DCHECK(!data_reduction_proxy_); 490 DCHECK(!data_reduction_proxy_);
487 // For now, the choice to enable the data reduction proxy happens once, 491 // For now, the choice to enable the data reduction proxy happens once,
488 // at initialization. It cannot be disabled thereafter. 492 // at initialization. It cannot be disabled thereafter.
489 if (!config->data_reduction_proxy_key.empty()) { 493 if (!config->data_reduction_proxy_key.empty()) {
490 data_reduction_proxy_.reset(new CronetDataReductionProxy( 494 data_reduction_proxy_.reset(new CronetDataReductionProxy(
491 config->data_reduction_proxy_key, config->data_reduction_primary_proxy, 495 config->data_reduction_proxy_key, config->data_reduction_primary_proxy,
492 config->data_reduction_fallback_proxy, 496 config->data_reduction_fallback_proxy,
493 config->data_reduction_secure_proxy_check_url, config->user_agent, 497 config->data_reduction_secure_proxy_check_url, config->user_agent,
494 GetNetworkTaskRunner(), net_log_.get())); 498 GetNetworkTaskRunner(), g_net_log.Pointer()));
495 network_delegate = data_reduction_proxy_->CreateNetworkDelegate( 499 network_delegate = data_reduction_proxy_->CreateNetworkDelegate(
496 std::move(network_delegate)); 500 std::move(network_delegate));
497 context_builder.set_proxy_delegate( 501 context_builder.set_proxy_delegate(
498 data_reduction_proxy_->CreateProxyDelegate()); 502 data_reduction_proxy_->CreateProxyDelegate());
499 std::vector<scoped_ptr<net::URLRequestInterceptor>> interceptors; 503 std::vector<scoped_ptr<net::URLRequestInterceptor>> interceptors;
500 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); 504 interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
501 context_builder.SetInterceptors(std::move(interceptors)); 505 context_builder.SetInterceptors(std::move(interceptors));
502 } 506 }
503 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) 507 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT)
504 context_builder.set_network_delegate(std::move(network_delegate)); 508 context_builder.set_network_delegate(std::move(network_delegate));
505 context_builder.set_net_log(net_log_.get()); 509 context_builder.set_net_log(g_net_log.Pointer());
506 510
507 // Android provides a local HTTP proxy server that handles proxying when a PAC 511 // Android provides a local HTTP proxy server that handles proxying when a PAC
508 // URL is present. Create a proxy service without a resolver and rely on this 512 // URL is present. Create a proxy service without a resolver and rely on this
509 // local HTTP proxy. See: crbug.com/432539. 513 // local HTTP proxy. See: crbug.com/432539.
510 context_builder.set_proxy_service( 514 context_builder.set_proxy_service(
511 net::ProxyService::CreateWithoutProxyResolver( 515 net::ProxyService::CreateWithoutProxyResolver(
512 std::move(proxy_config_service_), net_log_.get())); 516 std::move(proxy_config_service_), g_net_log.Pointer()));
513 517
514 config->ConfigureURLRequestContextBuilder(&context_builder, net_log_.get(), 518 config->ConfigureURLRequestContextBuilder(
515 GetFileThread()->task_runner()); 519 &context_builder, g_net_log.Pointer(), GetFileThread()->task_runner());
516 520
517 // Set up pref file if storage path is specified. 521 // Set up pref file if storage path is specified.
518 if (!config->storage_path.empty()) { 522 if (!config->storage_path.empty()) {
519 base::FilePath storage_path(config->storage_path); 523 base::FilePath storage_path(config->storage_path);
520 // Make sure storage directory has correct version. 524 // Make sure storage directory has correct version.
521 InitializeStorageDirectory(storage_path); 525 InitializeStorageDirectory(storage_path);
522 base::FilePath filepath = 526 base::FilePath filepath =
523 storage_path.Append(FILE_PATH_LITERAL(kPrefsDirectoryName)) 527 storage_path.Append(FILE_PATH_LITERAL(kPrefsDirectoryName))
524 .Append(FILE_PATH_LITERAL(kPrefsFileName)); 528 .Append(FILE_PATH_LITERAL(kPrefsFileName));
525 json_pref_store_ = new JsonPrefStore( 529 json_pref_store_ = new JsonPrefStore(
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 JNIEnv* env, 885 JNIEnv* env,
882 const JavaParamRef<jclass>& jcaller) { 886 const JavaParamRef<jclass>& jcaller) {
883 base::StatisticsRecorder::Initialize(); 887 base::StatisticsRecorder::Initialize();
884 std::vector<uint8_t> data; 888 std::vector<uint8_t> data;
885 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 889 if (!HistogramManager::GetInstance()->GetDeltas(&data))
886 return ScopedJavaLocalRef<jbyteArray>(); 890 return ScopedJavaLocalRef<jbyteArray>();
887 return base::android::ToJavaByteArray(env, &data[0], data.size()); 891 return base::android::ToJavaByteArray(env, &data[0], data.size());
888 } 892 }
889 893
890 } // namespace cronet 894 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698