| OLD | NEW |
| 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/chromium_url_request_context.h" | 5 #include "components/cronet/android/chromium_url_request_context.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 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" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/metrics/statistics_recorder.h" | 14 #include "base/metrics/statistics_recorder.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "components/cronet/android/chromium_url_request.h" | 16 #include "components/cronet/android/chromium_url_request.h" |
| 17 #include "components/cronet/android/url_request_adapter.h" | 17 #include "components/cronet/android/url_request_adapter.h" |
| 18 #include "components/cronet/android/url_request_context_adapter.h" | 18 #include "components/cronet/android/url_request_context_adapter.h" |
| 19 #include "components/cronet/url_request_context_config.h" | 19 #include "components/cronet/url_request_context_config.h" |
| 20 #include "jni/ChromiumUrlRequestContext_jni.h" | 20 #include "jni/ChromiumUrlRequestContext_jni.h" |
| 21 #include "net/cert/cert_verifier.h" |
| 21 | 22 |
| 22 using base::android::ConvertUTF8ToJavaString; | 23 using base::android::ConvertUTF8ToJavaString; |
| 23 using base::android::ConvertJavaStringToUTF8; | 24 using base::android::ConvertJavaStringToUTF8; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Delegate of URLRequestContextAdapter that delivers callbacks to the Java | 28 // Delegate of URLRequestContextAdapter that delivers callbacks to the Java |
| 28 // layer. | 29 // layer. |
| 29 class JniURLRequestContextAdapterDelegate | 30 class JniURLRequestContextAdapterDelegate |
| 30 : public cronet::URLRequestContextAdapter:: | 31 : public cronet::URLRequestContextAdapter:: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 91 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
| 91 | 92 |
| 92 // TODO(dplotnikov): set application context. | 93 // TODO(dplotnikov): set application context. |
| 93 URLRequestContextAdapter* context_adapter = new URLRequestContextAdapter( | 94 URLRequestContextAdapter* context_adapter = new URLRequestContextAdapter( |
| 94 new JniURLRequestContextAdapterDelegate(env, jcaller), user_agent); | 95 new JniURLRequestContextAdapterDelegate(env, jcaller), user_agent); |
| 95 context_adapter->AddRef(); // Hold onto this ref-counted object. | 96 context_adapter->AddRef(); // Hold onto this ref-counted object. |
| 96 context_adapter->Initialize(context_config.Pass()); | 97 context_adapter->Initialize(context_config.Pass()); |
| 97 return reinterpret_cast<jlong>(context_adapter); | 98 return reinterpret_cast<jlong>(context_adapter); |
| 98 } | 99 } |
| 99 | 100 |
| 101 static void SetMockCertVerifierForTesting(JNIEnv* env, |
| 102 const JavaParamRef<jobject>& jcaller, |
| 103 jlong jcontext_adapter, |
| 104 jlong jmock_verifier) { |
| 105 URLRequestContextAdapter* context_adapter = |
| 106 reinterpret_cast<URLRequestContextAdapter*>(jcontext_adapter); |
| 107 net::CertVerifier* mock_verifier = |
| 108 reinterpret_cast<net::CertVerifier*>(jmock_verifier); |
| 109 context_adapter->SetMockCertVerifierForTesting(mock_verifier); |
| 110 } |
| 111 |
| 100 // Releases native objects. | 112 // Releases native objects. |
| 101 static void ReleaseRequestContextAdapter(JNIEnv* env, | 113 static void ReleaseRequestContextAdapter(JNIEnv* env, |
| 102 const JavaParamRef<jobject>& jcaller, | 114 const JavaParamRef<jobject>& jcaller, |
| 103 jlong jurl_request_context_adapter) { | 115 jlong jurl_request_context_adapter) { |
| 104 URLRequestContextAdapter* context_adapter = | 116 URLRequestContextAdapter* context_adapter = |
| 105 reinterpret_cast<URLRequestContextAdapter*>(jurl_request_context_adapter); | 117 reinterpret_cast<URLRequestContextAdapter*>(jurl_request_context_adapter); |
| 106 // TODO(mef): Revisit this from thread safety point of view: Can we delete a | 118 // TODO(mef): Revisit this from thread safety point of view: Can we delete a |
| 107 // thread while running on that thread? | 119 // thread while running on that thread? |
| 108 // URLRequestContextAdapter is a ref-counted object, and may have pending | 120 // URLRequestContextAdapter is a ref-counted object, and may have pending |
| 109 // tasks, | 121 // tasks, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // Called on application's main Java thread. | 164 // Called on application's main Java thread. |
| 153 static void InitRequestContextOnMainThread(JNIEnv* env, | 165 static void InitRequestContextOnMainThread(JNIEnv* env, |
| 154 const JavaParamRef<jobject>& jcaller, | 166 const JavaParamRef<jobject>& jcaller, |
| 155 jlong jurl_request_context_adapter) { | 167 jlong jurl_request_context_adapter) { |
| 156 URLRequestContextAdapter* context_adapter = | 168 URLRequestContextAdapter* context_adapter = |
| 157 reinterpret_cast<URLRequestContextAdapter*>(jurl_request_context_adapter); | 169 reinterpret_cast<URLRequestContextAdapter*>(jurl_request_context_adapter); |
| 158 context_adapter->InitRequestContextOnMainThread(); | 170 context_adapter->InitRequestContextOnMainThread(); |
| 159 } | 171 } |
| 160 | 172 |
| 161 } // namespace cronet | 173 } // namespace cronet |
| OLD | NEW |