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 "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 base::AtExitManager* g_at_exit_ = nullptr; | 51 base::AtExitManager* g_at_exit_ = nullptr; |
52 | 52 |
53 // Request context getter for CrNet. | 53 // Request context getter for CrNet. |
54 class CrNetURLRequestContextGetter : public net::URLRequestContextGetter { | 54 class CrNetURLRequestContextGetter : public net::URLRequestContextGetter { |
55 public: | 55 public: |
56 CrNetURLRequestContextGetter( | 56 CrNetURLRequestContextGetter( |
57 net::URLRequestContext* context, | 57 net::URLRequestContext* context, |
58 const scoped_refptr<base::MessageLoopProxy>& loop) | 58 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
59 : context_(context), loop_(loop) {} | 59 : context_(context), task_runner_(task_runner) {} |
60 | 60 |
61 net::URLRequestContext* GetURLRequestContext() override { return context_; } | 61 net::URLRequestContext* GetURLRequestContext() override { return context_; } |
62 | 62 |
63 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | 63 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
64 const override { | 64 const override { |
65 return loop_; | 65 return task_runner_; |
66 } | 66 } |
67 private: | 67 private: |
68 // Must be called on the IO thread. | 68 // Must be called on the IO thread. |
69 ~CrNetURLRequestContextGetter() override {} | 69 ~CrNetURLRequestContextGetter() override {} |
70 | 70 |
71 net::URLRequestContext* context_; | 71 net::URLRequestContext* context_; |
72 scoped_refptr<base::MessageLoopProxy> loop_; | 72 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
73 DISALLOW_COPY_AND_ASSIGN(CrNetURLRequestContextGetter); | 73 DISALLOW_COPY_AND_ASSIGN(CrNetURLRequestContextGetter); |
74 }; | 74 }; |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 // net::HTTPProtocolHandlerDelegate for CrNet. | 78 // net::HTTPProtocolHandlerDelegate for CrNet. |
79 class CrNetHttpProtocolHandlerDelegate | 79 class CrNetHttpProtocolHandlerDelegate |
80 : public net::HTTPProtocolHandlerDelegate { | 80 : public net::HTTPProtocolHandlerDelegate { |
81 public: | 81 public: |
82 CrNetHttpProtocolHandlerDelegate(net::URLRequestContextGetter* getter, | 82 CrNetHttpProtocolHandlerDelegate(net::URLRequestContextGetter* getter, |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 253 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
254 file_user_blocking_thread_.reset( | 254 file_user_blocking_thread_.reset( |
255 new base::Thread("Chrome File User Blocking Thread")); | 255 new base::Thread("Chrome File User Blocking Thread")); |
256 file_user_blocking_thread_->StartWithOptions( | 256 file_user_blocking_thread_->StartWithOptions( |
257 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 257 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
258 | 258 |
259 // The network change notifier must be initialized so that registered | 259 // The network change notifier must be initialized so that registered |
260 // delegates will receive callbacks. | 260 // delegates will receive callbacks. |
261 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 261 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
262 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( | 262 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( |
263 network_io_thread_->message_loop_proxy(), nullptr)); | 263 network_io_thread_->task_runner(), nullptr)); |
264 | 264 |
265 PostToNetworkThread(FROM_HERE, | 265 PostToNetworkThread(FROM_HERE, |
266 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, | 266 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, |
267 base::Unretained(this))); | 267 base::Unretained(this))); |
268 | 268 |
269 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); | 269 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); |
270 main_context_getter_ = new CrNetURLRequestContextGetter( | 270 main_context_getter_ = new CrNetURLRequestContextGetter( |
271 main_context_.get(), network_io_thread_->message_loop_proxy()); | 271 main_context_.get(), network_io_thread_->task_runner()); |
272 SetRequestFilterBlock(nil); | 272 SetRequestFilterBlock(nil); |
273 net_log_started_ = false; | 273 net_log_started_ = false; |
274 } | 274 } |
275 | 275 |
276 void CrNetEnvironment::InstallIntoSessionConfiguration( | 276 void CrNetEnvironment::InstallIntoSessionConfiguration( |
277 NSURLSessionConfiguration* config) { | 277 NSURLSessionConfiguration* config) { |
278 config.protocolClasses = @[ [CRNHTTPProtocolHandler class] ]; | 278 config.protocolClasses = @[ [CRNHTTPProtocolHandler class] ]; |
279 } | 279 } |
280 | 280 |
281 CrNetEnvironment::~CrNetEnvironment() { | 281 CrNetEnvironment::~CrNetEnvironment() { |
(...skipping 21 matching lines...) Expand all Loading... |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 void CrNetEnvironment::InitializeOnNetworkThread() { | 306 void CrNetEnvironment::InitializeOnNetworkThread() { |
307 DCHECK(base::MessageLoop::current() == network_io_thread_->message_loop()); | 307 DCHECK(base::MessageLoop::current() == network_io_thread_->message_loop()); |
308 | 308 |
309 // Register network clients. | 309 // Register network clients. |
310 net::RequestTracker::AddGlobalNetworkClientFactory( | 310 net::RequestTracker::AddGlobalNetworkClientFactory( |
311 [[[WebPNetworkClientFactory alloc] | 311 [[[WebPNetworkClientFactory alloc] |
312 initWithTaskRunner:file_user_blocking_thread_ | 312 initWithTaskRunner:file_user_blocking_thread_ |
313 ->message_loop_proxy()] autorelease]); | 313 ->task_runner()] autorelease]); |
314 | 314 |
315 #if 0 | 315 #if 0 |
316 // TODO(huey): Re-enable this once SDCH supports SSL and dictionaries from | 316 // TODO(huey): Re-enable this once SDCH supports SSL and dictionaries from |
317 // previous sessions can be used on the first request after a fresh launch. | 317 // previous sessions can be used on the first request after a fresh launch. |
318 sdch_manager_.reset(new net::SdchManager()); | 318 sdch_manager_.reset(new net::SdchManager()); |
319 sdch_manager_->set_sdch_fetcher( | 319 sdch_manager_->set_sdch_fetcher( |
320 new SdchDictionaryFetcher(main_context_getter_)); | 320 new SdchDictionaryFetcher(main_context_getter_)); |
321 #else | 321 #else |
322 // Otherwise, explicitly disable SDCH to avoid a crash. | 322 // Otherwise, explicitly disable SDCH to avoid a crash. |
323 net::SdchManager::EnableSdchSupport(false); | 323 net::SdchManager::EnableSdchSupport(false); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 proxy_config_service_.get(), 0, nullptr)); | 366 proxy_config_service_.get(), 0, nullptr)); |
367 | 367 |
368 // Cache | 368 // Cache |
369 NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, | 369 NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, |
370 NSUserDomainMask, | 370 NSUserDomainMask, |
371 YES); | 371 YES); |
372 base::FilePath cache_path = | 372 base::FilePath cache_path = |
373 base::mac::NSStringToFilePath([dirs objectAtIndex:0]); | 373 base::mac::NSStringToFilePath([dirs objectAtIndex:0]); |
374 cache_path = cache_path.Append(FILE_PATH_LITERAL("crnet")); | 374 cache_path = cache_path.Append(FILE_PATH_LITERAL("crnet")); |
375 net::HttpCache::DefaultBackend* main_backend = | 375 net::HttpCache::DefaultBackend* main_backend = |
376 new net::HttpCache::DefaultBackend( | 376 new net::HttpCache::DefaultBackend(net::DISK_CACHE, |
377 net::DISK_CACHE, | 377 net::CACHE_BACKEND_DEFAULT, cache_path, |
378 net::CACHE_BACKEND_DEFAULT, | 378 0, // Default cache size. |
379 cache_path, | 379 network_cache_thread_->task_runner()); |
380 0, // Default cache size. | |
381 network_cache_thread_->message_loop_proxy()); | |
382 | 380 |
383 net::HttpNetworkSession::Params params; | 381 net::HttpNetworkSession::Params params; |
384 params.host_resolver = main_context_->host_resolver(); | 382 params.host_resolver = main_context_->host_resolver(); |
385 params.cert_verifier = main_context_->cert_verifier(); | 383 params.cert_verifier = main_context_->cert_verifier(); |
386 params.channel_id_service = main_context_->channel_id_service(); | 384 params.channel_id_service = main_context_->channel_id_service(); |
387 params.transport_security_state = main_context_->transport_security_state(); | 385 params.transport_security_state = main_context_->transport_security_state(); |
388 params.proxy_service = main_context_->proxy_service(); | 386 params.proxy_service = main_context_->proxy_service(); |
389 params.ssl_session_cache_shard = ""; | 387 params.ssl_session_cache_shard = ""; |
390 params.ssl_config_service = main_context_->ssl_config_service(); | 388 params.ssl_config_service = main_context_->ssl_config_service(); |
391 params.http_auth_handler_factory = main_context_->http_auth_handler_factory(); | 389 params.http_auth_handler_factory = main_context_->http_auth_handler_factory(); |
(...skipping 22 matching lines...) Expand all Loading... |
414 | 412 |
415 // Cookies | 413 // Cookies |
416 scoped_refptr<net::CookieStore> cookie_store = | 414 scoped_refptr<net::CookieStore> cookie_store = |
417 net::CookieStoreIOS::CreateCookieStoreFromNSHTTPCookieStorage(); | 415 net::CookieStoreIOS::CreateCookieStoreFromNSHTTPCookieStorage(); |
418 main_context_->set_cookie_store(cookie_store.get()); | 416 main_context_->set_cookie_store(cookie_store.get()); |
419 | 417 |
420 net::URLRequestJobFactoryImpl* job_factory = | 418 net::URLRequestJobFactoryImpl* job_factory = |
421 new net::URLRequestJobFactoryImpl; | 419 new net::URLRequestJobFactoryImpl; |
422 job_factory->SetProtocolHandler("data", new net::DataProtocolHandler); | 420 job_factory->SetProtocolHandler("data", new net::DataProtocolHandler); |
423 job_factory->SetProtocolHandler( | 421 job_factory->SetProtocolHandler( |
424 "file", new net::FileProtocolHandler(file_thread_->message_loop_proxy())); | 422 "file", new net::FileProtocolHandler(file_thread_->task_runner())); |
425 main_context_->set_job_factory(job_factory); | 423 main_context_->set_job_factory(job_factory); |
426 } | 424 } |
427 | 425 |
428 std::string CrNetEnvironment::user_agent() { | 426 std::string CrNetEnvironment::user_agent() { |
429 const net::HttpUserAgentSettings* user_agent_settings = | 427 const net::HttpUserAgentSettings* user_agent_settings = |
430 main_context_->http_user_agent_settings(); | 428 main_context_->http_user_agent_settings(); |
431 if (!user_agent_settings) { | 429 if (!user_agent_settings) { |
432 return nullptr; | 430 return nullptr; |
433 } | 431 } |
434 | 432 |
(...skipping 20 matching lines...) Expand all Loading... |
455 if (backend) | 453 if (backend) |
456 backend->DoomAllEntries(client_callback); | 454 backend->DoomAllEntries(client_callback); |
457 }); | 455 }); |
458 int rc = cache->GetBackend(&backend, doom_callback); | 456 int rc = cache->GetBackend(&backend, doom_callback); |
459 if (rc != net::ERR_IO_PENDING) { | 457 if (rc != net::ERR_IO_PENDING) { |
460 // GetBackend doesn't call the callback if it completes synchronously, so | 458 // GetBackend doesn't call the callback if it completes synchronously, so |
461 // call it directly here. | 459 // call it directly here. |
462 doom_callback.Run(rc); | 460 doom_callback.Run(rc); |
463 } | 461 } |
464 } | 462 } |
OLD | NEW |