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/org_chromium_net_UrlRequestContext.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/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/statistics_recorder.h" | 14 #include "base/metrics/statistics_recorder.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "components/cronet/android/org_chromium_net_UrlRequest.h" | 16 #include "components/cronet/android/org_chromium_net_UrlRequest.h" |
16 #include "components/cronet/android/url_request_context_peer.h" | 17 #include "components/cronet/android/url_request_context_peer.h" |
17 #include "components/cronet/android/url_request_peer.h" | 18 #include "components/cronet/android/url_request_peer.h" |
18 #include "components/cronet/url_request_context_config.h" | 19 #include "components/cronet/url_request_context_config.h" |
19 #include "jni/UrlRequestContext_jni.h" | 20 #include "jni/UrlRequestContext_jni.h" |
20 | 21 |
21 namespace { | 22 namespace { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 base::JSONValueConverter<URLRequestContextConfig> converter; | 80 base::JSONValueConverter<URLRequestContextConfig> converter; |
80 if (!converter.Convert(*config_value, context_config.get())) { | 81 if (!converter.Convert(*config_value, context_config.get())) { |
81 DLOG(ERROR) << "Bad Config: " << config_value; | 82 DLOG(ERROR) << "Bad Config: " << config_value; |
82 return 0; | 83 return 0; |
83 } | 84 } |
84 | 85 |
85 // Set application context. | 86 // Set application context. |
86 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); | 87 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); |
87 base::android::InitApplicationContext(env, scoped_context); | 88 base::android::InitApplicationContext(env, scoped_context); |
88 | 89 |
89 int logging_level = log_level; | 90 // TODO(mef): MinLogLevel is global, shared by all URLRequestContexts. |
| 91 // Revisit this if each URLRequestContext would need an individual log level. |
| 92 logging::SetMinLogLevel(static_cast<int>(log_level)); |
90 | 93 |
91 // TODO(dplotnikov): set application context. | 94 // TODO(dplotnikov): set application context. |
92 URLRequestContextPeer* peer = new URLRequestContextPeer( | 95 URLRequestContextPeer* peer = new URLRequestContextPeer( |
93 new JniURLRequestContextPeerDelegate(env, object), | 96 new JniURLRequestContextPeerDelegate(env, object), user_agent_string); |
94 user_agent_string, | |
95 logging_level); | |
96 peer->AddRef(); // Hold onto this ref-counted object. | 97 peer->AddRef(); // Hold onto this ref-counted object. |
97 peer->Initialize(context_config.Pass()); | 98 peer->Initialize(context_config.Pass()); |
98 return reinterpret_cast<jlong>(peer); | 99 return reinterpret_cast<jlong>(peer); |
99 } | 100 } |
100 | 101 |
101 // Releases native objects. | 102 // Releases native objects. |
102 static void ReleaseRequestContextPeer(JNIEnv* env, | 103 static void ReleaseRequestContextPeer(JNIEnv* env, |
103 jobject object, | 104 jobject object, |
104 jlong urlRequestContextPeer) { | 105 jlong urlRequestContextPeer) { |
105 URLRequestContextPeer* peer = | 106 URLRequestContextPeer* peer = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Stops recording NetLog. | 139 // Stops recording NetLog. |
139 static void StopNetLog(JNIEnv* env, | 140 static void StopNetLog(JNIEnv* env, |
140 jobject jcaller, | 141 jobject jcaller, |
141 jlong urlRequestContextPeer) { | 142 jlong urlRequestContextPeer) { |
142 URLRequestContextPeer* peer = | 143 URLRequestContextPeer* peer = |
143 reinterpret_cast<URLRequestContextPeer*>(urlRequestContextPeer); | 144 reinterpret_cast<URLRequestContextPeer*>(urlRequestContextPeer); |
144 peer->StopNetLog(); | 145 peer->StopNetLog(); |
145 } | 146 } |
146 | 147 |
147 } // namespace cronet | 148 } // namespace cronet |
OLD | NEW |