Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: ios/crnet/crnet_environment.mm

Issue 1142383006: CrNet: add pauseable NSURLProtocol and switch to using it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_->message_loop_proxy());
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 = @[ [CRNPauseableHTTPProtocolHandler class] ];
279 } 279 }
280 280
281 CrNetEnvironment::~CrNetEnvironment() { 281 CrNetEnvironment::~CrNetEnvironment() {
282 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); 282 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr);
283 net::SetURLRequestContextForNSSHttpIO(nullptr); 283 net::SetURLRequestContextForNSSHttpIO(nullptr);
284 } 284 }
285 285
286 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { 286 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() {
287 return main_context_getter_.get(); 287 return main_context_getter_.get();
288 } 288 }
289 289
290 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { 290 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) {
291 if (registered) { 291 if (registered) {
292 // Disable the default cache. 292 // Disable the default cache.
293 [NSURLCache setSharedURLCache:nil]; 293 [NSURLCache setSharedURLCache:nil];
294 // Register the chrome http protocol handler to replace the default one. 294 // Register the chrome http protocol handler to replace the default one.
295 BOOL success = [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]]; 295 BOOL success = [NSURLProtocol registerClass:
296 [CRNPauseableHTTPProtocolHandler class]];
296 DCHECK(success); 297 DCHECK(success);
297 } else { 298 } else {
298 // Set up an empty default cache, with default size. 299 // Set up an empty default cache, with default size.
299 // TODO(droger): If the NSURLCache is to be used, its size should most 300 // TODO(droger): If the NSURLCache is to be used, its size should most
300 // likely be changed. On an iPod2 with iOS4, the default size is 512k. 301 // likely be changed. On an iPod2 with iOS4, the default size is 512k.
301 [NSURLCache setSharedURLCache:[[[NSURLCache alloc] init] autorelease]]; 302 [NSURLCache setSharedURLCache:[[[NSURLCache alloc] init] autorelease]];
302 [NSURLProtocol unregisterClass:[CRNHTTPProtocolHandler class]]; 303 [NSURLProtocol unregisterClass:[CRNPauseableHTTPProtocolHandler class]];
303 } 304 }
304 } 305 }
305 306
306 void CrNetEnvironment::InitializeOnNetworkThread() { 307 void CrNetEnvironment::InitializeOnNetworkThread() {
307 DCHECK(base::MessageLoop::current() == network_io_thread_->message_loop()); 308 DCHECK(base::MessageLoop::current() == network_io_thread_->message_loop());
308 309
309 // Register network clients. 310 // Register network clients.
310 net::RequestTracker::AddGlobalNetworkClientFactory( 311 net::RequestTracker::AddGlobalNetworkClientFactory(
311 [[[WebPNetworkClientFactory alloc] 312 [[[WebPNetworkClientFactory alloc]
312 initWithTaskRunner:file_user_blocking_thread_ 313 initWithTaskRunner:file_user_blocking_thread_
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (backend) 456 if (backend)
456 backend->DoomAllEntries(client_callback); 457 backend->DoomAllEntries(client_callback);
457 }); 458 });
458 int rc = cache->GetBackend(&backend, doom_callback); 459 int rc = cache->GetBackend(&backend, doom_callback);
459 if (rc != net::ERR_IO_PENDING) { 460 if (rc != net::ERR_IO_PENDING) {
460 // GetBackend doesn't call the callback if it completes synchronously, so 461 // GetBackend doesn't call the callback if it completes synchronously, so
461 // call it directly here. 462 // call it directly here.
462 doom_callback.Run(rc); 463 doom_callback.Run(rc);
463 } 464 }
464 } 465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698