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

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

Issue 1318573006: [Cronet] Add support for Proxy Auto Config (PAC) script (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 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 | no next file » | 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/cronet_url_request_context_adapter.h" 5 #include "components/cronet/android/cronet_url_request_context_adapter.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_file.h" 11 #include "base/files/scoped_file.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/prefs/pref_filter.h" 15 #include "base/prefs/pref_filter.h"
16 #include "base/prefs/pref_registry_simple.h" 16 #include "base/prefs/pref_registry_simple.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/pref_service_factory.h" 18 #include "base/prefs/pref_service_factory.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "components/cronet/url_request_context_config.h" 22 #include "components/cronet/url_request_context_config.h"
23 #include "jni/CronetUrlRequestContext_jni.h" 23 #include "jni/CronetUrlRequestContext_jni.h"
24 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
25 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
26 #include "net/base/network_delegate_impl.h" 26 #include "net/base/network_delegate_impl.h"
27 #include "net/http/http_auth_handler_factory.h" 27 #include "net/http/http_auth_handler_factory.h"
28 #include "net/http/http_server_properties_manager.h" 28 #include "net/http/http_server_properties_manager.h"
29 #include "net/log/write_to_file_net_log_observer.h" 29 #include "net/log/write_to_file_net_log_observer.h"
30 #include "net/proxy/proxy_config_service_android.h"
30 #include "net/proxy/proxy_service.h" 31 #include "net/proxy/proxy_service.h"
31 #include "net/sdch/sdch_owner.h" 32 #include "net/sdch/sdch_owner.h"
32 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
33 #include "net/url_request/url_request_context_builder.h" 34 #include "net/url_request/url_request_context_builder.h"
34 #include "net/url_request/url_request_interceptor.h" 35 #include "net/url_request/url_request_interceptor.h"
35 36
36 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 37 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
37 #include "components/cronet/android/cronet_data_reduction_proxy.h" 38 #include "components/cronet/android/cronet_data_reduction_proxy.h"
38 #endif 39 #endif
39 40
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 if (pref_service_) 141 if (pref_service_)
141 pref_service_->CommitPendingWrite(); 142 pref_service_->CommitPendingWrite();
142 StopNetLogOnNetworkThread(); 143 StopNetLogOnNetworkThread();
143 } 144 }
144 145
145 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( 146 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread(
146 JNIEnv* env, 147 JNIEnv* env,
147 jobject jcaller) { 148 jobject jcaller) {
148 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; 149 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
149 jcaller_ref.Reset(env, jcaller); 150 jcaller_ref.Reset(env, jcaller);
150 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( 151 net::ProxyConfigServiceAndroid* android_proxy_config_service =
151 GetNetworkTaskRunner(), nullptr)); 152 static_cast<net::ProxyConfigServiceAndroid*>(
153 net::ProxyService::CreateSystemProxyConfigService(
154 GetNetworkTaskRunner(), nullptr /* Ignored on Android */));
155 // If a PAC URL is present, ignore it and use the address and port of
156 // Android system's local HTTP proxy server. See: crbug.com/432539.
157 android_proxy_config_service->set_exclude_pac_url(true);
158 proxy_config_service_.reset(android_proxy_config_service);
152 GetNetworkTaskRunner()->PostTask( 159 GetNetworkTaskRunner()->PostTask(
153 FROM_HERE, 160 FROM_HERE,
154 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, 161 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread,
155 base::Unretained(this), Passed(&context_config_), 162 base::Unretained(this), Passed(&context_config_),
156 jcaller_ref)); 163 jcaller_ref));
157 } 164 }
158 165
159 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( 166 void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
160 scoped_ptr<URLRequestContextConfig> config, 167 scoped_ptr<URLRequestContextConfig> config,
161 const base::android::ScopedJavaGlobalRef<jobject>& 168 const base::android::ScopedJavaGlobalRef<jobject>&
(...skipping 18 matching lines...) Expand all
180 GetNetworkTaskRunner(), net_log_.get())); 187 GetNetworkTaskRunner(), net_log_.get()));
181 network_delegate = 188 network_delegate =
182 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); 189 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass());
183 ScopedVector<net::URLRequestInterceptor> interceptors; 190 ScopedVector<net::URLRequestInterceptor> interceptors;
184 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); 191 interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
185 context_builder.SetInterceptors(interceptors.Pass()); 192 context_builder.SetInterceptors(interceptors.Pass());
186 } 193 }
187 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) 194 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT)
188 context_builder.set_network_delegate(network_delegate.Pass()); 195 context_builder.set_network_delegate(network_delegate.Pass());
189 context_builder.set_net_log(net_log_.get()); 196 context_builder.set_net_log(net_log_.get());
190 context_builder.set_proxy_config_service(proxy_config_service_.Pass()); 197
198 // Android provides a local HTTP proxy server that handles proxying when a PAC
199 // URL is present. Create a proxy service without a resolver and rely on this
200 // local HTTP proxy. See: crbug.com/432539.
201 context_builder.set_proxy_service(
202 net::ProxyService::CreateWithoutProxyResolver(
203 proxy_config_service_.release(), net_log_.get()));
191 config->ConfigureURLRequestContextBuilder(&context_builder); 204 config->ConfigureURLRequestContextBuilder(&context_builder);
192 205
193 // Set up pref file if storage path is specified. 206 // Set up pref file if storage path is specified.
194 if (!config->storage_path.empty()) { 207 if (!config->storage_path.empty()) {
195 base::FilePath filepath(config->storage_path); 208 base::FilePath filepath(config->storage_path);
196 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); 209 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json"));
197 json_pref_store_ = new JsonPrefStore( 210 json_pref_store_ = new JsonPrefStore(
198 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); 211 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>());
199 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); 212 context_builder.SetFileTaskRunner(GetFileThread()->task_runner());
200 213
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 static jint SetMinLogLevel(JNIEnv* env, 428 static jint SetMinLogLevel(JNIEnv* env,
416 const JavaParamRef<jclass>& jcaller, 429 const JavaParamRef<jclass>& jcaller,
417 jint jlog_level) { 430 jint jlog_level) {
418 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 431 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
419 // MinLogLevel is global, shared by all URLRequestContexts. 432 // MinLogLevel is global, shared by all URLRequestContexts.
420 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 433 logging::SetMinLogLevel(static_cast<int>(jlog_level));
421 return old_log_level; 434 return old_log_level;
422 } 435 }
423 436
424 } // namespace cronet 437 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698