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/org_chromium_net_UrlRequestContext.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/org_chromium_net_UrlRequest.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/UrlRequestContext_jni.h" | 20 #include "jni/ChromiumUrlRequestContext_jni.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Delegate of URLRequestContextAdapter that delivers callbacks to the Java | 24 // Delegate of URLRequestContextAdapter that delivers callbacks to the Java |
25 // layer. | 25 // layer. |
26 class JniURLRequestContextAdapterDelegate | 26 class JniURLRequestContextAdapterDelegate |
27 : public cronet::URLRequestContextAdapter:: | 27 : public cronet::URLRequestContextAdapter:: |
28 URLRequestContextAdapterDelegate { | 28 URLRequestContextAdapterDelegate { |
29 public: | 29 public: |
30 JniURLRequestContextAdapterDelegate(JNIEnv* env, jobject owner) | 30 JniURLRequestContextAdapterDelegate(JNIEnv* env, jobject owner) |
31 : owner_(env->NewGlobalRef(owner)) {} | 31 : owner_(env->NewGlobalRef(owner)) {} |
32 | 32 |
33 virtual void OnContextInitialized( | 33 virtual void OnContextInitialized( |
34 cronet::URLRequestContextAdapter* context) OVERRIDE { | 34 cronet::URLRequestContextAdapter* context) OVERRIDE { |
35 JNIEnv* env = base::android::AttachCurrentThread(); | 35 JNIEnv* env = base::android::AttachCurrentThread(); |
36 cronet::Java_UrlRequestContext_initNetworkThread(env, owner_); | 36 cronet::Java_ChromiumUrlRequestContext_initNetworkThread(env, owner_); |
37 // TODO(dplotnikov): figure out if we need to detach from the thread. | 37 // TODO(dplotnikov): figure out if we need to detach from the thread. |
38 // The documentation says we should detach just before the thread exits. | 38 // The documentation says we should detach just before the thread exits. |
39 } | 39 } |
40 | 40 |
41 protected: | 41 protected: |
42 virtual ~JniURLRequestContextAdapterDelegate() { | 42 virtual ~JniURLRequestContextAdapterDelegate() { |
43 JNIEnv* env = base::android::AttachCurrentThread(); | 43 JNIEnv* env = base::android::AttachCurrentThread(); |
44 env->DeleteGlobalRef(owner_); | 44 env->DeleteGlobalRef(owner_); |
45 } | 45 } |
46 | 46 |
47 private: | 47 private: |
48 jobject owner_; | 48 jobject owner_; |
49 }; | 49 }; |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 namespace cronet { | 53 namespace cronet { |
54 | 54 |
55 // Explicitly register static JNI functions. | 55 // Explicitly register static JNI functions. |
56 bool UrlRequestContextRegisterJni(JNIEnv* env) { | 56 bool ChromiumUrlRequestContextRegisterJni(JNIEnv* env) { |
57 return RegisterNativesImpl(env); | 57 return RegisterNativesImpl(env); |
58 } | 58 } |
59 | 59 |
60 // Sets global user-agent to be used for all subsequent requests. | 60 // Sets global user-agent to be used for all subsequent requests. |
61 static jlong CreateRequestContextAdapter(JNIEnv* env, | 61 static jlong CreateRequestContextAdapter(JNIEnv* env, |
62 jobject object, | 62 jobject object, |
63 jobject context, | 63 jobject context, |
64 jstring user_agent, | 64 jstring user_agent, |
65 jint log_level, | 65 jint log_level, |
66 jstring config) { | 66 jstring config) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Stops recording NetLog. | 141 // Stops recording NetLog. |
142 static void StopNetLog(JNIEnv* env, | 142 static void StopNetLog(JNIEnv* env, |
143 jobject jcaller, | 143 jobject jcaller, |
144 jlong urlRequestContextAdapter) { | 144 jlong urlRequestContextAdapter) { |
145 URLRequestContextAdapter* adapter = | 145 URLRequestContextAdapter* adapter = |
146 reinterpret_cast<URLRequestContextAdapter*>(urlRequestContextAdapter); | 146 reinterpret_cast<URLRequestContextAdapter*>(urlRequestContextAdapter); |
147 adapter->StopNetLog(); | 147 adapter->StopNetLog(); |
148 } | 148 } |
149 | 149 |
150 } // namespace cronet | 150 } // namespace cronet |
OLD | NEW |