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

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: Address Helen's comments. 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 28 matching lines...) Expand all
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;
47 47
48 // Set application context. 48 // Set application context.
49 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, japp_context); 49 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, japp_context);
xunjieli 2015/01/05 18:22:45 base::android::InitApplicationContext is already d
mef 2015/01/05 19:32:41 Done.
50 base::android::InitApplicationContext(env, scoped_context); 50 base::android::InitApplicationContext(env, scoped_context);
51 51
52 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
53 jcaller_ref.Reset(env, jcaller);
54
55 CronetURLRequestContextAdapter* context_adapter = 52 CronetURLRequestContextAdapter* context_adapter =
56 new CronetURLRequestContextAdapter(); 53 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); 54 return reinterpret_cast<jlong>(context_adapter);
62 } 55 }
63 56
64 // Destroys native objects. 57 // Destroys native objects.
65 static void DestroyRequestContextAdapter(JNIEnv* env, 58 static void DestroyRequestContextAdapter(JNIEnv* env,
66 jobject jcaller, 59 jobject jcaller,
67 jlong jurl_request_context_adapter) { 60 jlong jurl_request_context_adapter) {
68 DCHECK(jurl_request_context_adapter); 61 DCHECK(jurl_request_context_adapter);
69 CronetURLRequestContextAdapter* context_adapter = 62 CronetURLRequestContextAdapter* context_adapter =
70 reinterpret_cast<CronetURLRequestContextAdapter*>( 63 reinterpret_cast<CronetURLRequestContextAdapter*>(
(...skipping 28 matching lines...) Expand all
99 context_adapter->StopNetLog(); 92 context_adapter->StopNetLog();
100 } 93 }
101 94
102 static jint SetMinLogLevel(JNIEnv* env, jobject jcaller, jint jlog_level) { 95 static jint SetMinLogLevel(JNIEnv* env, jobject jcaller, jint jlog_level) {
103 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 96 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
104 // MinLogLevel is global, shared by all URLRequestContexts. 97 // MinLogLevel is global, shared by all URLRequestContexts.
105 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 98 logging::SetMinLogLevel(static_cast<int>(jlog_level));
106 return old_log_level; 99 return old_log_level;
107 } 100 }
108 101
102 // Called on application's main Java thread.
103 static void InitRequestContextOnMainThread(JNIEnv* env,
104 jobject jcaller,
105 jlong jurl_request_context_adapter,
106 jstring jconfig) {
107 if (jurl_request_context_adapter == 0)
108 return;
109
110 std::string config_string =
111 base::android::ConvertJavaStringToUTF8(env, jconfig);
112 scoped_ptr<URLRequestContextConfig> context_config(
113 new URLRequestContextConfig());
114 if (!context_config->LoadFromJSON(config_string))
xunjieli 2015/01/05 18:22:45 Hmm.. we probably should avoid doing things on the
mef 2015/01/05 19:32:41 The config used to be a member of CronetURLRequest
115 return;
116
117 CronetURLRequestContextAdapter* context_adapter =
118 reinterpret_cast<CronetURLRequestContextAdapter*>(
119 jurl_request_context_adapter);
120
121 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
122 jcaller_ref.Reset(env, jcaller);
123 base::Closure init_java_network_thread = base::Bind(&initJavaNetworkThread,
124 jcaller_ref);
125 context_adapter->InitRequestContextOnMainThread(
126 context_config.Pass(), init_java_network_thread);
127 }
128
109 } // namespace cronet 129 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698