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

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

Powered by Google App Engine
This is Rietveld 408576698