Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/android/jni_android.h" | |
| 6 #include "base/android/jni_registrar.h" | |
| 7 #include "base/android/jni_string.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "jni/URLRequestJobUtil_jni.h" | |
| 10 #include "net/base/net_errors.h" | |
| 11 #include "net/test/url_request_failed_job.h" | |
| 12 #include "net/url_request/url_request_filter.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 using base::android::ConvertJavaStringToUTF8; | |
| 16 | |
| 17 namespace cronet { | |
| 18 namespace { | |
| 19 // Fails requests using ERR_CONNECTION_RESET. | |
| 20 net::URLRequestJob* FailedJobFactory( | |
| 21 net::URLRequest* request, | |
| 22 net::NetworkDelegate* network_delegate, | |
| 23 const std::string& scheme) { | |
| 24 return new net::URLRequestFailedJob( | |
| 25 request, network_delegate, net::ERR_CONNECTION_RESET); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 static void FailURLRequestJob(JNIEnv* env, jclass jcaller, jstring jurl) { | |
| 31 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | |
| 32 filter->AddUrlHandler( | |
| 33 GURL(ConvertJavaStringToUTF8(env, jurl)), &FailedJobFactory); | |
|
mmenke
2014/09/03 18:02:35
Suggest just using URLRequestFailedJob::AddUrlHand
| |
| 34 } | |
| 35 | |
| 36 // Explicitly register static JNI functions. | |
| 37 bool MockURLRequestJobRegisterJni(JNIEnv* env) { | |
| 38 return RegisterNativesImpl(env); | |
| 39 } | |
| 40 | |
| 41 } // namespace cronet | |
| 42 | |
| OLD | NEW |