Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: components/cronet/android/cronet_url_request_context.cc

Issue 726013002: [Cronet] Hook up library loader, system proxy and network change notifier to async api. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/cronet_url_request_context.h" 5 #include "components/cronet/android/cronet_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"
(...skipping 25 matching lines...) Expand all
36 // Sets global user-agent to be used for all subsequent requests. 36 // Sets global user-agent to be used for all subsequent requests.
37 static jlong CreateRequestContextAdapter(JNIEnv* env, 37 static jlong CreateRequestContextAdapter(JNIEnv* env,
38 jobject jcaller, 38 jobject jcaller,
39 jobject japp_context, 39 jobject japp_context,
40 jstring jconfig) { 40 jstring jconfig) {
41 std::string config_string = 41 std::string config_string =
42 base::android::ConvertJavaStringToUTF8(env, jconfig); 42 base::android::ConvertJavaStringToUTF8(env, jconfig);
43 scoped_ptr<URLRequestContextConfig> context_config( 43 scoped_ptr<URLRequestContextConfig> context_config(
44 new URLRequestContextConfig()); 44 new URLRequestContextConfig());
45 if (!context_config->LoadFromJSON(config_string)) 45 if (!context_config->LoadFromJSON(config_string))
46 return 0; 46 return 0;
mmenke 2015/01/08 19:06:16 We parse the config here...And then we just throw
mef 2015/01/08 21:17:02 Done.
47 47
48 // Set application context.
49 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, japp_context);
50 base::android::InitApplicationContext(env, scoped_context);
51
52 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
53 jcaller_ref.Reset(env, jcaller);
54
55 CronetURLRequestContextAdapter* context_adapter = 48 CronetURLRequestContextAdapter* context_adapter =
56 new CronetURLRequestContextAdapter(); 49 new CronetURLRequestContextAdapter();
57 base::Closure init_java_network_thread = base::Bind(&initJavaNetworkThread,
58 jcaller_ref);
59 context_adapter->Initialize(context_config.Pass(), init_java_network_thread);
60
61 return reinterpret_cast<jlong>(context_adapter); 50 return reinterpret_cast<jlong>(context_adapter);
62 } 51 }
63 52
64 // Destroys native objects. 53 // Destroys native objects.
65 static void DestroyRequestContextAdapter(JNIEnv* env, 54 static void DestroyRequestContextAdapter(JNIEnv* env,
66 jobject jcaller, 55 jobject jcaller,
67 jlong jurl_request_context_adapter) { 56 jlong jurl_request_context_adapter) {
68 DCHECK(jurl_request_context_adapter); 57 DCHECK(jurl_request_context_adapter);
69 CronetURLRequestContextAdapter* context_adapter = 58 CronetURLRequestContextAdapter* context_adapter =
70 reinterpret_cast<CronetURLRequestContextAdapter*>( 59 reinterpret_cast<CronetURLRequestContextAdapter*>(
(...skipping 28 matching lines...) Expand all
99 context_adapter->StopNetLog(); 88 context_adapter->StopNetLog();
100 } 89 }
101 90
102 static jint SetMinLogLevel(JNIEnv* env, jobject jcaller, jint jlog_level) { 91 static jint SetMinLogLevel(JNIEnv* env, jobject jcaller, jint jlog_level) {
103 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 92 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
104 // MinLogLevel is global, shared by all URLRequestContexts. 93 // MinLogLevel is global, shared by all URLRequestContexts.
105 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 94 logging::SetMinLogLevel(static_cast<int>(jlog_level));
106 return old_log_level; 95 return old_log_level;
107 } 96 }
108 97
98 // Called on application's main Java thread.
99 static void InitRequestContextOnMainThread(JNIEnv* env,
100 jobject jcaller,
101 jlong jurl_request_context_adapter,
102 jstring jconfig) {
103 if (jurl_request_context_adapter == 0)
104 return;
105
106 std::string config_string =
107 base::android::ConvertJavaStringToUTF8(env, jconfig);
108 scoped_ptr<URLRequestContextConfig> context_config(
109 new URLRequestContextConfig());
110 if (!context_config->LoadFromJSON(config_string))
111 return;
112
113 CronetURLRequestContextAdapter* context_adapter =
114 reinterpret_cast<CronetURLRequestContextAdapter*>(
115 jurl_request_context_adapter);
116
117 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
118 jcaller_ref.Reset(env, jcaller);
119 base::Closure init_java_network_thread = base::Bind(&initJavaNetworkThread,
120 jcaller_ref);
121 context_adapter->InitRequestContextOnMainThread(
122 context_config.Pass(), init_java_network_thread);
123 }
124
109 } // namespace cronet 125 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698