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

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_service.cc

Issue 10386063: Move URLFetcherDelegate to net/ and split URLFetcher between net/ and content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head, fix win component build Created 8 years, 7 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
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/client_side_detection_service.h" 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Refresh the model when the service is enabled. This can happen when the 101 // Refresh the model when the service is enabled. This can happen when the
102 // preference is toggled, or early during startup if the preference is 102 // preference is toggled, or early during startup if the preference is
103 // already enabled. In a lot of cases the model will be in the cache so it 103 // already enabled. In a lot of cases the model will be in the cache so it
104 // won't actually be fetched from the network. 104 // won't actually be fetched from the network.
105 // We delay the first model fetch to avoid slowing down browser startup. 105 // We delay the first model fetch to avoid slowing down browser startup.
106 ScheduleFetchModel(kInitialClientModelFetchDelayMs); 106 ScheduleFetchModel(kInitialClientModelFetchDelayMs);
107 } else { 107 } else {
108 // Cancel pending requests. 108 // Cancel pending requests.
109 model_fetcher_.reset(); 109 model_fetcher_.reset();
110 // Invoke pending callbacks with a false verdict. 110 // Invoke pending callbacks with a false verdict.
111 for (std::map<const content::URLFetcher*, ClientReportInfo*>::iterator it = 111 for (std::map<const net::URLFetcher*, ClientReportInfo*>::iterator it =
112 client_phishing_reports_.begin(); 112 client_phishing_reports_.begin();
113 it != client_phishing_reports_.end(); ++it) { 113 it != client_phishing_reports_.end(); ++it) {
114 ClientReportInfo* info = it->second; 114 ClientReportInfo* info = it->second;
115 if (!info->callback.is_null()) 115 if (!info->callback.is_null())
116 info->callback.Run(info->phishing_url, false); 116 info->callback.Run(info->phishing_url, false);
117 } 117 }
118 STLDeleteContainerPairPointers(client_phishing_reports_.begin(), 118 STLDeleteContainerPairPointers(client_phishing_reports_.begin(),
119 client_phishing_reports_.end()); 119 client_phishing_reports_.end());
120 client_phishing_reports_.clear(); 120 client_phishing_reports_.clear();
121 cache_.clear(); 121 cache_.clear();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 subnet[i] = ip_number[i] & mask[i]; 174 subnet[i] = ip_number[i] & mask[i];
175 } 175 }
176 if (it->second.count(crypto::SHA256HashString(subnet)) > 0) { 176 if (it->second.count(crypto::SHA256HashString(subnet)) > 0) {
177 return true; 177 return true;
178 } 178 }
179 } 179 }
180 return false; 180 return false;
181 } 181 }
182 182
183 void ClientSideDetectionService::OnURLFetchComplete( 183 void ClientSideDetectionService::OnURLFetchComplete(
184 const content::URLFetcher* source) { 184 const net::URLFetcher* source) {
185 std::string data; 185 std::string data;
186 source->GetResponseAsString(&data); 186 source->GetResponseAsString(&data);
187 if (source == model_fetcher_.get()) { 187 if (source == model_fetcher_.get()) {
188 HandleModelResponse( 188 HandleModelResponse(
189 source, source->GetURL(), source->GetStatus(), 189 source, source->GetURL(), source->GetStatus(),
190 source->GetResponseCode(), source->GetCookies(), data); 190 source->GetResponseCode(), source->GetCookies(), data);
191 } else if (client_phishing_reports_.find(source) != 191 } else if (client_phishing_reports_.find(source) !=
192 client_phishing_reports_.end()) { 192 client_phishing_reports_.end()) {
193 HandlePhishingVerdict( 193 HandlePhishingVerdict(
194 source, source->GetURL(), source->GetStatus(), 194 source, source->GetURL(), source->GetStatus(),
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); 315 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
316 fetcher->SetRequestContext(request_context_getter_.get()); 316 fetcher->SetRequestContext(request_context_getter_.get());
317 fetcher->SetUploadData("application/octet-stream", request_data); 317 fetcher->SetUploadData("application/octet-stream", request_data);
318 fetcher->Start(); 318 fetcher->Start();
319 319
320 // Record that we made a request 320 // Record that we made a request
321 phishing_report_times_.push(base::Time::Now()); 321 phishing_report_times_.push(base::Time::Now());
322 } 322 }
323 323
324 void ClientSideDetectionService::HandleModelResponse( 324 void ClientSideDetectionService::HandleModelResponse(
325 const content::URLFetcher* source, 325 const net::URLFetcher* source,
326 const GURL& url, 326 const GURL& url,
327 const net::URLRequestStatus& status, 327 const net::URLRequestStatus& status,
328 int response_code, 328 int response_code,
329 const net::ResponseCookies& cookies, 329 const net::ResponseCookies& cookies,
330 const std::string& data) { 330 const std::string& data) {
331 base::TimeDelta max_age; 331 base::TimeDelta max_age;
332 if (status.is_success() && net::HTTP_OK == response_code && 332 if (status.is_success() && net::HTTP_OK == response_code &&
333 source->GetResponseHeaders() && 333 source->GetResponseHeaders() &&
334 source->GetResponseHeaders()->GetMaxAgeValue(&max_age)) { 334 source->GetResponseHeaders()->GetMaxAgeValue(&max_age)) {
335 model_max_age_.reset(new base::TimeDelta(max_age)); 335 model_max_age_.reset(new base::TimeDelta(max_age));
(...skipping 20 matching lines...) Expand all
356 } else { 356 } else {
357 // The model is valid => replace the existing model with the new one. 357 // The model is valid => replace the existing model with the new one.
358 model_str_.assign(data); 358 model_str_.assign(data);
359 model_.swap(model); 359 model_.swap(model);
360 model_status = MODEL_SUCCESS; 360 model_status = MODEL_SUCCESS;
361 } 361 }
362 EndFetchModel(model_status); 362 EndFetchModel(model_status);
363 } 363 }
364 364
365 void ClientSideDetectionService::HandlePhishingVerdict( 365 void ClientSideDetectionService::HandlePhishingVerdict(
366 const content::URLFetcher* source, 366 const net::URLFetcher* source,
367 const GURL& url, 367 const GURL& url,
368 const net::URLRequestStatus& status, 368 const net::URLRequestStatus& status,
369 int response_code, 369 int response_code,
370 const net::ResponseCookies& cookies, 370 const net::ResponseCookies& cookies,
371 const std::string& data) { 371 const std::string& data) {
372 ClientPhishingResponse response; 372 ClientPhishingResponse response;
373 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); 373 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]);
374 bool is_phishing = false; 374 bool is_phishing = false;
375 if (status.is_success() && net::HTTP_OK == response_code && 375 if (status.is_success() && net::HTTP_OK == response_code &&
376 response.ParseFromString(data)) { 376 response.ParseFromString(data)) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 526 }
527 } 527 }
528 for (int i = 0; i < model.page_term_size(); ++i) { 528 for (int i = 0; i < model.page_term_size(); ++i) {
529 if (model.page_term(i) < 0 || model.page_term(i) > max_index) { 529 if (model.page_term(i) < 0 || model.page_term(i) > max_index) {
530 return false; 530 return false;
531 } 531 }
532 } 532 }
533 return true; 533 return true;
534 } 534 }
535 } // namespace safe_browsing 535 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698