| 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 #import "ios/web/net/request_tracker_impl.h" | 5 #import "ios/web/net/request_tracker_impl.h" |
| 6 | 6 |
| 7 #include <pthread.h> | 7 #include <pthread.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 void RequestTrackerImpl::Close() { | 398 void RequestTrackerImpl::Close() { |
| 399 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 399 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
| 400 // Mark the tracker as closing on the IO thread. Note that because the local | 400 // Mark the tracker as closing on the IO thread. Note that because the local |
| 401 // scoped_refptr here retains |this|, we a are guaranteed that destruiction | 401 // scoped_refptr here retains |this|, we a are guaranteed that destruiction |
| 402 // won't begin until the block completes, and thus |is_closing_| will always | 402 // won't begin until the block completes, and thus |is_closing_| will always |
| 403 // be set before destruction begins. | 403 // be set before destruction begins. |
| 404 web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, | 404 web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, |
| 405 base::Bind( | 405 base::Bind( |
| 406 [](RequestTrackerImpl* tracker) { | 406 [](RequestTrackerImpl* tracker) { |
| 407 tracker->is_closing_ = true; | 407 tracker->is_closing_ = true; |
| 408 tracker->CancelRequests(); | |
| 409 }, | 408 }, |
| 410 base::RetainedRef(this))); | 409 base::RetainedRef(this))); |
| 411 | 410 |
| 412 // Disable the delegate. | 411 // Disable the delegate. |
| 413 delegate_ = nil; | 412 delegate_ = nil; |
| 414 // The user_info is no longer needed. | 413 // The user_info is no longer needed. |
| 415 user_info_.reset(); | 414 user_info_.reset(); |
| 416 } | 415 } |
| 417 | 416 |
| 418 // static | 417 // static |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 NSMutableArray* urls = [NSMutableArray array]; | 1232 NSMutableArray* urls = [NSMutableArray array]; |
| 1234 for (const auto& tracker_count : counts_) | 1233 for (const auto& tracker_count : counts_) |
| 1235 [urls addObject:tracker_count->Description()]; | 1234 [urls addObject:tracker_count->Description()]; |
| 1236 | 1235 |
| 1237 return [NSString stringWithFormat:@"RequestGroupID %@\n%@\n%@", | 1236 return [NSString stringWithFormat:@"RequestGroupID %@\n%@\n%@", |
| 1238 request_group_id_.get(), | 1237 request_group_id_.get(), |
| 1239 net::NSURLWithGURL(page_url_), | 1238 net::NSURLWithGURL(page_url_), |
| 1240 [urls componentsJoinedByString:@"\n"]]; | 1239 [urls componentsJoinedByString:@"\n"]]; |
| 1241 } | 1240 } |
| 1242 | 1241 |
| 1243 void RequestTrackerImpl::CancelRequests() { | |
| 1244 DCHECK_CURRENTLY_ON(web::WebThread::IO); | |
| 1245 std::set<net::URLRequest*>::iterator it; | |
| 1246 // TODO(droger): When canceling the request, we should in theory make sure | |
| 1247 // that the NSURLProtocol client method |didFailWithError| is called, | |
| 1248 // otherwise the iOS system may wait indefinitely for the request to complete. | |
| 1249 // However, as we currently only cancel the requests when closing a tab, the | |
| 1250 // requests are all canceled by the system shortly after and nothing bad | |
| 1251 // happens. | |
| 1252 for (it = live_requests_.begin(); it != live_requests_.end(); ++it) | |
| 1253 (*it)->Cancel(); | |
| 1254 | |
| 1255 live_requests_.clear(); | |
| 1256 } | |
| 1257 | |
| 1258 void RequestTrackerImpl::SetCertificatePolicyCacheForTest( | 1242 void RequestTrackerImpl::SetCertificatePolicyCacheForTest( |
| 1259 web::CertificatePolicyCache* cache) { | 1243 web::CertificatePolicyCache* cache) { |
| 1260 policy_cache_ = cache; | 1244 policy_cache_ = cache; |
| 1261 } | 1245 } |
| 1262 | 1246 |
| 1263 } // namespace web | 1247 } // namespace web |
| OLD | NEW |