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 base::WrapUnique(io_data_->http_server_properties_manager_)); |
265 io_data_->InitializeOnUIThread(browser_state_); | 266 io_data_->InitializeOnUIThread(browser_state_); |
266 } | 267 } |
267 | 268 |
268 scoped_ptr<ChromeBrowserStateIOData::IOSChromeURLRequestContextGetterVector> | 269 std::unique_ptr< |
| 270 ChromeBrowserStateIOData::IOSChromeURLRequestContextGetterVector> |
269 ChromeBrowserStateImplIOData::Handle::GetAllContextGetters() { | 271 ChromeBrowserStateImplIOData::Handle::GetAllContextGetters() { |
270 IOSChromeURLRequestContextGetterMap::iterator iter; | 272 IOSChromeURLRequestContextGetterMap::iterator iter; |
271 scoped_ptr<IOSChromeURLRequestContextGetterVector> context_getters( | 273 std::unique_ptr<IOSChromeURLRequestContextGetterVector> context_getters( |
272 new IOSChromeURLRequestContextGetterVector()); | 274 new IOSChromeURLRequestContextGetterVector()); |
273 | 275 |
274 iter = app_request_context_getter_map_.begin(); | 276 iter = app_request_context_getter_map_.begin(); |
275 for (; iter != app_request_context_getter_map_.end(); ++iter) | 277 for (; iter != app_request_context_getter_map_.end(); ++iter) |
276 context_getters->push_back(iter->second); | 278 context_getters->push_back(iter->second); |
277 | 279 |
278 if (main_request_context_getter_.get()) | 280 if (main_request_context_getter_.get()) |
279 context_getters->push_back(main_request_context_getter_); | 281 context_getters->push_back(main_request_context_getter_); |
280 | 282 |
281 return context_getters; | 283 return context_getters; |
282 } | 284 } |
283 | 285 |
284 ChromeBrowserStateImplIOData::LazyParams::LazyParams() : cache_max_size(0) {} | 286 ChromeBrowserStateImplIOData::LazyParams::LazyParams() : cache_max_size(0) {} |
285 | 287 |
286 ChromeBrowserStateImplIOData::LazyParams::~LazyParams() {} | 288 ChromeBrowserStateImplIOData::LazyParams::~LazyParams() {} |
287 | 289 |
288 ChromeBrowserStateImplIOData::ChromeBrowserStateImplIOData() | 290 ChromeBrowserStateImplIOData::ChromeBrowserStateImplIOData() |
289 : ChromeBrowserStateIOData( | 291 : ChromeBrowserStateIOData( |
290 ios::ChromeBrowserStateType::REGULAR_BROWSER_STATE), | 292 ios::ChromeBrowserStateType::REGULAR_BROWSER_STATE), |
291 http_server_properties_manager_(nullptr), | 293 http_server_properties_manager_(nullptr), |
292 app_cache_max_size_(0) {} | 294 app_cache_max_size_(0) {} |
293 | 295 |
294 ChromeBrowserStateImplIOData::~ChromeBrowserStateImplIOData() {} | 296 ChromeBrowserStateImplIOData::~ChromeBrowserStateImplIOData() {} |
295 | 297 |
296 void ChromeBrowserStateImplIOData::InitializeInternal( | 298 void ChromeBrowserStateImplIOData::InitializeInternal( |
297 scoped_ptr<IOSChromeNetworkDelegate> chrome_network_delegate, | 299 std::unique_ptr<IOSChromeNetworkDelegate> chrome_network_delegate, |
298 ProfileParams* profile_params, | 300 ProfileParams* profile_params, |
299 ProtocolHandlerMap* protocol_handlers) const { | 301 ProtocolHandlerMap* protocol_handlers) const { |
300 // Set up a persistent store for use by the network stack on the IO thread. | 302 // Set up a persistent store for use by the network stack on the IO thread. |
301 base::FilePath network_json_store_filepath( | 303 base::FilePath network_json_store_filepath( |
302 profile_path_.Append(kIOSChromeNetworkPersistentStateFilename)); | 304 profile_path_.Append(kIOSChromeNetworkPersistentStateFilename)); |
303 network_json_store_ = new JsonPrefStore( | 305 network_json_store_ = new JsonPrefStore( |
304 network_json_store_filepath, | 306 network_json_store_filepath, |
305 JsonPrefStore::GetTaskRunnerForFile(network_json_store_filepath, | 307 JsonPrefStore::GetTaskRunnerForFile(network_json_store_filepath, |
306 web::WebThread::GetBlockingPool()), | 308 web::WebThread::GetBlockingPool()), |
307 scoped_ptr<PrefFilter>()); | 309 std::unique_ptr<PrefFilter>()); |
308 network_json_store_->ReadPrefsAsync(nullptr); | 310 network_json_store_->ReadPrefsAsync(nullptr); |
309 | 311 |
310 net::URLRequestContext* main_context = main_request_context(); | 312 net::URLRequestContext* main_context = main_request_context(); |
311 | 313 |
312 IOSChromeIOThread* const io_thread = profile_params->io_thread; | 314 IOSChromeIOThread* const io_thread = profile_params->io_thread; |
313 IOSChromeIOThread::Globals* const io_thread_globals = io_thread->globals(); | 315 IOSChromeIOThread::Globals* const io_thread_globals = io_thread->globals(); |
314 | 316 |
315 ApplyProfileParamsToContext(main_context); | 317 ApplyProfileParamsToContext(main_context); |
316 | 318 |
317 if (http_server_properties_manager_) | 319 if (http_server_properties_manager_) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 web::WebThread::GetBlockingPool()->GetSequenceToken())); | 368 web::WebThread::GetBlockingPool()->GetSequenceToken())); |
367 channel_id_service = new net::ChannelIDService( | 369 channel_id_service = new net::ChannelIDService( |
368 new net::DefaultChannelIDStore(channel_id_db.get()), | 370 new net::DefaultChannelIDStore(channel_id_db.get()), |
369 base::WorkerPool::GetTaskRunner(true)); | 371 base::WorkerPool::GetTaskRunner(true)); |
370 } | 372 } |
371 | 373 |
372 set_channel_id_service(channel_id_service); | 374 set_channel_id_service(channel_id_service); |
373 main_context->set_channel_id_service(channel_id_service); | 375 main_context->set_channel_id_service(channel_id_service); |
374 main_cookie_store_->SetChannelIDServiceID(channel_id_service->GetUniqueID()); | 376 main_cookie_store_->SetChannelIDServiceID(channel_id_service->GetUniqueID()); |
375 | 377 |
376 scoped_ptr<net::HttpCache::BackendFactory> main_backend( | 378 std::unique_ptr<net::HttpCache::BackendFactory> main_backend( |
377 new net::HttpCache::DefaultBackend( | 379 new net::HttpCache::DefaultBackend( |
378 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, | 380 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, |
379 lazy_params_->cache_path, lazy_params_->cache_max_size, | 381 lazy_params_->cache_path, lazy_params_->cache_max_size, |
380 web::WebThread::GetTaskRunnerForThread(web::WebThread::CACHE))); | 382 web::WebThread::GetTaskRunnerForThread(web::WebThread::CACHE))); |
381 http_network_session_ = CreateHttpNetworkSession(*profile_params); | 383 http_network_session_ = CreateHttpNetworkSession(*profile_params); |
382 main_http_factory_ = CreateMainHttpFactory(http_network_session_.get(), | 384 main_http_factory_ = CreateMainHttpFactory(http_network_session_.get(), |
383 std::move(main_backend)); | 385 std::move(main_backend)); |
384 main_context->set_http_transaction_factory(main_http_factory_.get()); | 386 main_context->set_http_transaction_factory(main_http_factory_.get()); |
385 | 387 |
386 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( | 388 std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory( |
387 new net::URLRequestJobFactoryImpl()); | 389 new net::URLRequestJobFactoryImpl()); |
388 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); | 390 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); |
389 | 391 |
390 // TODO(crbug.com/592012): Delete request_interceptor and its handling if | 392 // TODO(crbug.com/592012): Delete request_interceptor and its handling if |
391 // it's not needed in the future. | 393 // it's not needed in the future. |
392 URLRequestInterceptorScopedVector request_interceptors; | 394 URLRequestInterceptorScopedVector request_interceptors; |
393 main_job_factory_ = SetUpJobFactoryDefaults(std::move(main_job_factory), | 395 main_job_factory_ = SetUpJobFactoryDefaults(std::move(main_job_factory), |
394 std::move(request_interceptors), | 396 std::move(request_interceptors), |
395 main_context->network_delegate()); | 397 main_context->network_delegate()); |
396 main_context->set_job_factory(main_job_factory_.get()); | 398 main_context->set_job_factory(main_job_factory_.get()); |
397 main_context->set_network_quality_estimator( | 399 main_context->set_network_quality_estimator( |
398 io_thread_globals->network_quality_estimator.get()); | 400 io_thread_globals->network_quality_estimator.get()); |
399 | 401 |
400 // Setup SDCH for this profile. | 402 // Setup SDCH for this profile. |
401 sdch_manager_.reset(new net::SdchManager); | 403 sdch_manager_.reset(new net::SdchManager); |
402 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); | 404 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); |
403 main_context->set_sdch_manager(sdch_manager_.get()); | 405 main_context->set_sdch_manager(sdch_manager_.get()); |
404 sdch_policy_->EnablePersistentStorage( | 406 sdch_policy_->EnablePersistentStorage( |
405 make_scoped_ptr(new SdchOwnerPrefStorage(network_json_store_.get()))); | 407 base::WrapUnique(new SdchOwnerPrefStorage(network_json_store_.get()))); |
406 | 408 |
407 lazy_params_.reset(); | 409 lazy_params_.reset(); |
408 } | 410 } |
409 | 411 |
410 ChromeBrowserStateIOData::AppRequestContext* | 412 ChromeBrowserStateIOData::AppRequestContext* |
411 ChromeBrowserStateImplIOData::InitializeAppRequestContext( | 413 ChromeBrowserStateImplIOData::InitializeAppRequestContext( |
412 net::URLRequestContext* main_context) const { | 414 net::URLRequestContext* main_context) const { |
413 // Copy most state from the main context. | 415 // Copy most state from the main context. |
414 AppRequestContext* context = new AppRequestContext(); | 416 AppRequestContext* context = new AppRequestContext(); |
415 context->CopyFrom(main_context); | 417 context->CopyFrom(main_context); |
416 | 418 |
417 // Use a separate HTTP disk cache for isolated apps. | 419 // Use a separate HTTP disk cache for isolated apps. |
418 scoped_ptr<net::HttpCache::BackendFactory> app_backend = | 420 std::unique_ptr<net::HttpCache::BackendFactory> app_backend = |
419 net::HttpCache::DefaultBackend::InMemory(0); | 421 net::HttpCache::DefaultBackend::InMemory(0); |
420 scoped_ptr<net::HttpCache> app_http_cache = | 422 std::unique_ptr<net::HttpCache> app_http_cache = |
421 CreateHttpFactory(http_network_session_.get(), std::move(app_backend)); | 423 CreateHttpFactory(http_network_session_.get(), std::move(app_backend)); |
422 | 424 |
423 cookie_util::CookieStoreConfig ios_cookie_config( | 425 cookie_util::CookieStoreConfig ios_cookie_config( |
424 base::FilePath(), | 426 base::FilePath(), |
425 cookie_util::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, | 427 cookie_util::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, |
426 cookie_util::CookieStoreConfig::COOKIE_STORE_IOS, nullptr); | 428 cookie_util::CookieStoreConfig::COOKIE_STORE_IOS, nullptr); |
427 scoped_ptr<net::CookieStore> cookie_store = | 429 std::unique_ptr<net::CookieStore> cookie_store = |
428 cookie_util::CreateCookieStore(ios_cookie_config); | 430 cookie_util::CreateCookieStore(ios_cookie_config); |
429 | 431 |
430 // Transfer ownership of the cookies and cache to AppRequestContext. | 432 // Transfer ownership of the cookies and cache to AppRequestContext. |
431 context->SetCookieStore(std::move(cookie_store)); | 433 context->SetCookieStore(std::move(cookie_store)); |
432 context->SetHttpTransactionFactory(std::move(app_http_cache)); | 434 context->SetHttpTransactionFactory(std::move(app_http_cache)); |
433 | 435 |
434 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 436 std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory( |
435 new net::URLRequestJobFactoryImpl()); | 437 new net::URLRequestJobFactoryImpl()); |
436 // TODO(crbug.com/592012): Delete request_interceptor and its handling if | 438 // TODO(crbug.com/592012): Delete request_interceptor and its handling if |
437 // it's not needed in the future. | 439 // it's not needed in the future. |
438 URLRequestInterceptorScopedVector request_interceptors; | 440 URLRequestInterceptorScopedVector request_interceptors; |
439 scoped_ptr<net::URLRequestJobFactory> top_job_factory(SetUpJobFactoryDefaults( | 441 std::unique_ptr<net::URLRequestJobFactory> top_job_factory( |
440 std::move(job_factory), std::move(request_interceptors), | 442 SetUpJobFactoryDefaults(std::move(job_factory), |
441 main_context->network_delegate())); | 443 std::move(request_interceptors), |
| 444 main_context->network_delegate())); |
442 context->SetJobFactory(std::move(top_job_factory)); | 445 context->SetJobFactory(std::move(top_job_factory)); |
443 | 446 |
444 return context; | 447 return context; |
445 } | 448 } |
446 | 449 |
447 ChromeBrowserStateIOData::AppRequestContext* | 450 ChromeBrowserStateIOData::AppRequestContext* |
448 ChromeBrowserStateImplIOData::AcquireIsolatedAppRequestContext( | 451 ChromeBrowserStateImplIOData::AcquireIsolatedAppRequestContext( |
449 net::URLRequestContext* main_context) const { | 452 net::URLRequestContext* main_context) const { |
450 // We create per-app contexts on demand, unlike the others above. | 453 // We create per-app contexts on demand, unlike the others above. |
451 AppRequestContext* app_request_context = | 454 AppRequestContext* app_request_context = |
452 InitializeAppRequestContext(main_context); | 455 InitializeAppRequestContext(main_context); |
453 DCHECK(app_request_context); | 456 DCHECK(app_request_context); |
454 return app_request_context; | 457 return app_request_context; |
455 } | 458 } |
456 | 459 |
457 void ChromeBrowserStateImplIOData::ClearNetworkingHistorySinceOnIOThread( | 460 void ChromeBrowserStateImplIOData::ClearNetworkingHistorySinceOnIOThread( |
458 base::Time time, | 461 base::Time time, |
459 const base::Closure& completion) { | 462 const base::Closure& completion) { |
460 DCHECK_CURRENTLY_ON(web::WebThread::IO); | 463 DCHECK_CURRENTLY_ON(web::WebThread::IO); |
461 DCHECK(initialized()); | 464 DCHECK(initialized()); |
462 | 465 |
463 DCHECK(transport_security_state()); | 466 DCHECK(transport_security_state()); |
464 // Completes synchronously. | 467 // Completes synchronously. |
465 transport_security_state()->DeleteAllDynamicDataSince(time); | 468 transport_security_state()->DeleteAllDynamicDataSince(time); |
466 DCHECK(http_server_properties_manager_); | 469 DCHECK(http_server_properties_manager_); |
467 http_server_properties_manager_->Clear(completion); | 470 http_server_properties_manager_->Clear(completion); |
468 } | 471 } |
OLD | NEW |