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

Side by Side Diff: ios/web/net/request_tracker_impl.mm

Issue 2522943003: [iOS/ARC] Fix a violation of ODR in base::BindBlock under ARC. (Closed)
Patch Set: Use EXPECT_NSEQ instead of EXPECT_EQ/EXPECT_TRUE. Created 4 years 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/web/net/crw_cert_verification_controller.mm ('k') | ios/web/webui/crw_web_ui_manager.mm » ('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/web/net/request_tracker_impl.h" 5 #include "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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 477
478 void RequestTrackerImpl::StartRequest(net::URLRequest* request) { 478 void RequestTrackerImpl::StartRequest(net::URLRequest* request) {
479 DCHECK_CURRENTLY_ON(web::WebThread::IO); 479 DCHECK_CURRENTLY_ON(web::WebThread::IO);
480 DCHECK(!counts_by_request_.count(request)); 480 DCHECK(!counts_by_request_.count(request));
481 DCHECK_EQ(is_for_static_file_requests_, request->url().SchemeIsFile()); 481 DCHECK_EQ(is_for_static_file_requests_, request->url().SchemeIsFile());
482 482
483 bool addedRequest = live_requests_.insert(request).second; 483 bool addedRequest = live_requests_.insert(request).second;
484 if (!is_for_static_file_requests_ && addedRequest) { 484 if (!is_for_static_file_requests_ && addedRequest) {
485 NSString* networkActivityKey = GetNetworkActivityKey(); 485 NSString* networkActivityKey = GetNetworkActivityKey();
486 web::WebThread::PostTask( 486 web::WebThread::PostTask(
487 web::WebThread::UI, FROM_HERE, 487 web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
488 base::BindBlock(^{
489 [[CRWNetworkActivityIndicatorManager sharedInstance] 488 [[CRWNetworkActivityIndicatorManager sharedInstance]
490 startNetworkTaskForGroup:networkActivityKey]; 489 startNetworkTaskForGroup:networkActivityKey];
491 })); 490 }));
492 } 491 }
493 492
494 if (new_estimate_round_) { 493 if (new_estimate_round_) {
495 // Starting a new estimate round. Ignore the previous requests for the 494 // Starting a new estimate round. Ignore the previous requests for the
496 // calculation. 495 // calculation.
497 counts_by_request_.clear(); 496 counts_by_request_.clear();
498 estimate_start_index_ = counts_.size(); 497 estimate_start_index_ = counts_.size();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 557 }
559 } 558 }
560 559
561 void RequestTrackerImpl::StopRequest(net::URLRequest* request) { 560 void RequestTrackerImpl::StopRequest(net::URLRequest* request) {
562 DCHECK_CURRENTLY_ON(web::WebThread::IO); 561 DCHECK_CURRENTLY_ON(web::WebThread::IO);
563 562
564 int removedRequests = live_requests_.erase(request); 563 int removedRequests = live_requests_.erase(request);
565 if (!is_for_static_file_requests_ && removedRequests > 0) { 564 if (!is_for_static_file_requests_ && removedRequests > 0) {
566 NSString* networkActivityKey = GetNetworkActivityKey(); 565 NSString* networkActivityKey = GetNetworkActivityKey();
567 web::WebThread::PostTask( 566 web::WebThread::PostTask(
568 web::WebThread::UI, FROM_HERE, 567 web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
569 base::BindBlock(^{
570 [[CRWNetworkActivityIndicatorManager sharedInstance] 568 [[CRWNetworkActivityIndicatorManager sharedInstance]
571 stopNetworkTaskForGroup:networkActivityKey]; 569 stopNetworkTaskForGroup:networkActivityKey];
572 })); 570 }));
573 } 571 }
574 572
575 if (counts_by_request_.count(request)) { 573 if (counts_by_request_.count(request)) {
576 StopRedirectedRequest(request); 574 StopRedirectedRequest(request);
577 Notify(); 575 Notify();
578 } 576 }
579 } 577 }
580 578
581 void RequestTrackerImpl::StopRedirectedRequest(net::URLRequest* request) { 579 void RequestTrackerImpl::StopRedirectedRequest(net::URLRequest* request) {
582 DCHECK_CURRENTLY_ON(web::WebThread::IO); 580 DCHECK_CURRENTLY_ON(web::WebThread::IO);
583 581
584 int removedRequests = live_requests_.erase(request); 582 int removedRequests = live_requests_.erase(request);
585 if (!is_for_static_file_requests_ && removedRequests > 0) { 583 if (!is_for_static_file_requests_ && removedRequests > 0) {
586 NSString* networkActivityKey = GetNetworkActivityKey(); 584 NSString* networkActivityKey = GetNetworkActivityKey();
587 web::WebThread::PostTask( 585 web::WebThread::PostTask(
588 web::WebThread::UI, FROM_HERE, 586 web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
589 base::BindBlock(^{
590 [[CRWNetworkActivityIndicatorManager sharedInstance] 587 [[CRWNetworkActivityIndicatorManager sharedInstance]
591 stopNetworkTaskForGroup:networkActivityKey]; 588 stopNetworkTaskForGroup:networkActivityKey];
592 })); 589 }));
593 } 590 }
594 591
595 if (counts_by_request_.count(request)) { 592 if (counts_by_request_.count(request)) {
596 TrackerCounts* counts = counts_by_request_[request]; 593 TrackerCounts* counts = counts_by_request_[request];
597 DCHECK(!counts->done); 594 DCHECK(!counts->done);
598 const net::SSLInfo& ssl_info = request->ssl_info(); 595 const net::SSLInfo& ssl_info = request->ssl_info();
599 if (ssl_info.is_valid()) 596 if (ssl_info.is_valid())
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 RequestTrackerImpl* inconstant_t = const_cast<RequestTrackerImpl*>(t); 738 RequestTrackerImpl* inconstant_t = const_cast<RequestTrackerImpl*>(t);
742 if (web::WebThread::CurrentlyOn(web::WebThread::IO)) { 739 if (web::WebThread::CurrentlyOn(web::WebThread::IO)) {
743 inconstant_t->Destruct(); 740 inconstant_t->Destruct();
744 } else { 741 } else {
745 // Use BindBlock rather than Bind to avoid creating another scoped_refpter 742 // Use BindBlock rather than Bind to avoid creating another scoped_refpter
746 // to |this|. |inconstant_t| isn't retained by the block, but since this 743 // to |this|. |inconstant_t| isn't retained by the block, but since this
747 // method is the mechanism by which all RequestTrackerImpl instances are 744 // method is the mechanism by which all RequestTrackerImpl instances are
748 // destroyed, the object inconstant_t points to won't be deleted while 745 // destroyed, the object inconstant_t points to won't be deleted while
749 // the block is executing (and Destruct() itself will do the deleting). 746 // the block is executing (and Destruct() itself will do the deleting).
750 web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, 747 web::WebThread::PostTask(web::WebThread::IO, FROM_HERE,
751 base::BindBlock(^{ 748 base::BindBlockArc(^{
752 inconstant_t->Destruct(); 749 inconstant_t->Destruct();
753 })); 750 }));
754 } 751 }
755 } 752 }
756 753
757 void RequestTrackerImpl::Destruct() { 754 void RequestTrackerImpl::Destruct() {
758 DCHECK_CURRENTLY_ON(web::WebThread::IO); 755 DCHECK_CURRENTLY_ON(web::WebThread::IO);
759 DCHECK(is_closing_); 756 DCHECK(is_closing_);
760 757
761 pthread_once(&g_once_control, &InitializeGlobals); 758 pthread_once(&g_once_control, &InitializeGlobals);
762 { 759 {
763 base::AutoLock scoped_lock(*g_trackers_lock); 760 base::AutoLock scoped_lock(*g_trackers_lock);
764 g_trackers->erase(request_group_id_); 761 g_trackers->erase(request_group_id_);
765 } 762 }
766 InvalidateWeakPtrs(); 763 InvalidateWeakPtrs();
767 // Delete on the UI thread. 764 // Delete on the UI thread.
768 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, base::BindBlock(^{ 765 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
769 delete this; 766 delete this;
770 })); 767 }));
771 } 768 }
772 769
773 #pragma mark Other private methods 770 #pragma mark Other private methods
774 771
775 void RequestTrackerImpl::Notify() { 772 void RequestTrackerImpl::Notify() {
776 DCHECK_CURRENTLY_ON(web::WebThread::IO); 773 DCHECK_CURRENTLY_ON(web::WebThread::IO);
777 if (is_closing_) 774 if (is_closing_)
778 return; 775 return;
779 // Notify() is called asynchronously, it runs later on the same 776 // Notify() is called asynchronously, it runs later on the same
780 // thread. This is used to collate notifications together, avoiding 777 // thread. This is used to collate notifications together, avoiding
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 // requests are all canceled by the system shortly after and nothing bad 1290 // requests are all canceled by the system shortly after and nothing bad
1294 // happens. 1291 // happens.
1295 for (it = live_requests_.begin(); it != live_requests_.end(); ++it) 1292 for (it = live_requests_.begin(); it != live_requests_.end(); ++it)
1296 (*it)->Cancel(); 1293 (*it)->Cancel();
1297 1294
1298 int removedRequests = live_requests_.size(); 1295 int removedRequests = live_requests_.size();
1299 live_requests_.clear(); 1296 live_requests_.clear();
1300 if (!is_for_static_file_requests_ && removedRequests > 0) { 1297 if (!is_for_static_file_requests_ && removedRequests > 0) {
1301 NSString* networkActivityKey = GetNetworkActivityKey(); 1298 NSString* networkActivityKey = GetNetworkActivityKey();
1302 web::WebThread::PostTask( 1299 web::WebThread::PostTask(
1303 web::WebThread::UI, FROM_HERE, 1300 web::WebThread::UI, FROM_HERE, base::BindBlockArc(^{
1304 base::BindBlock(^{
1305 [[CRWNetworkActivityIndicatorManager sharedInstance] 1301 [[CRWNetworkActivityIndicatorManager sharedInstance]
1306 clearNetworkTasksForGroup:networkActivityKey]; 1302 clearNetworkTasksForGroup:networkActivityKey];
1307 })); 1303 }));
1308 } 1304 }
1309 } 1305 }
1310 1306
1311 void RequestTrackerImpl::SetCertificatePolicyCacheForTest( 1307 void RequestTrackerImpl::SetCertificatePolicyCacheForTest(
1312 web::CertificatePolicyCache* cache) { 1308 web::CertificatePolicyCache* cache) {
1313 policy_cache_ = cache; 1309 policy_cache_ = cache;
1314 } 1310 }
1315 1311
1316 } // namespace web 1312 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/net/crw_cert_verification_controller.mm ('k') | ios/web/webui/crw_web_ui_manager.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698