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

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

Issue 23625015: Consolidate TestURLFetcherFactory::SetFakeResponse (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 7 years, 3 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (!request->SerializeToString(&request_data)) { 360 if (!request->SerializeToString(&request_data)) {
361 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1); 361 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1);
362 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; 362 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?";
363 if (!callback.is_null()) 363 if (!callback.is_null())
364 callback.Run(GURL(request->url()), false); 364 callback.Run(GURL(request->url()), false);
365 return; 365 return;
366 } 366 }
367 367
368 net::URLFetcher* fetcher = net::URLFetcher::Create( 368 net::URLFetcher* fetcher = net::URLFetcher::Create(
369 0 /* ID used for testing */, 369 0 /* ID used for testing */,
370 GURL(GetClientReportUrl(kClientReportPhishingUrl)), 370 GetClientReportUrl(kClientReportPhishingUrl),
371 net::URLFetcher::POST, this); 371 net::URLFetcher::POST, this);
372 372
373 // Remember which callback and URL correspond to the current fetcher object. 373 // Remember which callback and URL correspond to the current fetcher object.
374 ClientReportInfo* info = new ClientReportInfo; 374 ClientReportInfo* info = new ClientReportInfo;
375 info->callback = callback; 375 info->callback = callback;
376 info->phishing_url = GURL(request->url()); 376 info->phishing_url = GURL(request->url());
377 client_phishing_reports_[fetcher] = info; 377 client_phishing_reports_[fetcher] = info;
378 378
379 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); 379 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
380 fetcher->SetRequestContext(request_context_getter_.get()); 380 fetcher->SetRequestContext(request_context_getter_.get());
(...skipping 29 matching lines...) Expand all
410 if (!request->SerializeToString(&request_data)) { 410 if (!request->SerializeToString(&request_data)) {
411 UpdateEnumUMAHistogram(REPORT_FAILED_SERIALIZATION); 411 UpdateEnumUMAHistogram(REPORT_FAILED_SERIALIZATION);
412 DVLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; 412 DVLOG(1) << "Unable to serialize the CSD request. Proto file changed?";
413 if (!callback.is_null()) 413 if (!callback.is_null())
414 callback.Run(GURL(request->url()), GURL(request->url()), false); 414 callback.Run(GURL(request->url()), GURL(request->url()), false);
415 return; 415 return;
416 } 416 }
417 417
418 net::URLFetcher* fetcher = net::URLFetcher::Create( 418 net::URLFetcher* fetcher = net::URLFetcher::Create(
419 0 /* ID used for testing */, 419 0 /* ID used for testing */,
420 GURL(GetClientReportUrl(kClientReportMalwareUrl)), 420 GetClientReportUrl(kClientReportMalwareUrl),
421 net::URLFetcher::POST, this); 421 net::URLFetcher::POST, this);
422 422
423 // Remember which callback and URL correspond to the current fetcher object. 423 // Remember which callback and URL correspond to the current fetcher object.
424 ClientMalwareReportInfo* info = new ClientMalwareReportInfo; 424 ClientMalwareReportInfo* info = new ClientMalwareReportInfo;
425 info->callback = callback; 425 info->callback = callback;
426 info->original_url = GURL(request->url()); 426 info->original_url = GURL(request->url());
427 client_malware_reports_[fetcher] = info; 427 client_malware_reports_[fetcher] = info;
428 428
429 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); 429 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
430 fetcher->SetRequestContext(request_context_getter_.get()); 430 fetcher->SetRequestContext(request_context_getter_.get());
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 } 699 }
700 for (int i = 0; i < model.page_term_size(); ++i) { 700 for (int i = 0; i < model.page_term_size(); ++i) {
701 if (model.page_term(i) < 0 || model.page_term(i) > max_index) { 701 if (model.page_term(i) < 0 || model.page_term(i) > max_index) {
702 return false; 702 return false;
703 } 703 }
704 } 704 }
705 return true; 705 return true;
706 } 706 }
707 707
708 // static 708 // static
709 std::string ClientSideDetectionService::GetClientReportUrl( 709 GURL ClientSideDetectionService::GetClientReportUrl(
710 const std::string& report_url) { 710 const std::string& report_url) {
711 std::string url = report_url; 711 GURL url(report_url);
712 std::string api_key = google_apis::GetAPIKey(); 712 std::string api_key = google_apis::GetAPIKey();
713 if (!api_key.empty()) { 713 if (!api_key.empty())
714 base::StringAppendF(&url, "?key=%s", 714 url = url.Resolve("?key=%s" + net::EscapeQueryParamValue(api_key, true));
mattm 2013/09/23 21:37:00 remove %s
Mattias Nissler (ping if slow) 2013/09/24 08:53:29 Oops, thanks for pointing out. Done.
715 net::EscapeQueryParamValue(api_key, true).c_str()); 715
716 }
717 return url; 716 return url;
718 } 717 }
719 } // namespace safe_browsing 718 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698