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

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

Issue 1507783002: Revert of [Cronet] Remove JSON serialization of CronetEngine.Builder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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( 64 static jlong CreateRequestContextAdapter(
65 JNIEnv* env, 65 JNIEnv* env,
66 const JavaParamRef<jobject>& jcaller, 66 const JavaParamRef<jobject>& jcaller,
67 const JavaParamRef<jstring>& juser_agent, 67 const JavaParamRef<jstring>& juser_agent,
68 jint jlog_level, 68 jint jlog_level,
69 jlong jconfig) { 69 const JavaParamRef<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);
73
74 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config);
75 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) {
76 DLOG(ERROR) << "Bad JSON: " << config;
77 return 0;
78 }
79
72 scoped_ptr<URLRequestContextConfig> context_config( 80 scoped_ptr<URLRequestContextConfig> context_config(
73 reinterpret_cast<URLRequestContextConfig*>(jconfig)); 81 new URLRequestContextConfig());
82 base::JSONValueConverter<URLRequestContextConfig> converter;
83 if (!converter.Convert(*config_value, context_config.get())) {
84 DLOG(ERROR) << "Bad Config: " << config_value;
85 return 0;
86 }
74 87
75 // TODO(mef): MinLogLevel is global, shared by all URLRequestContexts. 88 // TODO(mef): MinLogLevel is global, shared by all URLRequestContexts.
76 // Revisit this if each URLRequestContext would need an individual log level. 89 // Revisit this if each URLRequestContext would need an individual log level.
77 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 90 logging::SetMinLogLevel(static_cast<int>(jlog_level));
78 91
79 // TODO(dplotnikov): set application context. 92 // TODO(dplotnikov): set application context.
80 URLRequestContextAdapter* context_adapter = new URLRequestContextAdapter( 93 URLRequestContextAdapter* context_adapter = new URLRequestContextAdapter(
81 new JniURLRequestContextAdapterDelegate(env, jcaller), user_agent); 94 new JniURLRequestContextAdapterDelegate(env, jcaller), user_agent);
82 context_adapter->AddRef(); // Hold onto this ref-counted object. 95 context_adapter->AddRef(); // Hold onto this ref-counted object.
83 context_adapter->Initialize(context_config.Pass()); 96 context_adapter->Initialize(context_config.Pass());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // Called on application's main Java thread. 152 // Called on application's main Java thread.
140 static void InitRequestContextOnMainThread(JNIEnv* env, 153 static void InitRequestContextOnMainThread(JNIEnv* env,
141 const JavaParamRef<jobject>& jcaller, 154 const JavaParamRef<jobject>& jcaller,
142 jlong jurl_request_context_adapter) { 155 jlong jurl_request_context_adapter) {
143 URLRequestContextAdapter* context_adapter = 156 URLRequestContextAdapter* context_adapter =
144 reinterpret_cast<URLRequestContextAdapter*>(jurl_request_context_adapter); 157 reinterpret_cast<URLRequestContextAdapter*>(jurl_request_context_adapter);
145 context_adapter->InitRequestContextOnMainThread(); 158 context_adapter->InitRequestContextOnMainThread();
146 } 159 }
147 160
148 } // namespace cronet 161 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698