| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 base::Unretained(this))); | 278 base::Unretained(this))); |
| 279 | 279 |
| 280 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); | 280 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); |
| 281 main_context_getter_ = new CrNetURLRequestContextGetter( | 281 main_context_getter_ = new CrNetURLRequestContextGetter( |
| 282 main_context_.get(), network_io_thread_->task_runner()); | 282 main_context_.get(), network_io_thread_->task_runner()); |
| 283 SetRequestFilterBlock(nil); | 283 SetRequestFilterBlock(nil); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void CrNetEnvironment::InstallIntoSessionConfiguration( | 286 void CrNetEnvironment::InstallIntoSessionConfiguration( |
| 287 NSURLSessionConfiguration* config) { | 287 NSURLSessionConfiguration* config) { |
| 288 config.protocolClasses = @[ [CRNHTTPProtocolHandler class] ]; | 288 config.protocolClasses = @[ [CRNPauseableHTTPProtocolHandler class] ]; |
| 289 } | 289 } |
| 290 | 290 |
| 291 CrNetEnvironment::~CrNetEnvironment() { | 291 CrNetEnvironment::~CrNetEnvironment() { |
| 292 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); | 292 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); |
| 293 net::SetURLRequestContextForNSSHttpIO(nullptr); | 293 net::SetURLRequestContextForNSSHttpIO(nullptr); |
| 294 } | 294 } |
| 295 | 295 |
| 296 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { | 296 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { |
| 297 return main_context_getter_.get(); | 297 return main_context_getter_.get(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { | 300 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { |
| 301 if (registered) { | 301 if (registered) { |
| 302 // Disable the default cache. | 302 // Disable the default cache. |
| 303 [NSURLCache setSharedURLCache:nil]; | 303 [NSURLCache setSharedURLCache:nil]; |
| 304 // Register the chrome http protocol handler to replace the default one. | 304 // Register the chrome http protocol handler to replace the default one. |
| 305 BOOL success = [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]]; | 305 BOOL success = [NSURLProtocol registerClass: |
| 306 [CRNPauseableHTTPProtocolHandler class]]; |
| 306 DCHECK(success); | 307 DCHECK(success); |
| 307 } else { | 308 } else { |
| 308 // Set up an empty default cache, with default size. | 309 // Set up an empty default cache, with default size. |
| 309 // TODO(droger): If the NSURLCache is to be used, its size should most | 310 // TODO(droger): If the NSURLCache is to be used, its size should most |
| 310 // likely be changed. On an iPod2 with iOS4, the default size is 512k. | 311 // likely be changed. On an iPod2 with iOS4, the default size is 512k. |
| 311 [NSURLCache setSharedURLCache:[[[NSURLCache alloc] init] autorelease]]; | 312 [NSURLCache setSharedURLCache:[[[NSURLCache alloc] init] autorelease]]; |
| 312 [NSURLProtocol unregisterClass:[CRNHTTPProtocolHandler class]]; | 313 [NSURLProtocol unregisterClass:[CRNPauseableHTTPProtocolHandler class]]; |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 | 316 |
| 316 void CrNetEnvironment::InitializeOnNetworkThread() { | 317 void CrNetEnvironment::InitializeOnNetworkThread() { |
| 317 DCHECK(base::MessageLoop::current() == network_io_thread_->message_loop()); | 318 DCHECK(base::MessageLoop::current() == network_io_thread_->message_loop()); |
| 318 | 319 |
| 319 // Register network clients. | 320 // Register network clients. |
| 320 net::RequestTracker::AddGlobalNetworkClientFactory( | 321 net::RequestTracker::AddGlobalNetworkClientFactory( |
| 321 [[[WebPNetworkClientFactory alloc] | 322 [[[WebPNetworkClientFactory alloc] |
| 322 initWithTaskRunner:file_user_blocking_thread_ | 323 initWithTaskRunner:file_user_blocking_thread_ |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 if (backend) | 467 if (backend) |
| 467 backend->DoomAllEntries(client_callback); | 468 backend->DoomAllEntries(client_callback); |
| 468 }); | 469 }); |
| 469 int rc = cache->GetBackend(&backend, doom_callback); | 470 int rc = cache->GetBackend(&backend, doom_callback); |
| 470 if (rc != net::ERR_IO_PENDING) { | 471 if (rc != net::ERR_IO_PENDING) { |
| 471 // GetBackend doesn't call the callback if it completes synchronously, so | 472 // GetBackend doesn't call the callback if it completes synchronously, so |
| 472 // call it directly here. | 473 // call it directly here. |
| 473 doom_callback.Run(rc); | 474 doom_callback.Run(rc); |
| 474 } | 475 } |
| 475 } | 476 } |
| OLD | NEW |