| OLD | NEW |
| 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 "ios/crnet/crnet_environment.h" | 5 #include "ios/crnet/crnet_environment.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/atomicops.h" | 12 #include "base/atomicops.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/files/scoped_file.h" | 16 #include "base/files/scoped_file.h" |
| 17 #include "base/i18n/icu_util.h" | 17 #include "base/i18n/icu_util.h" |
| 18 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
| 19 #include "base/mac/bind_objc_block.h" | 19 #include "base/mac/bind_objc_block.h" |
| 20 #include "base/mac/foundation_util.h" | 20 #include "base/mac/foundation_util.h" |
| 21 #include "base/mac/scoped_block.h" | 21 #include "base/mac/scoped_block.h" |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/memory/ptr_util.h" |
| 23 #include "base/metrics/statistics_recorder.h" | 24 #include "base/metrics/statistics_recorder.h" |
| 24 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 25 #include "base/threading/worker_pool.h" | 26 #include "base/threading/worker_pool.h" |
| 26 #include "components/prefs/json_pref_store.h" | 27 #include "components/prefs/json_pref_store.h" |
| 27 #include "components/prefs/pref_filter.h" | 28 #include "components/prefs/pref_filter.h" |
| 28 #include "crypto/nss_util.h" | 29 #include "crypto/nss_util.h" |
| 29 #include "ios/crnet/sdch_owner_pref_storage.h" | 30 #include "ios/crnet/sdch_owner_pref_storage.h" |
| 30 #include "ios/net/cookies/cookie_store_ios.h" | 31 #include "ios/net/cookies/cookie_store_ios.h" |
| 31 #include "ios/net/crn_http_protocol_handler.h" | 32 #include "ios/net/crn_http_protocol_handler.h" |
| 32 #include "ios/net/empty_nsurlcache.h" | 33 #include "ios/net/empty_nsurlcache.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (!sdch_enabled_) { | 346 if (!sdch_enabled_) { |
| 346 DCHECK_EQ(static_cast<net::SdchManager*>(nullptr), context->sdch_manager()); | 347 DCHECK_EQ(static_cast<net::SdchManager*>(nullptr), context->sdch_manager()); |
| 347 return; | 348 return; |
| 348 } | 349 } |
| 349 | 350 |
| 350 sdch_manager_.reset(new net::SdchManager()); | 351 sdch_manager_.reset(new net::SdchManager()); |
| 351 sdch_owner_.reset(new net::SdchOwner(sdch_manager_.get(), context)); | 352 sdch_owner_.reset(new net::SdchOwner(sdch_manager_.get(), context)); |
| 352 if (!sdch_pref_store_filename_.empty()) { | 353 if (!sdch_pref_store_filename_.empty()) { |
| 353 base::FilePath path(sdch_pref_store_filename_); | 354 base::FilePath path(sdch_pref_store_filename_); |
| 354 pref_store_worker_pool_ = file_user_blocking_thread_->task_runner(); | 355 pref_store_worker_pool_ = file_user_blocking_thread_->task_runner(); |
| 355 net_pref_store_ = new JsonPrefStore( | 356 net_pref_store_ = new JsonPrefStore(path, pref_store_worker_pool_.get(), |
| 356 path, | 357 std::unique_ptr<PrefFilter>()); |
| 357 pref_store_worker_pool_.get(), | |
| 358 scoped_ptr<PrefFilter>()); | |
| 359 net_pref_store_->ReadPrefsAsync(nullptr); | 358 net_pref_store_->ReadPrefsAsync(nullptr); |
| 360 sdch_owner_->EnablePersistentStorage( | 359 sdch_owner_->EnablePersistentStorage( |
| 361 scoped_ptr<net::SdchOwner::PrefStorage>( | 360 std::unique_ptr<net::SdchOwner::PrefStorage>( |
| 362 new SdchOwnerPrefStorage(net_pref_store_.get()))); | 361 new SdchOwnerPrefStorage(net_pref_store_.get()))); |
| 363 } | 362 } |
| 364 context->set_sdch_manager(sdch_manager_.get()); | 363 context->set_sdch_manager(sdch_manager_.get()); |
| 365 } | 364 } |
| 366 | 365 |
| 367 void CrNetEnvironment::InitializeOnNetworkThread() { | 366 void CrNetEnvironment::InitializeOnNetworkThread() { |
| 368 DCHECK(base::MessageLoop::current() == network_io_thread_->message_loop()); | 367 DCHECK(base::MessageLoop::current() == network_io_thread_->message_loop()); |
| 369 | 368 |
| 370 ConfigureSdchOnNetworkThread(); | 369 ConfigureSdchOnNetworkThread(); |
| 371 | 370 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 std::move(proxy_config_service_), 0, nullptr) | 417 std::move(proxy_config_service_), 0, nullptr) |
| 419 .release()); | 418 .release()); |
| 420 | 419 |
| 421 // Cache | 420 // Cache |
| 422 NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, | 421 NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, |
| 423 NSUserDomainMask, | 422 NSUserDomainMask, |
| 424 YES); | 423 YES); |
| 425 base::FilePath cache_path = | 424 base::FilePath cache_path = |
| 426 base::mac::NSStringToFilePath([dirs objectAtIndex:0]); | 425 base::mac::NSStringToFilePath([dirs objectAtIndex:0]); |
| 427 cache_path = cache_path.Append(FILE_PATH_LITERAL("crnet")); | 426 cache_path = cache_path.Append(FILE_PATH_LITERAL("crnet")); |
| 428 scoped_ptr<net::HttpCache::DefaultBackend> main_backend( | 427 std::unique_ptr<net::HttpCache::DefaultBackend> main_backend( |
| 429 new net::HttpCache::DefaultBackend(net::DISK_CACHE, | 428 new net::HttpCache::DefaultBackend(net::DISK_CACHE, |
| 430 net::CACHE_BACKEND_DEFAULT, cache_path, | 429 net::CACHE_BACKEND_DEFAULT, cache_path, |
| 431 0, // Default cache size. | 430 0, // Default cache size. |
| 432 network_cache_thread_->task_runner())); | 431 network_cache_thread_->task_runner())); |
| 433 | 432 |
| 434 net::HttpNetworkSession::Params params; | 433 net::HttpNetworkSession::Params params; |
| 435 params.host_resolver = main_context_->host_resolver(); | 434 params.host_resolver = main_context_->host_resolver(); |
| 436 params.cert_verifier = main_context_->cert_verifier(); | 435 params.cert_verifier = main_context_->cert_verifier(); |
| 437 params.channel_id_service = main_context_->channel_id_service(); | 436 params.channel_id_service = main_context_->channel_id_service(); |
| 438 params.transport_security_state = main_context_->transport_security_state(); | 437 params.transport_security_state = main_context_->transport_security_state(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 466 main_context_->set_http_transaction_factory(main_cache); | 465 main_context_->set_http_transaction_factory(main_cache); |
| 467 | 466 |
| 468 // Cookies | 467 // Cookies |
| 469 cookie_store_ = net::CookieStoreIOS::CreateCookieStore( | 468 cookie_store_ = net::CookieStoreIOS::CreateCookieStore( |
| 470 [NSHTTPCookieStorage sharedHTTPCookieStorage]); | 469 [NSHTTPCookieStorage sharedHTTPCookieStorage]); |
| 471 main_context_->set_cookie_store(cookie_store_.get()); | 470 main_context_->set_cookie_store(cookie_store_.get()); |
| 472 | 471 |
| 473 net::URLRequestJobFactoryImpl* job_factory = | 472 net::URLRequestJobFactoryImpl* job_factory = |
| 474 new net::URLRequestJobFactoryImpl; | 473 new net::URLRequestJobFactoryImpl; |
| 475 job_factory->SetProtocolHandler( | 474 job_factory->SetProtocolHandler( |
| 476 "data", make_scoped_ptr(new net::DataProtocolHandler)); | 475 "data", base::WrapUnique(new net::DataProtocolHandler)); |
| 477 job_factory->SetProtocolHandler( | 476 job_factory->SetProtocolHandler( |
| 478 "file", make_scoped_ptr( | 477 "file", base::WrapUnique( |
| 479 new net::FileProtocolHandler(file_thread_->task_runner()))); | 478 new net::FileProtocolHandler(file_thread_->task_runner()))); |
| 480 main_context_->set_job_factory(job_factory); | 479 main_context_->set_job_factory(job_factory); |
| 481 | 480 |
| 482 main_context_->set_net_log(net_log_.get()); | 481 main_context_->set_net_log(net_log_.get()); |
| 483 } | 482 } |
| 484 | 483 |
| 485 std::string CrNetEnvironment::user_agent() { | 484 std::string CrNetEnvironment::user_agent() { |
| 486 const net::HttpUserAgentSettings* user_agent_settings = | 485 const net::HttpUserAgentSettings* user_agent_settings = |
| 487 main_context_->http_user_agent_settings(); | 486 main_context_->http_user_agent_settings(); |
| 488 if (!user_agent_settings) { | 487 if (!user_agent_settings) { |
| 489 return nullptr; | 488 return nullptr; |
| 490 } | 489 } |
| 491 | 490 |
| 492 return user_agent_settings->GetUserAgent(); | 491 return user_agent_settings->GetUserAgent(); |
| 493 } | 492 } |
| 494 | 493 |
| 495 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { | 494 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { |
| 496 PostToNetworkThread( | 495 PostToNetworkThread( |
| 497 FROM_HERE, | 496 FROM_HERE, |
| 498 base::Bind(&net::ClearHttpCache, main_context_getter_, | 497 base::Bind(&net::ClearHttpCache, main_context_getter_, |
| 499 network_io_thread_->task_runner(), base::BindBlock(callback))); | 498 network_io_thread_->task_runner(), base::BindBlock(callback))); |
| 500 } | 499 } |
| OLD | NEW |