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

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

Issue 981013002: [Cronet] Make sure to only pass the application Context to InitApplicationContext to avoid DCHECK fa (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add ChromiumUrlRequestContext test too Created 5 years, 9 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
« no previous file with comments | « no previous file | components/cronet/android/cronet_library_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chromium_url_request_context.h" 5 #include "components/cronet/android/chromium_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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 namespace cronet { 56 namespace cronet {
57 57
58 // Explicitly register static JNI functions. 58 // Explicitly register static JNI functions.
59 bool ChromiumUrlRequestContextRegisterJni(JNIEnv* env) { 59 bool ChromiumUrlRequestContextRegisterJni(JNIEnv* env) {
60 return RegisterNativesImpl(env); 60 return RegisterNativesImpl(env);
61 } 61 }
62 62
63 // Sets global user-agent to be used for all subsequent requests. 63 // Sets global user-agent to be used for all subsequent requests.
64 static jlong CreateRequestContextAdapter(JNIEnv* env, 64 static jlong CreateRequestContextAdapter(JNIEnv* env,
65 jobject jcaller, 65 jobject jcaller,
66 jobject jcontext, 66 jobject japp_context,
67 jstring juser_agent, 67 jstring juser_agent,
68 jint jlog_level, 68 jint jlog_level,
69 jstring jconfig) { 69 jstring jconfig) {
70 std::string user_agent = ConvertJavaStringToUTF8(env, juser_agent); 70 std::string user_agent = ConvertJavaStringToUTF8(env, juser_agent);
71 71
72 std::string config = ConvertJavaStringToUTF8(env, jconfig); 72 std::string config = ConvertJavaStringToUTF8(env, jconfig);
73 73
74 scoped_ptr<base::Value> config_value(base::JSONReader::Read(config)); 74 scoped_ptr<base::Value> config_value(base::JSONReader::Read(config));
75 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { 75 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) {
76 DLOG(ERROR) << "Bad JSON: " << config; 76 DLOG(ERROR) << "Bad JSON: " << config;
77 return 0; 77 return 0;
78 } 78 }
79 79
80 scoped_ptr<URLRequestContextConfig> context_config( 80 scoped_ptr<URLRequestContextConfig> context_config(
81 new URLRequestContextConfig()); 81 new URLRequestContextConfig());
82 base::JSONValueConverter<URLRequestContextConfig> converter; 82 base::JSONValueConverter<URLRequestContextConfig> converter;
83 if (!converter.Convert(*config_value, context_config.get())) { 83 if (!converter.Convert(*config_value, context_config.get())) {
84 DLOG(ERROR) << "Bad Config: " << config_value; 84 DLOG(ERROR) << "Bad Config: " << config_value;
85 return 0; 85 return 0;
86 } 86 }
87 87
88 // Set application context. 88 // Set application context.
89 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, jcontext); 89 base::android::ScopedJavaLocalRef<jobject> scoped_app_context(env,
90 base::android::InitApplicationContext(env, scoped_context); 90 japp_context);
91 base::android::InitApplicationContext(env, scoped_app_context);
91 92
92 // TODO(mef): MinLogLevel is global, shared by all URLRequestContexts. 93 // TODO(mef): MinLogLevel is global, shared by all URLRequestContexts.
93 // Revisit this if each URLRequestContext would need an individual log level. 94 // Revisit this if each URLRequestContext would need an individual log level.
94 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 95 logging::SetMinLogLevel(static_cast<int>(jlog_level));
95 96
96 // TODO(dplotnikov): set application context. 97 // TODO(dplotnikov): set application context.
97 URLRequestContextAdapter* context_adapter = new URLRequestContextAdapter( 98 URLRequestContextAdapter* context_adapter = new URLRequestContextAdapter(
98 new JniURLRequestContextAdapterDelegate(env, jcaller), user_agent); 99 new JniURLRequestContextAdapterDelegate(env, jcaller), user_agent);
99 context_adapter->AddRef(); // Hold onto this ref-counted object. 100 context_adapter->AddRef(); // Hold onto this ref-counted object.
100 context_adapter->Initialize(context_config.Pass()); 101 context_adapter->Initialize(context_config.Pass());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // Called on application's main Java thread. 154 // Called on application's main Java thread.
154 static void InitRequestContextOnMainThread(JNIEnv* env, 155 static void InitRequestContextOnMainThread(JNIEnv* env,
155 jobject jcaller, 156 jobject jcaller,
156 jlong jurl_request_context_adapter) { 157 jlong jurl_request_context_adapter) {
157 URLRequestContextAdapter* context_adapter = 158 URLRequestContextAdapter* context_adapter =
158 reinterpret_cast<URLRequestContextAdapter*>(jurl_request_context_adapter); 159 reinterpret_cast<URLRequestContextAdapter*>(jurl_request_context_adapter);
159 context_adapter->InitRequestContextOnMainThread(); 160 context_adapter->InitRequestContextOnMainThread();
160 } 161 }
161 162
162 } // namespace cronet 163 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | components/cronet/android/cronet_library_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698