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

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

Issue 1133883002: [Cronet] Enable persistence mode for Sdch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quic_server_remove_loop
Patch Set: Created 5 years, 7 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/prefs/pref_filter.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "components/cronet/url_request_context_config.h" 16 #include "components/cronet/url_request_context_config.h"
16 #include "jni/CronetUrlRequestContext_jni.h" 17 #include "jni/CronetUrlRequestContext_jni.h"
17 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
19 #include "net/base/network_delegate_impl.h" 20 #include "net/base/network_delegate_impl.h"
20 #include "net/http/http_auth_handler_factory.h" 21 #include "net/http/http_auth_handler_factory.h"
21 #include "net/log/write_to_file_net_log_observer.h" 22 #include "net/log/write_to_file_net_log_observer.h"
22 #include "net/proxy/proxy_service.h" 23 #include "net/proxy/proxy_service.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return false; 97 return false;
97 } 98 }
98 99
99 bool OnCanThrottleRequest(const net::URLRequest& request) const override { 100 bool OnCanThrottleRequest(const net::URLRequest& request) const override {
100 return false; 101 return false;
101 } 102 }
102 103
103 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); 104 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate);
104 }; 105 };
105 106
107 void CreatePrefFileIfNeeded(base::FilePath filepath) {
108 if (base::PathExists(filepath))
109 return;
110 base::WriteFile(filepath, "{}", 2);
mmenke 2015/05/11 17:16:19 Is this really needed? I don't see any documentat
xunjieli 2015/05/12 19:17:50 Done. Thanks! I saw an error from json pref store
111 }
112
106 } // namespace 113 } // namespace
107 114
108 namespace cronet { 115 namespace cronet {
109 116
110 // Explicitly register static JNI functions. 117 // Explicitly register static JNI functions.
111 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env) { 118 bool CronetUrlRequestContextAdapterRegisterJni(JNIEnv* env) {
112 return RegisterNativesImpl(env); 119 return RegisterNativesImpl(env);
113 } 120 }
114 121
115 CronetURLRequestContextAdapter::CronetURLRequestContextAdapter( 122 CronetURLRequestContextAdapter::CronetURLRequestContextAdapter(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 jcronet_url_request_context) { 155 jcronet_url_request_context) {
149 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 156 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
150 DCHECK(!is_context_initialized_); 157 DCHECK(!is_context_initialized_);
151 DCHECK(proxy_config_service_); 158 DCHECK(proxy_config_service_);
152 // TODO(mmenke): Add method to have the builder enable SPDY. 159 // TODO(mmenke): Add method to have the builder enable SPDY.
153 net::URLRequestContextBuilder context_builder; 160 net::URLRequestContextBuilder context_builder;
154 context_builder.set_network_delegate(new BasicNetworkDelegate()); 161 context_builder.set_network_delegate(new BasicNetworkDelegate());
155 context_builder.set_proxy_config_service(proxy_config_service_.release()); 162 context_builder.set_proxy_config_service(proxy_config_service_.release());
156 config->ConfigureURLRequestContextBuilder(&context_builder); 163 config->ConfigureURLRequestContextBuilder(&context_builder);
157 164
165 // Only set up pref file if http disk cache is enabled.
mef 2015/05/12 16:39:17 I think we should set pref file if storage_path is
xunjieli 2015/05/12 19:17:49 Done.
166 if (!config->storage_path.empty() && !config->load_disable_cache) {
167 base::FilePath filepath(config->storage_path);
168 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json"));
169 if (!file_thread_) {
170 file_thread_.reset(new base::Thread("Network File Thread"));
171 file_thread_->StartWithOptions(
172 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0));
173 }
174 file_thread_->task_runner()->PostTask(
175 FROM_HERE, base::Bind(&CreatePrefFileIfNeeded, filepath));
176 network_json_store_ = new JsonPrefStore(
177 filepath, file_thread_->task_runner(), scoped_ptr<PrefFilter>());
178 network_json_store_->ReadPrefsAsync(nullptr);
mef 2015/05/12 16:39:17 It seems that prefstore should just fallback to em
xunjieli 2015/05/12 19:17:50 Done. Yes, you and Matt are both right about this
179 context_builder.SetFileTaskRunner(file_thread_->task_runner());
180 }
181
158 context_.reset(context_builder.Build()); 182 context_.reset(context_builder.Build());
159 183
160 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | 184 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
161 net::LOAD_DO_NOT_SEND_COOKIES; 185 net::LOAD_DO_NOT_SEND_COOKIES;
162 if (config->load_disable_cache) 186 if (config->load_disable_cache)
163 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 187 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
164 188
165 if (config->enable_sdch) { 189 if (config->enable_sdch) {
166 DCHECK(context_->sdch_manager()); 190 DCHECK(context_->sdch_manager());
167 sdch_owner_.reset( 191 sdch_owner_.reset(
168 new net::SdchOwner(context_->sdch_manager(), context_.get())); 192 new net::SdchOwner(context_->sdch_manager(), context_.get()));
193 if (network_json_store_)
194 sdch_owner_->EnablePersistentStorage(network_json_store_.get());
169 } 195 }
170 196
171 // Currently (circa M39) enabling QUIC requires setting probability threshold. 197 // Currently (circa M39) enabling QUIC requires setting probability threshold.
172 if (config->enable_quic) { 198 if (config->enable_quic) {
173 context_->http_server_properties() 199 context_->http_server_properties()
174 ->SetAlternativeServiceProbabilityThreshold(0.0f); 200 ->SetAlternativeServiceProbabilityThreshold(0.0f);
175 for (auto hint = config->quic_hints.begin(); 201 for (auto hint = config->quic_hints.begin();
176 hint != config->quic_hints.end(); ++hint) { 202 hint != config->quic_hints.end(); ++hint) {
177 const URLRequestContextConfig::QuicHint& quic_hint = **hint; 203 const URLRequestContextConfig::QuicHint& quic_hint = **hint;
178 if (quic_hint.host.empty()) { 204 if (quic_hint.host.empty()) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 362 }
337 363
338 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { 364 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) {
339 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 365 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
340 // MinLogLevel is global, shared by all URLRequestContexts. 366 // MinLogLevel is global, shared by all URLRequestContexts.
341 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 367 logging::SetMinLogLevel(static_cast<int>(jlog_level));
342 return old_log_level; 368 return old_log_level;
343 } 369 }
344 370
345 } // namespace cronet 371 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698