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/safe_browsing/protocol_manager.cc

Issue 11347005: Change SafeBrowsingProtocolManager::GetFullHash signature. (Closed) Base URL: http://git.chromium.org/chromium/src.git@in_progress
Patch Set: Fix rebase with browser_test Created 8 years, 1 month 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
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/safe_browsing/protocol_manager.h" 5 #include "chrome/browser/safe_browsing/protocol_manager.h"
6 6
7 #ifndef NDEBUG 7 #ifndef NDEBUG
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #endif 9 #endif
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 safebrowsing_reports_.end()); 135 safebrowsing_reports_.end());
136 safebrowsing_reports_.clear(); 136 safebrowsing_reports_.clear();
137 } 137 }
138 138
139 // Public API used by the SafeBrowsingService ---------------------------------- 139 // Public API used by the SafeBrowsingService ----------------------------------
140 140
141 // We can only have one update or chunk request outstanding, but there may be 141 // We can only have one update or chunk request outstanding, but there may be
142 // multiple GetHash requests pending since we don't want to serialize them and 142 // multiple GetHash requests pending since we don't want to serialize them and
143 // slow down the user. 143 // slow down the user.
144 void SafeBrowsingProtocolManager::GetFullHash( 144 void SafeBrowsingProtocolManager::GetFullHash(
145 SafeBrowsingService::SafeBrowsingCheck* check, 145 const std::vector<SBPrefix>& prefixes,
146 const std::vector<SBPrefix>& prefixes) { 146 FullHashCallback callback,
147 bool is_download) {
147 // If we are in GetHash backoff, we need to check if we're past the next 148 // If we are in GetHash backoff, we need to check if we're past the next
148 // allowed time. If we are, we can proceed with the request. If not, we are 149 // allowed time. If we are, we can proceed with the request. If not, we are
149 // required to return empty results (i.e. treat the page as safe). 150 // required to return empty results (i.e. treat the page as safe).
150 if (gethash_error_count_ && Time::Now() <= next_gethash_time_) { 151 if (gethash_error_count_ && Time::Now() <= next_gethash_time_) {
151 std::vector<SBFullHashResult> full_hashes; 152 std::vector<SBFullHashResult> full_hashes;
152 sb_service_->HandleGetHashResults(check, full_hashes, false); 153 callback.Run(full_hashes, false);
153 return; 154 return;
154 } 155 }
155 GURL gethash_url = GetHashUrl(); 156 GURL gethash_url = GetHashUrl();
156 net::URLFetcher* fetcher = net::URLFetcher::Create( 157 net::URLFetcher* fetcher = net::URLFetcher::Create(
157 gethash_url, net::URLFetcher::POST, this); 158 gethash_url, net::URLFetcher::POST, this);
158 hash_requests_[fetcher] = check; 159 hash_requests_[fetcher] = FullHashDetails(callback, is_download);
159 160
160 std::string get_hash; 161 std::string get_hash;
161 SafeBrowsingProtocolParser parser; 162 SafeBrowsingProtocolParser parser;
162 parser.FormatGetHash(prefixes, &get_hash); 163 parser.FormatGetHash(prefixes, &get_hash);
163 164
164 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); 165 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
165 fetcher->SetRequestContext(request_context_getter_); 166 fetcher->SetRequestContext(request_context_getter_);
166 fetcher->SetUploadData("text/plain", get_hash); 167 fetcher->SetUploadData("text/plain", get_hash);
167 fetcher->Start(); 168 fetcher->Start();
168 } 169 }
(...skipping 27 matching lines...) Expand all
196 const net::URLFetcher* report = *sit; 197 const net::URLFetcher* report = *sit;
197 safebrowsing_reports_.erase(sit); 198 safebrowsing_reports_.erase(sit);
198 delete report; 199 delete report;
199 return; 200 return;
200 } 201 }
201 202
202 HashRequests::iterator it = hash_requests_.find(source); 203 HashRequests::iterator it = hash_requests_.find(source);
203 if (it != hash_requests_.end()) { 204 if (it != hash_requests_.end()) {
204 // GetHash response. 205 // GetHash response.
205 fetcher.reset(it->first); 206 fetcher.reset(it->first);
206 SafeBrowsingService::SafeBrowsingCheck* check = it->second; 207 FullHashDetails details = it->second;
mattm 2012/10/29 23:57:09 Maybe use a reference?
cbentzel 2012/10/30 11:34:03 Done.
207 std::vector<SBFullHashResult> full_hashes; 208 std::vector<SBFullHashResult> full_hashes;
208 bool can_cache = false; 209 bool can_cache = false;
209 if (source->GetStatus().is_success() && 210 if (source->GetStatus().is_success() &&
210 (source->GetResponseCode() == 200 || 211 (source->GetResponseCode() == 200 ||
211 source->GetResponseCode() == 204)) { 212 source->GetResponseCode() == 204)) {
212 // For tracking our GetHash false positive (204) rate, compared to real 213 // For tracking our GetHash false positive (204) rate, compared to real
213 // (200) responses. 214 // (200) responses.
214 if (source->GetResponseCode() == 200) 215 if (source->GetResponseCode() == 200)
215 RecordGetHashResult(check->is_download, GET_HASH_STATUS_200); 216 RecordGetHashResult(details.is_download, GET_HASH_STATUS_200);
216 else 217 else
217 RecordGetHashResult(check->is_download, GET_HASH_STATUS_204); 218 RecordGetHashResult(details.is_download, GET_HASH_STATUS_204);
218 can_cache = true; 219 can_cache = true;
219 gethash_error_count_ = 0; 220 gethash_error_count_ = 0;
220 gethash_back_off_mult_ = 1; 221 gethash_back_off_mult_ = 1;
221 SafeBrowsingProtocolParser parser; 222 SafeBrowsingProtocolParser parser;
222 std::string data; 223 std::string data;
223 source->GetResponseAsString(&data); 224 source->GetResponseAsString(&data);
224 parsed_ok = parser.ParseGetHash( 225 parsed_ok = parser.ParseGetHash(
225 data.data(), 226 data.data(),
226 static_cast<int>(data.length()), 227 static_cast<int>(data.length()),
227 &full_hashes); 228 &full_hashes);
(...skipping 10 matching lines...) Expand all
238 << " failed with error: " << source->GetStatus().error(); 239 << " failed with error: " << source->GetStatus().error();
239 } else { 240 } else {
240 VLOG(1) << "SafeBrowsing GetHash request for: " << source->GetURL() 241 VLOG(1) << "SafeBrowsing GetHash request for: " << source->GetURL()
241 << " failed with error: " << source->GetResponseCode(); 242 << " failed with error: " << source->GetResponseCode();
242 } 243 }
243 } 244 }
244 245
245 // Call back the SafeBrowsingService with full_hashes, even if there was a 246 // Call back the SafeBrowsingService with full_hashes, even if there was a
246 // parse error or an error response code (in which case full_hashes will be 247 // parse error or an error response code (in which case full_hashes will be
247 // empty). We can't block the user regardless of the error status. 248 // empty). We can't block the user regardless of the error status.
248 sb_service_->HandleGetHashResults(check, full_hashes, can_cache); 249 details.callback.Run(full_hashes, can_cache);
249 250
250 hash_requests_.erase(it); 251 hash_requests_.erase(it);
251 } else { 252 } else {
252 // Update or chunk response. 253 // Update or chunk response.
253 fetcher.reset(request_.release()); 254 fetcher.reset(request_.release());
254 255
255 if (request_type_ == UPDATE_REQUEST) { 256 if (request_type_ == UPDATE_REQUEST) {
256 if (!fetcher.get()) { 257 if (!fetcher.get()) {
257 // We've timed out waiting for an update response, so we've cancelled 258 // We've timed out waiting for an update response, so we've cancelled
258 // the update request and scheduled a new one. Ignore this response. 259 // the update request and scheduled a new one. Ignore this response.
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 if (!additional_query_.empty()) { 745 if (!additional_query_.empty()) {
745 if (next_url.find("?") != std::string::npos) { 746 if (next_url.find("?") != std::string::npos) {
746 next_url.append("&"); 747 next_url.append("&");
747 } else { 748 } else {
748 next_url.append("?"); 749 next_url.append("?");
749 } 750 }
750 next_url.append(additional_query_); 751 next_url.append(additional_query_);
751 } 752 }
752 return GURL(next_url); 753 return GURL(next_url);
753 } 754 }
755
756 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails()
757 : callback(),
758 is_download(false) {
759 }
760
761 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails(
762 FullHashCallback callback, bool is_download)
763 : callback(callback),
764 is_download(is_download) {
765 }
766
767 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {
768 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698