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 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 base::subtle::MemoryBarrier(); | 304 base::subtle::MemoryBarrier(); |
305 PostToNetworkThread(FROM_HERE, | 305 PostToNetworkThread(FROM_HERE, |
306 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, | 306 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, |
307 base::Unretained(this))); | 307 base::Unretained(this))); |
308 | 308 |
309 SetRequestFilterBlock(nil); | 309 SetRequestFilterBlock(nil); |
310 } | 310 } |
311 | 311 |
312 void CrNetEnvironment::InstallIntoSessionConfiguration( | 312 void CrNetEnvironment::InstallIntoSessionConfiguration( |
313 NSURLSessionConfiguration* config) { | 313 NSURLSessionConfiguration* config) { |
314 config.protocolClasses = @[ [CRNPauseableHTTPProtocolHandler class] ]; | 314 config.protocolClasses = @[ [CRNHTTPProtocolHandler class] ]; |
315 } | 315 } |
316 | 316 |
317 CrNetEnvironment::~CrNetEnvironment() { | 317 CrNetEnvironment::~CrNetEnvironment() { |
318 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); | 318 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); |
319 } | 319 } |
320 | 320 |
321 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { | 321 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { |
322 return main_context_getter_.get(); | 322 return main_context_getter_.get(); |
323 } | 323 } |
324 | 324 |
325 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { | 325 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { |
326 if (registered) { | 326 if (registered) { |
327 // Disable the default cache. | 327 // Disable the default cache. |
328 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; | 328 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; |
329 // Register the chrome http protocol handler to replace the default one. | 329 // Register the chrome http protocol handler to replace the default one. |
330 BOOL success = | 330 BOOL success = |
331 [NSURLProtocol registerClass:[CRNPauseableHTTPProtocolHandler class]]; | 331 [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]]; |
332 DCHECK(success); | 332 DCHECK(success); |
333 } else { | 333 } else { |
334 // Set up an empty default cache, with default size. | 334 // Set up an empty default cache, with default size. |
335 // TODO(droger): If the NSURLCache is to be used, its size should most | 335 // TODO(droger): If the NSURLCache is to be used, its size should most |
336 // likely be changed. On an iPod2 with iOS4, the default size is 512k. | 336 // likely be changed. On an iPod2 with iOS4, the default size is 512k. |
337 [NSURLCache setSharedURLCache:[[[NSURLCache alloc] init] autorelease]]; | 337 [NSURLCache setSharedURLCache:[[[NSURLCache alloc] init] autorelease]]; |
338 [NSURLProtocol unregisterClass:[CRNPauseableHTTPProtocolHandler class]]; | 338 [NSURLProtocol unregisterClass:[CRNHTTPProtocolHandler class]]; |
339 } | 339 } |
340 } | 340 } |
341 | 341 |
342 void CrNetEnvironment::ConfigureSdchOnNetworkThread() { | 342 void CrNetEnvironment::ConfigureSdchOnNetworkThread() { |
343 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); | 343 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); |
344 net::URLRequestContext* context = | 344 net::URLRequestContext* context = |
345 main_context_getter_->GetURLRequestContext(); | 345 main_context_getter_->GetURLRequestContext(); |
346 | 346 |
347 if (!sdch_enabled_) { | 347 if (!sdch_enabled_) { |
348 DCHECK_EQ(static_cast<net::SdchManager*>(nullptr), context->sdch_manager()); | 348 DCHECK_EQ(static_cast<net::SdchManager*>(nullptr), context->sdch_manager()); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 504 |
505 return user_agent_settings->GetUserAgent(); | 505 return user_agent_settings->GetUserAgent(); |
506 } | 506 } |
507 | 507 |
508 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { | 508 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { |
509 PostToNetworkThread( | 509 PostToNetworkThread( |
510 FROM_HERE, base::Bind(&net::ClearHttpCache, main_context_getter_, | 510 FROM_HERE, base::Bind(&net::ClearHttpCache, main_context_getter_, |
511 network_io_thread_->task_runner(), base::Time(), | 511 network_io_thread_->task_runner(), base::Time(), |
512 base::Time::Max(), base::BindBlock(callback))); | 512 base::Time::Max(), base::BindBlock(callback))); |
513 } | 513 } |
OLD | NEW |