| 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 <memory> |
| 7 #include <set> | 8 #include <set> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
| 17 #include "components/cookie_config/cookie_store_util.h" | 18 #include "components/cookie_config/cookie_store_util.h" |
| 18 #include "components/net_log/chrome_net_log.h" | 19 #include "components/net_log/chrome_net_log.h" |
| 19 #include "components/prefs/json_pref_store.h" | 20 #include "components/prefs/json_pref_store.h" |
| 20 #include "components/prefs/pref_filter.h" | 21 #include "components/prefs/pref_filter.h" |
| 21 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
| 22 #include "ios/chrome/browser/application_context.h" | 23 #include "ios/chrome/browser/application_context.h" |
| 23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 24 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return result_value->GetAsDictionary(result); | 97 return result_value->GetAsDictionary(result); |
| 97 } | 98 } |
| 98 | 99 |
| 99 bool GetMutableValue(base::DictionaryValue** result) override { | 100 bool GetMutableValue(base::DictionaryValue** result) override { |
| 100 base::Value* result_value = nullptr; | 101 base::Value* result_value = nullptr; |
| 101 if (!storage_->GetMutableValue(storage_key_, &result_value)) | 102 if (!storage_->GetMutableValue(storage_key_, &result_value)) |
| 102 return false; | 103 return false; |
| 103 return result_value->GetAsDictionary(result); | 104 return result_value->GetAsDictionary(result); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void SetValue(scoped_ptr<base::DictionaryValue> value) override { | 107 void SetValue(std::unique_ptr<base::DictionaryValue> value) override { |
| 107 storage_->SetValue(storage_key_, std::move(value), | 108 storage_->SetValue(storage_key_, std::move(value), |
| 108 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 109 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void ReportValueChanged() override { | 112 void ReportValueChanged() override { |
| 112 storage_->ReportValueChanged(storage_key_, | 113 storage_->ReportValueChanged(storage_key_, |
| 113 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 114 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 114 } | 115 } |
| 115 | 116 |
| 116 bool IsInitializationComplete() override { | 117 bool IsInitializationComplete() override { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 254 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
| 254 if (initialized_) | 255 if (initialized_) |
| 255 return; | 256 return; |
| 256 | 257 |
| 257 // Set initialized_ to true at the beginning in case any of the objects | 258 // Set initialized_ to true at the beginning in case any of the objects |
| 258 // below try to get the ResourceContext pointer. | 259 // below try to get the ResourceContext pointer. |
| 259 initialized_ = true; | 260 initialized_ = true; |
| 260 PrefService* pref_service = browser_state_->GetPrefs(); | 261 PrefService* pref_service = browser_state_->GetPrefs(); |
| 261 io_data_->http_server_properties_manager_ = | 262 io_data_->http_server_properties_manager_ = |
| 262 HttpServerPropertiesManagerFactory::CreateManager(pref_service); | 263 HttpServerPropertiesManagerFactory::CreateManager(pref_service); |
| 263 io_data_->set_http_server_properties(scoped_ptr<net::HttpServerProperties>( | 264 io_data_->set_http_server_properties( |
| 264 io_data_->http_server_properties_manager_)); | 265 std::unique_ptr<net::HttpServerProperties>( |
| 266 io_data_->http_server_properties_manager_)); |
| 265 io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, | 267 io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, |
| 266 pref_service); | 268 pref_service); |
| 267 io_data_->safe_browsing_enabled()->MoveToThread( | 269 io_data_->safe_browsing_enabled()->MoveToThread( |
| 268 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)); | 270 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)); |
| 269 io_data_->InitializeOnUIThread(browser_state_); | 271 io_data_->InitializeOnUIThread(browser_state_); |
| 270 } | 272 } |
| 271 | 273 |
| 272 scoped_ptr<ChromeBrowserStateIOData::IOSChromeURLRequestContextGetterVector> | 274 std::unique_ptr< |
| 275 ChromeBrowserStateIOData::IOSChromeURLRequestContextGetterVector> |
| 273 ChromeBrowserStateImplIOData::Handle::GetAllContextGetters() { | 276 ChromeBrowserStateImplIOData::Handle::GetAllContextGetters() { |
| 274 IOSChromeURLRequestContextGetterMap::iterator iter; | 277 IOSChromeURLRequestContextGetterMap::iterator iter; |
| 275 scoped_ptr<IOSChromeURLRequestContextGetterVector> context_getters( | 278 std::unique_ptr<IOSChromeURLRequestContextGetterVector> context_getters( |
| 276 new IOSChromeURLRequestContextGetterVector()); | 279 new IOSChromeURLRequestContextGetterVector()); |
| 277 | 280 |
| 278 iter = app_request_context_getter_map_.begin(); | 281 iter = app_request_context_getter_map_.begin(); |
| 279 for (; iter != app_request_context_getter_map_.end(); ++iter) | 282 for (; iter != app_request_context_getter_map_.end(); ++iter) |
| 280 context_getters->push_back(iter->second); | 283 context_getters->push_back(iter->second); |
| 281 | 284 |
| 282 if (main_request_context_getter_.get()) | 285 if (main_request_context_getter_.get()) |
| 283 context_getters->push_back(main_request_context_getter_); | 286 context_getters->push_back(main_request_context_getter_); |
| 284 | 287 |
| 285 return context_getters; | 288 return context_getters; |
| 286 } | 289 } |
| 287 | 290 |
| 288 ChromeBrowserStateImplIOData::LazyParams::LazyParams() : cache_max_size(0) {} | 291 ChromeBrowserStateImplIOData::LazyParams::LazyParams() : cache_max_size(0) {} |
| 289 | 292 |
| 290 ChromeBrowserStateImplIOData::LazyParams::~LazyParams() {} | 293 ChromeBrowserStateImplIOData::LazyParams::~LazyParams() {} |
| 291 | 294 |
| 292 ChromeBrowserStateImplIOData::ChromeBrowserStateImplIOData() | 295 ChromeBrowserStateImplIOData::ChromeBrowserStateImplIOData() |
| 293 : ChromeBrowserStateIOData( | 296 : ChromeBrowserStateIOData( |
| 294 ios::ChromeBrowserStateType::REGULAR_BROWSER_STATE), | 297 ios::ChromeBrowserStateType::REGULAR_BROWSER_STATE), |
| 295 http_server_properties_manager_(nullptr), | 298 http_server_properties_manager_(nullptr), |
| 296 app_cache_max_size_(0) {} | 299 app_cache_max_size_(0) {} |
| 297 | 300 |
| 298 ChromeBrowserStateImplIOData::~ChromeBrowserStateImplIOData() {} | 301 ChromeBrowserStateImplIOData::~ChromeBrowserStateImplIOData() {} |
| 299 | 302 |
| 300 void ChromeBrowserStateImplIOData::InitializeInternal( | 303 void ChromeBrowserStateImplIOData::InitializeInternal( |
| 301 scoped_ptr<IOSChromeNetworkDelegate> chrome_network_delegate, | 304 std::unique_ptr<IOSChromeNetworkDelegate> chrome_network_delegate, |
| 302 ProfileParams* profile_params, | 305 ProfileParams* profile_params, |
| 303 ProtocolHandlerMap* protocol_handlers) const { | 306 ProtocolHandlerMap* protocol_handlers) const { |
| 304 // Set up a persistent store for use by the network stack on the IO thread. | 307 // Set up a persistent store for use by the network stack on the IO thread. |
| 305 base::FilePath network_json_store_filepath( | 308 base::FilePath network_json_store_filepath( |
| 306 profile_path_.Append(kIOSChromeNetworkPersistentStateFilename)); | 309 profile_path_.Append(kIOSChromeNetworkPersistentStateFilename)); |
| 307 network_json_store_ = new JsonPrefStore( | 310 network_json_store_ = new JsonPrefStore( |
| 308 network_json_store_filepath, | 311 network_json_store_filepath, |
| 309 JsonPrefStore::GetTaskRunnerForFile(network_json_store_filepath, | 312 JsonPrefStore::GetTaskRunnerForFile(network_json_store_filepath, |
| 310 web::WebThread::GetBlockingPool()), | 313 web::WebThread::GetBlockingPool()), |
| 311 scoped_ptr<PrefFilter>()); | 314 std::unique_ptr<PrefFilter>()); |
| 312 network_json_store_->ReadPrefsAsync(nullptr); | 315 network_json_store_->ReadPrefsAsync(nullptr); |
| 313 | 316 |
| 314 net::URLRequestContext* main_context = main_request_context(); | 317 net::URLRequestContext* main_context = main_request_context(); |
| 315 | 318 |
| 316 IOSChromeIOThread* const io_thread = profile_params->io_thread; | 319 IOSChromeIOThread* const io_thread = profile_params->io_thread; |
| 317 IOSChromeIOThread::Globals* const io_thread_globals = io_thread->globals(); | 320 IOSChromeIOThread::Globals* const io_thread_globals = io_thread->globals(); |
| 318 | 321 |
| 319 ApplyProfileParamsToContext(main_context); | 322 ApplyProfileParamsToContext(main_context); |
| 320 | 323 |
| 321 if (http_server_properties_manager_) | 324 if (http_server_properties_manager_) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 web::WebThread::GetBlockingPool()->GetSequenceToken())); | 373 web::WebThread::GetBlockingPool()->GetSequenceToken())); |
| 371 channel_id_service = new net::ChannelIDService( | 374 channel_id_service = new net::ChannelIDService( |
| 372 new net::DefaultChannelIDStore(channel_id_db.get()), | 375 new net::DefaultChannelIDStore(channel_id_db.get()), |
| 373 base::WorkerPool::GetTaskRunner(true)); | 376 base::WorkerPool::GetTaskRunner(true)); |
| 374 } | 377 } |
| 375 | 378 |
| 376 set_channel_id_service(channel_id_service); | 379 set_channel_id_service(channel_id_service); |
| 377 main_context->set_channel_id_service(channel_id_service); | 380 main_context->set_channel_id_service(channel_id_service); |
| 378 main_cookie_store_->SetChannelIDServiceID(channel_id_service->GetUniqueID()); | 381 main_cookie_store_->SetChannelIDServiceID(channel_id_service->GetUniqueID()); |
| 379 | 382 |
| 380 scoped_ptr<net::HttpCache::BackendFactory> main_backend( | 383 std::unique_ptr<net::HttpCache::BackendFactory> main_backend( |
| 381 new net::HttpCache::DefaultBackend( | 384 new net::HttpCache::DefaultBackend( |
| 382 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, | 385 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, |
| 383 lazy_params_->cache_path, lazy_params_->cache_max_size, | 386 lazy_params_->cache_path, lazy_params_->cache_max_size, |
| 384 web::WebThread::GetTaskRunnerForThread(web::WebThread::CACHE))); | 387 web::WebThread::GetTaskRunnerForThread(web::WebThread::CACHE))); |
| 385 http_network_session_ = CreateHttpNetworkSession(*profile_params); | 388 http_network_session_ = CreateHttpNetworkSession(*profile_params); |
| 386 main_http_factory_ = CreateMainHttpFactory(http_network_session_.get(), | 389 main_http_factory_ = CreateMainHttpFactory(http_network_session_.get(), |
| 387 std::move(main_backend)); | 390 std::move(main_backend)); |
| 388 main_context->set_http_transaction_factory(main_http_factory_.get()); | 391 main_context->set_http_transaction_factory(main_http_factory_.get()); |
| 389 | 392 |
| 390 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 393 std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
| 391 new net::URLRequestJobFactoryImpl()); | 394 new net::URLRequestJobFactoryImpl()); |
| 392 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); | 395 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); |
| 393 | 396 |
| 394 // TODO(crbug.com/592012): Delete request_interceptor and its handling if | 397 // TODO(crbug.com/592012): Delete request_interceptor and its handling if |
| 395 // it's not needed in the future. | 398 // it's not needed in the future. |
| 396 URLRequestInterceptorScopedVector request_interceptors; | 399 URLRequestInterceptorScopedVector request_interceptors; |
| 397 main_job_factory_ = SetUpJobFactoryDefaults(std::move(main_job_factory), | 400 main_job_factory_ = SetUpJobFactoryDefaults(std::move(main_job_factory), |
| 398 std::move(request_interceptors), | 401 std::move(request_interceptors), |
| 399 main_context->network_delegate()); | 402 main_context->network_delegate()); |
| 400 main_context->set_job_factory(main_job_factory_.get()); | 403 main_context->set_job_factory(main_job_factory_.get()); |
| 401 main_context->set_network_quality_estimator( | 404 main_context->set_network_quality_estimator( |
| 402 io_thread_globals->network_quality_estimator.get()); | 405 io_thread_globals->network_quality_estimator.get()); |
| 403 | 406 |
| 404 // Setup SDCH for this profile. | 407 // Setup SDCH for this profile. |
| 405 sdch_manager_.reset(new net::SdchManager); | 408 sdch_manager_.reset(new net::SdchManager); |
| 406 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); | 409 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); |
| 407 main_context->set_sdch_manager(sdch_manager_.get()); | 410 main_context->set_sdch_manager(sdch_manager_.get()); |
| 408 sdch_policy_->EnablePersistentStorage( | 411 sdch_policy_->EnablePersistentStorage( |
| 409 make_scoped_ptr(new SdchOwnerPrefStorage(network_json_store_.get()))); | 412 base::WrapUnique(new SdchOwnerPrefStorage(network_json_store_.get()))); |
| 410 | 413 |
| 411 lazy_params_.reset(); | 414 lazy_params_.reset(); |
| 412 } | 415 } |
| 413 | 416 |
| 414 ChromeBrowserStateIOData::AppRequestContext* | 417 ChromeBrowserStateIOData::AppRequestContext* |
| 415 ChromeBrowserStateImplIOData::InitializeAppRequestContext( | 418 ChromeBrowserStateImplIOData::InitializeAppRequestContext( |
| 416 net::URLRequestContext* main_context) const { | 419 net::URLRequestContext* main_context) const { |
| 417 // Copy most state from the main context. | 420 // Copy most state from the main context. |
| 418 AppRequestContext* context = new AppRequestContext(); | 421 AppRequestContext* context = new AppRequestContext(); |
| 419 context->CopyFrom(main_context); | 422 context->CopyFrom(main_context); |
| 420 | 423 |
| 421 // Use a separate HTTP disk cache for isolated apps. | 424 // Use a separate HTTP disk cache for isolated apps. |
| 422 scoped_ptr<net::HttpCache::BackendFactory> app_backend = | 425 std::unique_ptr<net::HttpCache::BackendFactory> app_backend = |
| 423 net::HttpCache::DefaultBackend::InMemory(0); | 426 net::HttpCache::DefaultBackend::InMemory(0); |
| 424 scoped_ptr<net::HttpCache> app_http_cache = | 427 std::unique_ptr<net::HttpCache> app_http_cache = |
| 425 CreateHttpFactory(http_network_session_.get(), std::move(app_backend)); | 428 CreateHttpFactory(http_network_session_.get(), std::move(app_backend)); |
| 426 | 429 |
| 427 cookie_util::CookieStoreConfig ios_cookie_config( | 430 cookie_util::CookieStoreConfig ios_cookie_config( |
| 428 base::FilePath(), | 431 base::FilePath(), |
| 429 cookie_util::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, | 432 cookie_util::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, |
| 430 cookie_util::CookieStoreConfig::COOKIE_STORE_IOS, nullptr); | 433 cookie_util::CookieStoreConfig::COOKIE_STORE_IOS, nullptr); |
| 431 scoped_ptr<net::CookieStore> cookie_store = | 434 std::unique_ptr<net::CookieStore> cookie_store = |
| 432 cookie_util::CreateCookieStore(ios_cookie_config); | 435 cookie_util::CreateCookieStore(ios_cookie_config); |
| 433 | 436 |
| 434 // Transfer ownership of the cookies and cache to AppRequestContext. | 437 // Transfer ownership of the cookies and cache to AppRequestContext. |
| 435 context->SetCookieStore(std::move(cookie_store)); | 438 context->SetCookieStore(std::move(cookie_store)); |
| 436 context->SetHttpTransactionFactory(std::move(app_http_cache)); | 439 context->SetHttpTransactionFactory(std::move(app_http_cache)); |
| 437 | 440 |
| 438 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 441 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 439 new net::URLRequestJobFactoryImpl()); | 442 new net::URLRequestJobFactoryImpl()); |
| 440 // TODO(crbug.com/592012): Delete request_interceptor and its handling if | 443 // TODO(crbug.com/592012): Delete request_interceptor and its handling if |
| 441 // it's not needed in the future. | 444 // it's not needed in the future. |
| 442 URLRequestInterceptorScopedVector request_interceptors; | 445 URLRequestInterceptorScopedVector request_interceptors; |
| 443 scoped_ptr<net::URLRequestJobFactory> top_job_factory(SetUpJobFactoryDefaults( | 446 std::unique_ptr<net::URLRequestJobFactory> top_job_factory( |
| 444 std::move(job_factory), std::move(request_interceptors), | 447 SetUpJobFactoryDefaults(std::move(job_factory), |
| 445 main_context->network_delegate())); | 448 std::move(request_interceptors), |
| 449 main_context->network_delegate())); |
| 446 context->SetJobFactory(std::move(top_job_factory)); | 450 context->SetJobFactory(std::move(top_job_factory)); |
| 447 | 451 |
| 448 return context; | 452 return context; |
| 449 } | 453 } |
| 450 | 454 |
| 451 ChromeBrowserStateIOData::AppRequestContext* | 455 ChromeBrowserStateIOData::AppRequestContext* |
| 452 ChromeBrowserStateImplIOData::AcquireIsolatedAppRequestContext( | 456 ChromeBrowserStateImplIOData::AcquireIsolatedAppRequestContext( |
| 453 net::URLRequestContext* main_context) const { | 457 net::URLRequestContext* main_context) const { |
| 454 // We create per-app contexts on demand, unlike the others above. | 458 // We create per-app contexts on demand, unlike the others above. |
| 455 AppRequestContext* app_request_context = | 459 AppRequestContext* app_request_context = |
| 456 InitializeAppRequestContext(main_context); | 460 InitializeAppRequestContext(main_context); |
| 457 DCHECK(app_request_context); | 461 DCHECK(app_request_context); |
| 458 return app_request_context; | 462 return app_request_context; |
| 459 } | 463 } |
| 460 | 464 |
| 461 void ChromeBrowserStateImplIOData::ClearNetworkingHistorySinceOnIOThread( | 465 void ChromeBrowserStateImplIOData::ClearNetworkingHistorySinceOnIOThread( |
| 462 base::Time time, | 466 base::Time time, |
| 463 const base::Closure& completion) { | 467 const base::Closure& completion) { |
| 464 DCHECK_CURRENTLY_ON(web::WebThread::IO); | 468 DCHECK_CURRENTLY_ON(web::WebThread::IO); |
| 465 DCHECK(initialized()); | 469 DCHECK(initialized()); |
| 466 | 470 |
| 467 DCHECK(transport_security_state()); | 471 DCHECK(transport_security_state()); |
| 468 // Completes synchronously. | 472 // Completes synchronously. |
| 469 transport_security_state()->DeleteAllDynamicDataSince(time); | 473 transport_security_state()->DeleteAllDynamicDataSince(time); |
| 470 DCHECK(http_server_properties_manager_); | 474 DCHECK(http_server_properties_manager_); |
| 471 http_server_properties_manager_->Clear(completion); | 475 http_server_properties_manager_->Clear(completion); |
| 472 } | 476 } |
| OLD | NEW |