Chromium Code Reviews| 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 logging::SetMinLogLevel(static_cast<int>(log_level)); |
|
mmenke
2014/08/07 15:07:27
Still a bit concerned about setting this globally,
mef
2014/08/07 15:39:57
Added TODO.
| |
| 90 | 91 |
| 91 // TODO(dplotnikov): set application context. | 92 // TODO(dplotnikov): set application context. |
| 92 URLRequestContextPeer* peer = new URLRequestContextPeer( | 93 URLRequestContextPeer* peer = new URLRequestContextPeer( |
| 93 new JniURLRequestContextPeerDelegate(env, object), | 94 new JniURLRequestContextPeerDelegate(env, object), user_agent_string); |
| 94 user_agent_string, | |
| 95 logging_level); | |
| 96 peer->AddRef(); // Hold onto this ref-counted object. | 95 peer->AddRef(); // Hold onto this ref-counted object. |
| 97 peer->Initialize(context_config.Pass()); | 96 peer->Initialize(context_config.Pass()); |
| 98 return reinterpret_cast<jlong>(peer); | 97 return reinterpret_cast<jlong>(peer); |
| 99 } | 98 } |
| 100 | 99 |
| 101 // Releases native objects. | 100 // Releases native objects. |
| 102 static void ReleaseRequestContextPeer(JNIEnv* env, | 101 static void ReleaseRequestContextPeer(JNIEnv* env, |
| 103 jobject object, | 102 jobject object, |
| 104 jlong urlRequestContextPeer) { | 103 jlong urlRequestContextPeer) { |
| 105 URLRequestContextPeer* peer = | 104 URLRequestContextPeer* peer = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 // Stops recording NetLog. | 137 // Stops recording NetLog. |
| 139 static void StopNetLog(JNIEnv* env, | 138 static void StopNetLog(JNIEnv* env, |
| 140 jobject jcaller, | 139 jobject jcaller, |
| 141 jlong urlRequestContextPeer) { | 140 jlong urlRequestContextPeer) { |
| 142 URLRequestContextPeer* peer = | 141 URLRequestContextPeer* peer = |
| 143 reinterpret_cast<URLRequestContextPeer*>(urlRequestContextPeer); | 142 reinterpret_cast<URLRequestContextPeer*>(urlRequestContextPeer); |
| 144 peer->StopNetLog(); | 143 peer->StopNetLog(); |
| 145 } | 144 } |
| 146 | 145 |
| 147 } // namespace cronet | 146 } // namespace cronet |
| OLD | NEW |