OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/browser_state/chrome_browser_state_impl_io_data.h" | 5 #include "ios/chrome/browser/browser_state/chrome_browser_state_impl_io_data.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 182 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
183 DCHECK(!io_data_->lazy_params_); | 183 DCHECK(!io_data_->lazy_params_); |
184 | 184 |
185 LazyParams* lazy_params = new LazyParams(); | 185 LazyParams* lazy_params = new LazyParams(); |
186 | 186 |
187 lazy_params->cookie_path = cookie_path; | 187 lazy_params->cookie_path = cookie_path; |
188 lazy_params->channel_id_path = channel_id_path; | 188 lazy_params->channel_id_path = channel_id_path; |
189 lazy_params->cache_path = cache_path; | 189 lazy_params->cache_path = cache_path; |
190 lazy_params->cache_max_size = cache_max_size; | 190 lazy_params->cache_max_size = cache_max_size; |
191 io_data_->lazy_params_.reset(lazy_params); | 191 io_data_->lazy_params_.reset(lazy_params); |
192 | |
193 // Keep track of profile path and cache sizes separately so we can use them | |
194 // on demand when creating storage isolated URLRequestContextGetters. | |
195 io_data_->profile_path_ = profile_path; | 192 io_data_->profile_path_ = profile_path; |
196 io_data_->app_cache_max_size_ = cache_max_size; | |
197 | 193 |
198 io_data_->InitializeMetricsEnabledStateOnUIThread(); | 194 io_data_->InitializeMetricsEnabledStateOnUIThread(); |
199 | 195 |
200 // TODO(tbansal): Move this to IO thread once the data reduction proxy | 196 // TODO(tbansal): Move this to IO thread once the data reduction proxy |
201 // params are unified into a single object. | 197 // params are unified into a single object. |
202 bool enable_quic_for_data_reduction_proxy = | 198 bool enable_quic_for_data_reduction_proxy = |
203 IOSChromeIOThread::ShouldEnableQuicForDataReductionProxy(); | 199 IOSChromeIOThread::ShouldEnableQuicForDataReductionProxy(); |
204 | 200 |
205 io_data_->set_data_reduction_proxy_io_data( | 201 io_data_->set_data_reduction_proxy_io_data( |
206 CreateIOSChromeDataReductionProxyIOData( | 202 CreateIOSChromeDataReductionProxyIOData( |
(...skipping 25 matching lines...) Expand all Loading... |
232 IOSChromeIOThread* io_thread) const { | 228 IOSChromeIOThread* io_thread) const { |
233 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 229 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
234 LazyInitialize(); | 230 LazyInitialize(); |
235 DCHECK(!main_request_context_getter_.get()); | 231 DCHECK(!main_request_context_getter_.get()); |
236 main_request_context_getter_ = | 232 main_request_context_getter_ = |
237 IOSChromeURLRequestContextGetter::Create(io_data_, protocol_handlers); | 233 IOSChromeURLRequestContextGetter::Create(io_data_, protocol_handlers); |
238 | 234 |
239 return main_request_context_getter_; | 235 return main_request_context_getter_; |
240 } | 236 } |
241 | 237 |
242 scoped_refptr<IOSChromeURLRequestContextGetter> | |
243 ChromeBrowserStateImplIOData::Handle::CreateIsolatedAppRequestContextGetter( | |
244 const base::FilePath& partition_path) const { | |
245 DCHECK_CURRENTLY_ON(web::WebThread::UI); | |
246 // Check that the partition_path is not the same as the base profile path. We | |
247 // expect isolated partition, which will never go to the default profile path. | |
248 CHECK(partition_path != browser_state_->GetStatePath()); | |
249 LazyInitialize(); | |
250 | |
251 // Keep a map of request context getters, one per requested storage partition. | |
252 IOSChromeURLRequestContextGetterMap::iterator iter = | |
253 app_request_context_getter_map_.find(partition_path); | |
254 if (iter != app_request_context_getter_map_.end()) | |
255 return iter->second; | |
256 | |
257 IOSChromeURLRequestContextGetter* context = | |
258 IOSChromeURLRequestContextGetter::CreateForIsolatedApp( | |
259 browser_state_->GetRequestContext(), io_data_, partition_path); | |
260 app_request_context_getter_map_[partition_path] = context; | |
261 return context; | |
262 } | |
263 | |
264 ChromeBrowserStateIOData* ChromeBrowserStateImplIOData::Handle::io_data() | 238 ChromeBrowserStateIOData* ChromeBrowserStateImplIOData::Handle::io_data() |
265 const { | 239 const { |
266 LazyInitialize(); | 240 LazyInitialize(); |
267 return io_data_; | 241 return io_data_; |
268 } | 242 } |
269 | 243 |
270 void ChromeBrowserStateImplIOData::Handle::ClearNetworkingHistorySince( | 244 void ChromeBrowserStateImplIOData::Handle::ClearNetworkingHistorySince( |
271 base::Time time, | 245 base::Time time, |
272 const base::Closure& completion) { | 246 const base::Closure& completion) { |
273 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 247 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
(...skipping 25 matching lines...) Expand all Loading... |
299 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)); | 273 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)); |
300 io_data_->InitializeOnUIThread(browser_state_); | 274 io_data_->InitializeOnUIThread(browser_state_); |
301 } | 275 } |
302 | 276 |
303 scoped_ptr<ChromeBrowserStateIOData::IOSChromeURLRequestContextGetterVector> | 277 scoped_ptr<ChromeBrowserStateIOData::IOSChromeURLRequestContextGetterVector> |
304 ChromeBrowserStateImplIOData::Handle::GetAllContextGetters() { | 278 ChromeBrowserStateImplIOData::Handle::GetAllContextGetters() { |
305 IOSChromeURLRequestContextGetterMap::iterator iter; | 279 IOSChromeURLRequestContextGetterMap::iterator iter; |
306 scoped_ptr<IOSChromeURLRequestContextGetterVector> context_getters( | 280 scoped_ptr<IOSChromeURLRequestContextGetterVector> context_getters( |
307 new IOSChromeURLRequestContextGetterVector()); | 281 new IOSChromeURLRequestContextGetterVector()); |
308 | 282 |
309 iter = app_request_context_getter_map_.begin(); | |
310 for (; iter != app_request_context_getter_map_.end(); ++iter) | |
311 context_getters->push_back(iter->second); | |
312 | |
313 if (main_request_context_getter_.get()) | 283 if (main_request_context_getter_.get()) |
314 context_getters->push_back(main_request_context_getter_); | 284 context_getters->push_back(main_request_context_getter_); |
315 | 285 |
316 return context_getters; | 286 return context_getters; |
317 } | 287 } |
318 | 288 |
319 ChromeBrowserStateImplIOData::LazyParams::LazyParams() : cache_max_size(0) {} | 289 ChromeBrowserStateImplIOData::LazyParams::LazyParams() : cache_max_size(0) {} |
320 | 290 |
321 ChromeBrowserStateImplIOData::LazyParams::~LazyParams() {} | 291 ChromeBrowserStateImplIOData::LazyParams::~LazyParams() {} |
322 | 292 |
323 ChromeBrowserStateImplIOData::ChromeBrowserStateImplIOData() | 293 ChromeBrowserStateImplIOData::ChromeBrowserStateImplIOData() |
324 : ChromeBrowserStateIOData( | 294 : ChromeBrowserStateIOData( |
325 ios::ChromeBrowserStateType::REGULAR_BROWSER_STATE), | 295 ios::ChromeBrowserStateType::REGULAR_BROWSER_STATE), |
326 http_server_properties_manager_(nullptr), | 296 http_server_properties_manager_(nullptr) {} |
327 app_cache_max_size_(0) {} | |
328 | 297 |
329 ChromeBrowserStateImplIOData::~ChromeBrowserStateImplIOData() {} | 298 ChromeBrowserStateImplIOData::~ChromeBrowserStateImplIOData() {} |
330 | 299 |
331 void ChromeBrowserStateImplIOData::InitializeInternal( | 300 void ChromeBrowserStateImplIOData::InitializeInternal( |
332 scoped_ptr<IOSChromeNetworkDelegate> chrome_network_delegate, | 301 scoped_ptr<IOSChromeNetworkDelegate> chrome_network_delegate, |
333 ProfileParams* profile_params, | 302 ProfileParams* profile_params, |
334 ProtocolHandlerMap* protocol_handlers) const { | 303 ProtocolHandlerMap* protocol_handlers) const { |
335 // Set up a persistent store for use by the network stack on the IO thread. | 304 // Set up a persistent store for use by the network stack on the IO thread. |
336 base::FilePath network_json_store_filepath( | 305 base::FilePath network_json_store_filepath( |
337 profile_path_.Append(kIOSChromeNetworkPersistentStateFilename)); | 306 profile_path_.Append(kIOSChromeNetworkPersistentStateFilename)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // Setup SDCH for this profile. | 411 // Setup SDCH for this profile. |
443 sdch_manager_.reset(new net::SdchManager); | 412 sdch_manager_.reset(new net::SdchManager); |
444 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); | 413 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); |
445 main_context->set_sdch_manager(sdch_manager_.get()); | 414 main_context->set_sdch_manager(sdch_manager_.get()); |
446 sdch_policy_->EnablePersistentStorage( | 415 sdch_policy_->EnablePersistentStorage( |
447 make_scoped_ptr(new SdchOwnerPrefStorage(network_json_store_.get()))); | 416 make_scoped_ptr(new SdchOwnerPrefStorage(network_json_store_.get()))); |
448 | 417 |
449 lazy_params_.reset(); | 418 lazy_params_.reset(); |
450 } | 419 } |
451 | 420 |
452 net::URLRequestContext* | |
453 ChromeBrowserStateImplIOData::InitializeAppRequestContext( | |
454 net::URLRequestContext* main_context) const { | |
455 // Copy most state from the main context. | |
456 AppRequestContext* context = new AppRequestContext(); | |
457 context->CopyFrom(main_context); | |
458 | |
459 // Use a separate HTTP disk cache for isolated apps. | |
460 scoped_ptr<net::HttpCache::BackendFactory> app_backend = | |
461 net::HttpCache::DefaultBackend::InMemory(0); | |
462 scoped_ptr<net::HttpCache> app_http_cache = | |
463 CreateHttpFactory(http_network_session_.get(), std::move(app_backend)); | |
464 | |
465 cookie_util::CookieStoreConfig ios_cookie_config( | |
466 base::FilePath(), | |
467 cookie_util::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, | |
468 cookie_util::CookieStoreConfig::COOKIE_STORE_IOS, nullptr); | |
469 scoped_refptr<net::CookieStore> cookie_store = | |
470 cookie_util::CreateCookieStore(ios_cookie_config); | |
471 | |
472 // Transfer ownership of the cookies and cache to AppRequestContext. | |
473 context->SetCookieStore(cookie_store.get()); | |
474 context->SetHttpTransactionFactory(std::move(app_http_cache)); | |
475 | |
476 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | |
477 new net::URLRequestJobFactoryImpl()); | |
478 // The data reduction proxy interceptor should be as close to the network as | |
479 // possible. | |
480 URLRequestInterceptorScopedVector request_interceptors; | |
481 request_interceptors.insert( | |
482 request_interceptors.begin(), | |
483 data_reduction_proxy_io_data()->CreateInterceptor().release()); | |
484 scoped_ptr<net::URLRequestJobFactory> top_job_factory(SetUpJobFactoryDefaults( | |
485 std::move(job_factory), std::move(request_interceptors), | |
486 main_context->network_delegate())); | |
487 context->SetJobFactory(std::move(top_job_factory)); | |
488 | |
489 return context; | |
490 } | |
491 | |
492 net::URLRequestContext* | |
493 ChromeBrowserStateImplIOData::AcquireIsolatedAppRequestContext( | |
494 net::URLRequestContext* main_context) const { | |
495 // We create per-app contexts on demand, unlike the others above. | |
496 net::URLRequestContext* app_request_context = | |
497 InitializeAppRequestContext(main_context); | |
498 DCHECK(app_request_context); | |
499 return app_request_context; | |
500 } | |
501 | |
502 void ChromeBrowserStateImplIOData::ClearNetworkingHistorySinceOnIOThread( | 421 void ChromeBrowserStateImplIOData::ClearNetworkingHistorySinceOnIOThread( |
503 base::Time time, | 422 base::Time time, |
504 const base::Closure& completion) { | 423 const base::Closure& completion) { |
505 DCHECK_CURRENTLY_ON(web::WebThread::IO); | 424 DCHECK_CURRENTLY_ON(web::WebThread::IO); |
506 DCHECK(initialized()); | 425 DCHECK(initialized()); |
507 | 426 |
508 DCHECK(transport_security_state()); | 427 DCHECK(transport_security_state()); |
509 // Completes synchronously. | 428 // Completes synchronously. |
510 transport_security_state()->DeleteAllDynamicDataSince(time); | 429 transport_security_state()->DeleteAllDynamicDataSince(time); |
511 DCHECK(http_server_properties_manager_); | 430 DCHECK(http_server_properties_manager_); |
512 http_server_properties_manager_->Clear(completion); | 431 http_server_properties_manager_->Clear(completion); |
513 } | 432 } |
OLD | NEW |