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

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api.cc

Issue 10837164: WebRequest: Signal end of request if start signaled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WasSignaled is now a const method. Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/api/web_request/web_request_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/web_request/web_request_api.h" 5 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 args.Append(dict); 805 args.Append(dict);
806 806
807 DispatchEvent(profile, request, listeners, args); 807 DispatchEvent(profile, request, listeners, args);
808 } 808 }
809 809
810 void ExtensionWebRequestEventRouter::OnCompleted( 810 void ExtensionWebRequestEventRouter::OnCompleted(
811 void* profile, 811 void* profile,
812 ExtensionInfoMap* extension_info_map, 812 ExtensionInfoMap* extension_info_map,
813 net::URLRequest* request) { 813 net::URLRequest* request) {
814 // We hide events from the system context as well as sensitive requests. 814 // We hide events from the system context as well as sensitive requests.
815 if (!profile || WebRequestPermissions::HideRequest(request)) 815 // However, if the request first became sensitive after redirecting we have
816 // already signaled it and thus we have to signal the end of it. This is
817 // risk-free because the handler cannot modify the request now.
818 if (!profile ||
819 (WebRequestPermissions::HideRequest(request) && !WasSignaled(*request)))
816 return; 820 return;
817 821
818 request_time_tracker_->LogRequestEndTime(request->identifier(), 822 request_time_tracker_->LogRequestEndTime(request->identifier(),
819 base::Time::Now()); 823 base::Time::Now());
820 824
821 DCHECK(request->status().status() == net::URLRequestStatus::SUCCESS); 825 DCHECK(request->status().status() == net::URLRequestStatus::SUCCESS);
822 826
823 DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted)); 827 DCHECK(!GetAndSetSignaled(request->identifier(), kOnCompleted));
824 828
825 ClearPendingCallbacks(request); 829 ClearPendingCallbacks(request);
(...skipping 28 matching lines...) Expand all
854 858
855 DispatchEvent(profile, request, listeners, args); 859 DispatchEvent(profile, request, listeners, args);
856 } 860 }
857 861
858 void ExtensionWebRequestEventRouter::OnErrorOccurred( 862 void ExtensionWebRequestEventRouter::OnErrorOccurred(
859 void* profile, 863 void* profile,
860 ExtensionInfoMap* extension_info_map, 864 ExtensionInfoMap* extension_info_map,
861 net::URLRequest* request, 865 net::URLRequest* request,
862 bool started) { 866 bool started) {
863 // We hide events from the system context as well as sensitive requests. 867 // We hide events from the system context as well as sensitive requests.
864 if (!profile || WebRequestPermissions::HideRequest(request)) 868 // However, if the request first became sensitive after redirecting we have
869 // already signaled it and thus we have to signal the end of it. This is
870 // risk-free because the handler cannot modify the request now.
871 if (!profile ||
872 (WebRequestPermissions::HideRequest(request) && !WasSignaled(*request)))
865 return; 873 return;
866 874
867 request_time_tracker_->LogRequestEndTime(request->identifier(), 875 request_time_tracker_->LogRequestEndTime(request->identifier(),
868 base::Time::Now()); 876 base::Time::Now());
869 877
870 DCHECK(request->status().status() == net::URLRequestStatus::FAILED || 878 DCHECK(request->status().status() == net::URLRequestStatus::FAILED ||
871 request->status().status() == net::URLRequestStatus::CANCELED); 879 request->status().status() == net::URLRequestStatus::CANCELED);
872 880
873 DCHECK(!GetAndSetSignaled(request->identifier(), kOnErrorOccurred)); 881 DCHECK(!GetAndSetSignaled(request->identifier(), kOnErrorOccurred));
874 882
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1097 }
1090 1098
1091 void* ExtensionWebRequestEventRouter::GetCrossProfile(void* profile) const { 1099 void* ExtensionWebRequestEventRouter::GetCrossProfile(void* profile) const {
1092 CrossProfileMap::const_iterator cross_profile = 1100 CrossProfileMap::const_iterator cross_profile =
1093 cross_profile_map_.find(profile); 1101 cross_profile_map_.find(profile);
1094 if (cross_profile == cross_profile_map_.end()) 1102 if (cross_profile == cross_profile_map_.end())
1095 return NULL; 1103 return NULL;
1096 return cross_profile->second; 1104 return cross_profile->second;
1097 } 1105 }
1098 1106
1107 bool ExtensionWebRequestEventRouter::WasSignaled(
1108 const net::URLRequest& request) const {
1109 SignaledRequestMap::const_iterator flag =
1110 signaled_requests_.find(request.identifier());
1111 return (flag != signaled_requests_.end()) && (flag->second != 0);
1112 }
1113
1099 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl( 1114 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl(
1100 void* profile, 1115 void* profile,
1101 ExtensionInfoMap* extension_info_map, 1116 ExtensionInfoMap* extension_info_map,
1102 bool crosses_incognito, 1117 bool crosses_incognito,
1103 const std::string& event_name, 1118 const std::string& event_name,
1104 const GURL& url, 1119 const GURL& url,
1105 int tab_id, 1120 int tab_id,
1106 int window_id, 1121 int window_id,
1107 ResourceType::Type resource_type, 1122 ResourceType::Type resource_type,
1108 bool is_request_from_extension, 1123 bool is_request_from_extension,
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 1832 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
1818 adblock = true; 1833 adblock = true;
1819 } else { 1834 } else {
1820 other = true; 1835 other = true;
1821 } 1836 }
1822 } 1837 }
1823 } 1838 }
1824 1839
1825 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 1840 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
1826 } 1841 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_request/web_request_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698