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

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

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

Powered by Google App Engine
This is Rietveld 408576698