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

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

Issue 1977543002: [Cronet] Add network change events to Cronet's NetLog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10
(...skipping 19 matching lines...) Expand all
30 #include "base/values.h" 30 #include "base/values.h"
31 #include "components/cronet/histogram_manager.h" 31 #include "components/cronet/histogram_manager.h"
32 #include "components/cronet/url_request_context_config.h" 32 #include "components/cronet/url_request_context_config.h"
33 #include "components/prefs/pref_change_registrar.h" 33 #include "components/prefs/pref_change_registrar.h"
34 #include "components/prefs/pref_filter.h" 34 #include "components/prefs/pref_filter.h"
35 #include "components/prefs/pref_registry_simple.h" 35 #include "components/prefs/pref_registry_simple.h"
36 #include "components/prefs/pref_service.h" 36 #include "components/prefs/pref_service.h"
37 #include "components/prefs/pref_service_factory.h" 37 #include "components/prefs/pref_service_factory.h"
38 #include "jni/CronetUrlRequestContext_jni.h" 38 #include "jni/CronetUrlRequestContext_jni.h"
39 #include "net/base/load_flags.h" 39 #include "net/base/load_flags.h"
40 #include "net/base/logging_network_change_observer.h"
40 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
41 #include "net/base/network_delegate_impl.h" 42 #include "net/base/network_delegate_impl.h"
42 #include "net/base/url_util.h" 43 #include "net/base/url_util.h"
43 #include "net/cert/cert_verifier.h" 44 #include "net/cert/cert_verifier.h"
44 #include "net/cookies/cookie_monster.h" 45 #include "net/cookies/cookie_monster.h"
45 #include "net/http/http_auth_handler_factory.h" 46 #include "net/http/http_auth_handler_factory.h"
46 #include "net/http/http_server_properties_manager.h" 47 #include "net/http/http_server_properties_manager.h"
47 #include "net/log/write_to_file_net_log_observer.h" 48 #include "net/log/write_to_file_net_log_observer.h"
48 #include "net/nqe/external_estimate_provider.h" 49 #include "net/nqe/external_estimate_provider.h"
49 #include "net/proxy/proxy_config_service_android.h" 50 #include "net/proxy/proxy_config_service_android.h"
50 #include "net/proxy/proxy_service.h" 51 #include "net/proxy/proxy_service.h"
51 #include "net/sdch/sdch_owner.h" 52 #include "net/sdch/sdch_owner.h"
52 #include "net/ssl/channel_id_service.h" 53 #include "net/ssl/channel_id_service.h"
53 #include "net/url_request/url_request_context.h" 54 #include "net/url_request/url_request_context.h"
54 #include "net/url_request/url_request_context_builder.h" 55 #include "net/url_request/url_request_context_builder.h"
55 #include "net/url_request/url_request_interceptor.h" 56 #include "net/url_request/url_request_interceptor.h"
56 57
57 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 58 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
58 #include "components/cronet/android/cronet_data_reduction_proxy.h" 59 #include "components/cronet/android/cronet_data_reduction_proxy.h"
59 #endif 60 #endif
60 61
61 namespace { 62 namespace {
62 63
64 // This class wraps a NetLog that also contains network change events.
65 class NetLogWithNetworkChangeEvents {
66 public:
67 NetLogWithNetworkChangeEvents() : net_log_(), net_change_logger_(&net_log_) {}
68
69 net::NetLog* net_log() { return &net_log_; }
70
71 private:
72 net::NetLog net_log_;
xunjieli 2016/05/13 13:32:00 Can we make these into std::unique_ptr so we know
pauljensen 2016/05/13 16:16:18 Isn't having a definition of a variable even stron
xunjieli 2016/05/13 18:09:23 Acknowledged. Matt says if there isn't a use of un
73 net::LoggingNetworkChangeObserver net_change_logger_;
xunjieli 2016/05/13 13:32:00 Can we add a comment on why this is global?
pauljensen 2016/05/13 16:16:18 I don't think it is global, it's a member of a cla
xunjieli 2016/05/13 18:09:23 Yea. Semantically, it isn't a global. But it is es
pauljensen 2016/05/13 18:13:56 Well we have one LoggingNetworkChangeObserver for
xunjieli 2016/05/13 18:19:07 Yes. It isn't obvious why LoggingNetworkChangeObse
pauljensen 2016/05/21 01:26:31 Done.
74
75 DISALLOW_COPY_AND_ASSIGN(NetLogWithNetworkChangeEvents);
76 };
77
63 // Use a global NetLog instance. See crbug.com/486120. 78 // Use a global NetLog instance. See crbug.com/486120.
64 static base::LazyInstance<net::NetLog>::Leaky g_net_log = 79 static base::LazyInstance<NetLogWithNetworkChangeEvents>::Leaky g_net_log =
65 LAZY_INSTANCE_INITIALIZER; 80 LAZY_INSTANCE_INITIALIZER;
66 81
67 const char kHttpServerProperties[] = "net.http_server_properties"; 82 const char kHttpServerProperties[] = "net.http_server_properties";
68 // Current version of disk storage. 83 // Current version of disk storage.
69 const int32_t kStorageVersion = 1; 84 const int32_t kStorageVersion = 1;
70 // Version number used when the version of disk storage is unknown. 85 // Version number used when the version of disk storage is unknown.
71 const uint32_t kStorageVersionUnknown = 0; 86 const uint32_t kStorageVersionUnknown = 0;
72 // Name of preference directory. 87 // Name of preference directory.
73 const char kPrefsDirectoryName[] = "prefs"; 88 const char kPrefsDirectoryName[] = "prefs";
74 // Name of preference file. 89 // Name of preference file.
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 new BasicNetworkDelegate()); 499 new BasicNetworkDelegate());
485 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 500 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
486 DCHECK(!data_reduction_proxy_); 501 DCHECK(!data_reduction_proxy_);
487 // For now, the choice to enable the data reduction proxy happens once, 502 // For now, the choice to enable the data reduction proxy happens once,
488 // at initialization. It cannot be disabled thereafter. 503 // at initialization. It cannot be disabled thereafter.
489 if (!config->data_reduction_proxy_key.empty()) { 504 if (!config->data_reduction_proxy_key.empty()) {
490 data_reduction_proxy_.reset(new CronetDataReductionProxy( 505 data_reduction_proxy_.reset(new CronetDataReductionProxy(
491 config->data_reduction_proxy_key, config->data_reduction_primary_proxy, 506 config->data_reduction_proxy_key, config->data_reduction_primary_proxy,
492 config->data_reduction_fallback_proxy, 507 config->data_reduction_fallback_proxy,
493 config->data_reduction_secure_proxy_check_url, config->user_agent, 508 config->data_reduction_secure_proxy_check_url, config->user_agent,
494 GetNetworkTaskRunner(), g_net_log.Pointer())); 509 GetNetworkTaskRunner(), g_net_log.Get().net_log()));
495 network_delegate = data_reduction_proxy_->CreateNetworkDelegate( 510 network_delegate = data_reduction_proxy_->CreateNetworkDelegate(
496 std::move(network_delegate)); 511 std::move(network_delegate));
497 context_builder.set_proxy_delegate( 512 context_builder.set_proxy_delegate(
498 data_reduction_proxy_->CreateProxyDelegate()); 513 data_reduction_proxy_->CreateProxyDelegate());
499 std::vector<std::unique_ptr<net::URLRequestInterceptor>> interceptors; 514 std::vector<std::unique_ptr<net::URLRequestInterceptor>> interceptors;
500 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); 515 interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
501 context_builder.SetInterceptors(std::move(interceptors)); 516 context_builder.SetInterceptors(std::move(interceptors));
502 } 517 }
503 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) 518 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT)
504 context_builder.set_network_delegate(std::move(network_delegate)); 519 context_builder.set_network_delegate(std::move(network_delegate));
505 context_builder.set_net_log(g_net_log.Pointer()); 520 context_builder.set_net_log(g_net_log.Get().net_log());
506 521
507 // Android provides a local HTTP proxy server that handles proxying when a PAC 522 // 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 523 // URL is present. Create a proxy service without a resolver and rely on this
509 // local HTTP proxy. See: crbug.com/432539. 524 // local HTTP proxy. See: crbug.com/432539.
510 context_builder.set_proxy_service( 525 context_builder.set_proxy_service(
511 net::ProxyService::CreateWithoutProxyResolver( 526 net::ProxyService::CreateWithoutProxyResolver(
512 std::move(proxy_config_service_), g_net_log.Pointer())); 527 std::move(proxy_config_service_), g_net_log.Get().net_log()));
513 528
514 config->ConfigureURLRequestContextBuilder( 529 config->ConfigureURLRequestContextBuilder(&context_builder,
515 &context_builder, g_net_log.Pointer(), GetFileThread()->task_runner()); 530 g_net_log.Get().net_log(),
531 GetFileThread()->task_runner());
516 532
517 // Set up pref file if storage path is specified. 533 // Set up pref file if storage path is specified.
518 if (!config->storage_path.empty()) { 534 if (!config->storage_path.empty()) {
519 base::FilePath storage_path(config->storage_path); 535 base::FilePath storage_path(config->storage_path);
520 // Make sure storage directory has correct version. 536 // Make sure storage directory has correct version.
521 InitializeStorageDirectory(storage_path); 537 InitializeStorageDirectory(storage_path);
522 base::FilePath filepath = 538 base::FilePath filepath =
523 storage_path.Append(FILE_PATH_LITERAL(kPrefsDirectoryName)) 539 storage_path.Append(FILE_PATH_LITERAL(kPrefsDirectoryName))
524 .Append(FILE_PATH_LITERAL(kPrefsFileName)); 540 .Append(FILE_PATH_LITERAL(kPrefsFileName));
525 json_pref_store_ = 541 json_pref_store_ =
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 JNIEnv* env, 901 JNIEnv* env,
886 const JavaParamRef<jclass>& jcaller) { 902 const JavaParamRef<jclass>& jcaller) {
887 base::StatisticsRecorder::Initialize(); 903 base::StatisticsRecorder::Initialize();
888 std::vector<uint8_t> data; 904 std::vector<uint8_t> data;
889 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 905 if (!HistogramManager::GetInstance()->GetDeltas(&data))
890 return ScopedJavaLocalRef<jbyteArray>(); 906 return ScopedJavaLocalRef<jbyteArray>();
891 return base::android::ToJavaByteArray(env, &data[0], data.size()); 907 return base::android::ToJavaByteArray(env, &data[0], data.size());
892 } 908 }
893 909
894 } // namespace cronet 910 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698