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

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 Matt'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 27 matching lines...) Expand all
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;
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(context_config.Pass());
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 if (jurl_request_context_adapter == 0)
103 return;
104
105 CronetURLRequestContextAdapter* context_adapter =
106 reinterpret_cast<CronetURLRequestContextAdapter*>(
107 jurl_request_context_adapter);
108
109 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
110 jcaller_ref.Reset(env, jcaller);
111 base::Closure init_java_network_thread = base::Bind(&initJavaNetworkThread,
112 jcaller_ref);
113 context_adapter->InitRequestContextOnMainThread(init_java_network_thread);
114 }
115
109 } // namespace cronet 116 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698