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

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

Issue 1389213003: [Cronet] Use Https for Quic Test Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ryancl
Patch Set: Use mock verifier and fix tests Created 5 years, 2 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 <map> 7 #include <map>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 23 matching lines...) Expand all
34 #include "net/proxy/proxy_service.h" 34 #include "net/proxy/proxy_service.h"
35 #include "net/sdch/sdch_owner.h" 35 #include "net/sdch/sdch_owner.h"
36 #include "net/url_request/url_request_context.h" 36 #include "net/url_request/url_request_context.h"
37 #include "net/url_request/url_request_context_builder.h" 37 #include "net/url_request/url_request_context_builder.h"
38 #include "net/url_request/url_request_interceptor.h" 38 #include "net/url_request/url_request_interceptor.h"
39 39
40 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 40 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
41 #include "components/cronet/android/cronet_data_reduction_proxy.h" 41 #include "components/cronet/android/cronet_data_reduction_proxy.h"
42 #endif 42 #endif
43 43
44 #if defined(CRONET_TEST)
45 #include "net/base/test_data_directory.h"
46 #include "net/cert/cert_verifier.h"
47 #include "net/cert/cert_verify_result.h"
48 #include "net/cert/mock_cert_verifier.h"
49 #include "net/test/cert_test_util.h"
50 #endif
51
44 namespace { 52 namespace {
45 53
46 const char kHttpServerProperties[] = "net.http_server_properties"; 54 const char kHttpServerProperties[] = "net.http_server_properties";
47 55
48 class BasicNetworkDelegate : public net::NetworkDelegateImpl { 56 class BasicNetworkDelegate : public net::NetworkDelegateImpl {
49 public: 57 public:
50 BasicNetworkDelegate() {} 58 BasicNetworkDelegate() {}
51 ~BasicNetworkDelegate() override {} 59 ~BasicNetworkDelegate() override {}
52 60
53 private: 61 private:
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 context_builder.set_net_log(net_log_.get()); 279 context_builder.set_net_log(net_log_.get());
272 280
273 // Android provides a local HTTP proxy server that handles proxying when a PAC 281 // Android provides a local HTTP proxy server that handles proxying when a PAC
274 // URL is present. Create a proxy service without a resolver and rely on this 282 // URL is present. Create a proxy service without a resolver and rely on this
275 // local HTTP proxy. See: crbug.com/432539. 283 // local HTTP proxy. See: crbug.com/432539.
276 context_builder.set_proxy_service( 284 context_builder.set_proxy_service(
277 net::ProxyService::CreateWithoutProxyResolver( 285 net::ProxyService::CreateWithoutProxyResolver(
278 proxy_config_service_.Pass(), net_log_.get())); 286 proxy_config_service_.Pass(), net_log_.get()));
279 config->ConfigureURLRequestContextBuilder(&context_builder); 287 config->ConfigureURLRequestContextBuilder(&context_builder);
280 288
289 #if defined(CRONET_TEST)
290 ConfigureURLRequestContextBuilderForTesting(config.get(), &context_builder);
291 #endif
292
281 // Set up pref file if storage path is specified. 293 // Set up pref file if storage path is specified.
282 if (!config->storage_path.empty()) { 294 if (!config->storage_path.empty()) {
283 base::FilePath filepath(config->storage_path); 295 base::FilePath filepath(config->storage_path);
284 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); 296 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json"));
285 json_pref_store_ = new JsonPrefStore( 297 json_pref_store_ = new JsonPrefStore(
286 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); 298 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>());
287 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); 299 context_builder.SetFileTaskRunner(GetFileThread()->task_runner());
288 300
289 // Set up HttpServerPropertiesManager. 301 // Set up HttpServerPropertiesManager.
290 base::PrefServiceFactory factory; 302 base::PrefServiceFactory factory;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 void CronetURLRequestContextAdapter::OnThroughputObservation( 509 void CronetURLRequestContextAdapter::OnThroughputObservation(
498 int32_t throughput_kbps, 510 int32_t throughput_kbps,
499 const base::TimeTicks& timestamp, 511 const base::TimeTicks& timestamp,
500 net::NetworkQualityEstimator::ObservationSource source) { 512 net::NetworkQualityEstimator::ObservationSource source) {
501 Java_CronetUrlRequestContext_onThroughputObservation( 513 Java_CronetUrlRequestContext_onThroughputObservation(
502 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), 514 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(),
503 throughput_kbps, 515 throughput_kbps,
504 (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), source); 516 (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), source);
505 } 517 }
506 518
519 #if defined(CRONET_TEST)
520 void CronetURLRequestContextAdapter::
521 ConfigureURLRequestContextBuilderForTesting(
522 URLRequestContextConfig* config,
523 net::URLRequestContextBuilder* builder) {
524 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
525 DCHECK(!mock_cert_verifier_);
526
527 if (config->mock_certs_for_testing.empty())
528 return;
529
530 base::StringTokenizer tokens(config->mock_certs_for_testing, ",");
531 mock_cert_verifier_.reset(new net::MockCertVerifier());
532 while (tokens.GetNext()) {
533 net::CertVerifyResult verify_result;
534 verify_result.verified_cert =
535 net::ImportCertFromFile(net::GetTestCertsDirectory(), tokens.token());
536 mock_cert_verifier_->AddResultForCert(verify_result.verified_cert.get(),
537 verify_result, net::OK);
538 }
539 builder->set_cert_verifier(mock_cert_verifier_.get());
540 }
541 #endif
542
507 // Creates RequestContextAdater if config is valid URLRequestContextConfig, 543 // Creates RequestContextAdater if config is valid URLRequestContextConfig,
508 // returns 0 otherwise. 544 // returns 0 otherwise.
509 static jlong CreateRequestContextAdapter(JNIEnv* env, 545 static jlong CreateRequestContextAdapter(JNIEnv* env,
510 const JavaParamRef<jclass>& jcaller, 546 const JavaParamRef<jclass>& jcaller,
511 const JavaParamRef<jstring>& jconfig) { 547 const JavaParamRef<jstring>& jconfig) {
512 std::string config_string = 548 std::string config_string =
513 base::android::ConvertJavaStringToUTF8(env, jconfig); 549 base::android::ConvertJavaStringToUTF8(env, jconfig);
514 scoped_ptr<URLRequestContextConfig> context_config( 550 scoped_ptr<URLRequestContextConfig> context_config(
515 new URLRequestContextConfig()); 551 new URLRequestContextConfig());
516 if (!context_config->LoadFromJSON(config_string)) 552 if (!context_config->LoadFromJSON(config_string))
517 return 0; 553 return 0;
518 554
519 CronetURLRequestContextAdapter* context_adapter = 555 CronetURLRequestContextAdapter* context_adapter =
520 new CronetURLRequestContextAdapter(context_config.Pass()); 556 new CronetURLRequestContextAdapter(context_config.Pass());
521 return reinterpret_cast<jlong>(context_adapter); 557 return reinterpret_cast<jlong>(context_adapter);
522 } 558 }
523 559
524 static jint SetMinLogLevel(JNIEnv* env, 560 static jint SetMinLogLevel(JNIEnv* env,
525 const JavaParamRef<jclass>& jcaller, 561 const JavaParamRef<jclass>& jcaller,
526 jint jlog_level) { 562 jint jlog_level) {
527 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 563 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
528 // MinLogLevel is global, shared by all URLRequestContexts. 564 // MinLogLevel is global, shared by all URLRequestContexts.
529 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 565 logging::SetMinLogLevel(static_cast<int>(jlog_level));
530 return old_log_level; 566 return old_log_level;
531 } 567 }
532 568
533 } // namespace cronet 569 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698