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

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

Issue 1175733002: [Cronet] Set up HttpServerPropertiesManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: shutdown Created 5 years, 5 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"
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/prefs/pref_filter.h" 15 #include "base/prefs/pref_filter.h"
16 #include "base/prefs/pref_registry_simple.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/pref_service_factory.h"
15 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/thread_task_runner_handle.h"
16 #include "base/values.h" 21 #include "base/values.h"
17 #include "components/cronet/url_request_context_config.h" 22 #include "components/cronet/url_request_context_config.h"
18 #include "jni/CronetUrlRequestContext_jni.h" 23 #include "jni/CronetUrlRequestContext_jni.h"
19 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
20 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
21 #include "net/base/network_delegate_impl.h" 26 #include "net/base/network_delegate_impl.h"
22 #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"
23 #include "net/log/write_to_file_net_log_observer.h" 29 #include "net/log/write_to_file_net_log_observer.h"
24 #include "net/proxy/proxy_service.h" 30 #include "net/proxy/proxy_service.h"
25 #include "net/sdch/sdch_owner.h" 31 #include "net/sdch/sdch_owner.h"
26 #include "net/url_request/url_request_context.h" 32 #include "net/url_request/url_request_context.h"
27 #include "net/url_request/url_request_context_builder.h" 33 #include "net/url_request/url_request_context_builder.h"
28 #include "net/url_request/url_request_interceptor.h" 34 #include "net/url_request/url_request_interceptor.h"
29 35
30 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 36 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
31 #include "components/cronet/android/cronet_data_reduction_proxy.h" 37 #include "components/cronet/android/cronet_data_reduction_proxy.h"
32 #endif 38 #endif
33 39
34 namespace { 40 namespace {
35 41
42 const char kHttpServerProperties[] = "net.http_server_properties";
43
36 class BasicNetworkDelegate : public net::NetworkDelegateImpl { 44 class BasicNetworkDelegate : public net::NetworkDelegateImpl {
37 public: 45 public:
38 BasicNetworkDelegate() {} 46 BasicNetworkDelegate() {}
39 ~BasicNetworkDelegate() override {} 47 ~BasicNetworkDelegate() override {}
40 48
41 private: 49 private:
42 // net::NetworkDelegate implementation. 50 // net::NetworkDelegate implementation.
43 int OnBeforeURLRequest(net::URLRequest* request, 51 int OnBeforeURLRequest(net::URLRequest* request,
44 const net::CompletionCallback& callback, 52 const net::CompletionCallback& callback,
45 GURL* new_url) override { 53 GURL* new_url) override {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 context_config_(context_config.Pass()), 129 context_config_(context_config.Pass()),
122 is_context_initialized_(false), 130 is_context_initialized_(false),
123 default_load_flags_(net::LOAD_NORMAL) { 131 default_load_flags_(net::LOAD_NORMAL) {
124 base::Thread::Options options; 132 base::Thread::Options options;
125 options.message_loop_type = base::MessageLoop::TYPE_IO; 133 options.message_loop_type = base::MessageLoop::TYPE_IO;
126 network_thread_->StartWithOptions(options); 134 network_thread_->StartWithOptions(options);
127 } 135 }
128 136
129 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() { 137 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() {
130 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 138 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
139 if (pref_service_)
140 pref_service_->CommitPendingWrite();
131 StopNetLogOnNetworkThread(); 141 StopNetLogOnNetworkThread();
132 } 142 }
133 143
134 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( 144 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread(
135 JNIEnv* env, 145 JNIEnv* env,
136 jobject jcaller) { 146 jobject jcaller) {
137 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; 147 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
138 jcaller_ref.Reset(env, jcaller); 148 jcaller_ref.Reset(env, jcaller);
139 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( 149 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(
140 GetNetworkTaskRunner(), nullptr)); 150 GetNetworkTaskRunner(), nullptr));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 interceptors.push_back(data_reduction_proxy_->CreateInterceptor()); 187 interceptors.push_back(data_reduction_proxy_->CreateInterceptor());
178 context_builder.SetInterceptors(interceptors.Pass()); 188 context_builder.SetInterceptors(interceptors.Pass());
179 } 189 }
180 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) 190 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT)
181 context_builder.set_network_delegate(network_delegate.release()); 191 context_builder.set_network_delegate(network_delegate.release());
182 context_builder.set_net_log(net_log.release()); 192 context_builder.set_net_log(net_log.release());
183 context_builder.set_proxy_config_service(proxy_config_service_.release()); 193 context_builder.set_proxy_config_service(proxy_config_service_.release());
184 config->ConfigureURLRequestContextBuilder(&context_builder); 194 config->ConfigureURLRequestContextBuilder(&context_builder);
185 195
186 // Set up pref file if storage path is specified. 196 // Set up pref file if storage path is specified.
187 // TODO(xunjieli): maybe get rid of the condition on sdch. 197 if (!config->storage_path.empty()) {
188 if (!config->storage_path.empty() && config->enable_sdch) {
189 base::FilePath filepath(config->storage_path); 198 base::FilePath filepath(config->storage_path);
190 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); 199 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json"));
191 json_pref_store_ = new JsonPrefStore( 200 json_pref_store_ = new JsonPrefStore(
192 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); 201 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>());
193 json_pref_store_->ReadPrefsAsync(nullptr);
194 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); 202 context_builder.SetFileTaskRunner(GetFileThread()->task_runner());
203
204 // Set up HttpServerPropertiesManager.
205 base::PrefServiceFactory factory;
206 factory.set_user_prefs(json_pref_store_);
207 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple;
208 registry->RegisterDictionaryPref(kHttpServerProperties,
209 new base::DictionaryValue());
210 pref_service_ = factory.Create(registry.get()).Pass();
211
212 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager(
213 new net::HttpServerPropertiesManager(
214 pref_service_.get(), kHttpServerProperties,
215 base::ThreadTaskRunnerHandle::Get()));
mmenke 2015/07/07 19:18:29 You should be using GetFileThread()'s task runner
xunjieli 2015/07/07 19:37:34 Hmm.. but according to the header file, the third
mmenke 2015/07/07 20:28:12 Oops...You're right. I was thinking this was the
216 http_server_properties_manager->InitializeOnNetworkThread();
217 context_builder.SetHttpServerPropertiesManager(
218 http_server_properties_manager.Pass());
195 } 219 }
196 220
197 context_.reset(context_builder.Build()); 221 context_.reset(context_builder.Build());
198 222
199 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | 223 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
200 net::LOAD_DO_NOT_SEND_COOKIES; 224 net::LOAD_DO_NOT_SEND_COOKIES;
201 if (config->load_disable_cache) 225 if (config->load_disable_cache)
202 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 226 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
203 227
204 if (config->enable_sdch) { 228 if (config->enable_sdch) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 414 }
391 415
392 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { 416 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) {
393 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 417 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
394 // MinLogLevel is global, shared by all URLRequestContexts. 418 // MinLogLevel is global, shared by all URLRequestContexts.
395 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 419 logging::SetMinLogLevel(static_cast<int>(jlog_level));
396 return old_log_level; 420 return old_log_level;
397 } 421 }
398 422
399 } // namespace cronet 423 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698