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

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

Issue 1303493002: Make UrlRequestContextBuilder take scoped_ptr's (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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_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"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( 162 void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
163 scoped_ptr<URLRequestContextConfig> config, 163 scoped_ptr<URLRequestContextConfig> config,
164 const base::android::ScopedJavaGlobalRef<jobject>& 164 const base::android::ScopedJavaGlobalRef<jobject>&
165 jcronet_url_request_context) { 165 jcronet_url_request_context) {
166 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 166 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
167 DCHECK(!is_context_initialized_); 167 DCHECK(!is_context_initialized_);
168 DCHECK(proxy_config_service_); 168 DCHECK(proxy_config_service_);
169 // TODO(mmenke): Add method to have the builder enable SPDY. 169 // TODO(mmenke): Add method to have the builder enable SPDY.
170 net::URLRequestContextBuilder context_builder; 170 net::URLRequestContextBuilder context_builder;
171 171
172 scoped_ptr<net::NetLog> net_log(new net::NetLog); 172 net_log_.reset(new net::NetLog);
173 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate()); 173 scoped_ptr<net::NetworkDelegate> network_delegate(new BasicNetworkDelegate());
174 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 174 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
175 DCHECK(!data_reduction_proxy_); 175 DCHECK(!data_reduction_proxy_);
176 // For now, the choice to enable the data reduction proxy happens once, 176 // For now, the choice to enable the data reduction proxy happens once,
177 // at initialization. It cannot be disabled thereafter. 177 // at initialization. It cannot be disabled thereafter.
178 if (!config->data_reduction_proxy_key.empty()) { 178 if (!config->data_reduction_proxy_key.empty()) {
179 data_reduction_proxy_.reset( 179 data_reduction_proxy_.reset(new CronetDataReductionProxy(
180 new CronetDataReductionProxy( 180 config->data_reduction_proxy_key, config->data_reduction_primary_proxy,
181 config->data_reduction_proxy_key, 181 config->data_reduction_fallback_proxy,
182 config->data_reduction_primary_proxy, 182 config->data_reduction_secure_proxy_check_url, config->user_agent,
183 config->data_reduction_fallback_proxy, 183 GetNetworkTaskRunner(), net_log_.get()));
184 config->data_reduction_secure_proxy_check_url,
185 config->user_agent,
186 GetNetworkTaskRunner(),
187 net_log.get()));
188 network_delegate = 184 network_delegate =
189 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass()); 185 data_reduction_proxy_->CreateNetworkDelegate(network_delegate.Pass());
190 ScopedVector<net::URLRequestInterceptor> interceptors; 186 ScopedVector<net::URLRequestInterceptor> interceptors;
191 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); 187 interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
192 context_builder.SetInterceptors(interceptors.Pass()); 188 context_builder.SetInterceptors(interceptors.Pass());
193 } 189 }
194 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) 190 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT)
195 context_builder.set_network_delegate(network_delegate.release()); 191 context_builder.set_network_delegate(network_delegate.Pass());
196 context_builder.set_net_log(net_log.release()); 192 context_builder.set_net_log(net_log_.get());
197 context_builder.set_proxy_config_service(proxy_config_service_.release()); 193 context_builder.set_proxy_config_service(proxy_config_service_.Pass());
198 config->ConfigureURLRequestContextBuilder(&context_builder); 194 config->ConfigureURLRequestContextBuilder(&context_builder);
199 195
200 // Set up pref file if storage path is specified. 196 // Set up pref file if storage path is specified.
201 if (!config->storage_path.empty()) { 197 if (!config->storage_path.empty()) {
202 base::FilePath filepath(config->storage_path); 198 base::FilePath filepath(config->storage_path);
203 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); 199 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json"));
204 json_pref_store_ = new JsonPrefStore( 200 json_pref_store_ = new JsonPrefStore(
205 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); 201 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>());
206 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); 202 context_builder.SetFileTaskRunner(GetFileThread()->task_runner());
207 203
208 // Set up HttpServerPropertiesManager. 204 // Set up HttpServerPropertiesManager.
209 base::PrefServiceFactory factory; 205 base::PrefServiceFactory factory;
210 factory.set_user_prefs(json_pref_store_); 206 factory.set_user_prefs(json_pref_store_);
211 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple()); 207 scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple());
212 registry->RegisterDictionaryPref(kHttpServerProperties, 208 registry->RegisterDictionaryPref(kHttpServerProperties,
213 new base::DictionaryValue()); 209 new base::DictionaryValue());
214 pref_service_ = factory.Create(registry.get()).Pass(); 210 pref_service_ = factory.Create(registry.get()).Pass();
215 211
216 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager( 212 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager(
217 new net::HttpServerPropertiesManager(pref_service_.get(), 213 new net::HttpServerPropertiesManager(pref_service_.get(),
218 kHttpServerProperties, 214 kHttpServerProperties,
219 GetNetworkTaskRunner())); 215 GetNetworkTaskRunner()));
220 http_server_properties_manager->InitializeOnNetworkThread(); 216 http_server_properties_manager->InitializeOnNetworkThread();
221 http_server_properties_manager_ = http_server_properties_manager.get(); 217 http_server_properties_manager_ = http_server_properties_manager.get();
222 context_builder.SetHttpServerProperties( 218 context_builder.SetHttpServerProperties(
223 http_server_properties_manager.Pass()); 219 http_server_properties_manager.Pass());
224 } 220 }
225 221
226 context_.reset(context_builder.Build()); 222 context_ = context_builder.Build().Pass();
227 223
228 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | 224 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
229 net::LOAD_DO_NOT_SEND_COOKIES; 225 net::LOAD_DO_NOT_SEND_COOKIES;
230 if (config->load_disable_cache) 226 if (config->load_disable_cache)
231 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 227 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
232 228
233 if (config->enable_sdch) { 229 if (config->enable_sdch) {
234 DCHECK(context_->sdch_manager()); 230 DCHECK(context_->sdch_manager());
235 sdch_owner_.reset( 231 sdch_owner_.reset(
236 new net::SdchOwner(context_->sdch_manager(), context_.get())); 232 new net::SdchOwner(context_->sdch_manager(), context_.get()));
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 416 }
421 417
422 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { 418 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) {
423 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 419 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
424 // MinLogLevel is global, shared by all URLRequestContexts. 420 // MinLogLevel is global, shared by all URLRequestContexts.
425 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 421 logging::SetMinLogLevel(static_cast<int>(jlog_level));
426 return old_log_level; 422 return old_log_level;
427 } 423 }
428 424
429 } // namespace cronet 425 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698