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

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

Issue 10907225: Add API keys to SafeBrowsing client-side phishing and download verdict requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/common/safe_browsing/client_model.pb.h" 20 #include "chrome/common/safe_browsing/client_model.pb.h"
21 #include "chrome/common/safe_browsing/csd.pb.h" 21 #include "chrome/common/safe_browsing/csd.pb.h"
22 #include "chrome/common/safe_browsing/safebrowsing_messages.h" 22 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/notification_types.h" 25 #include "content/public/browser/notification_types.h"
26 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
27 #include "crypto/sha2.h" 27 #include "crypto/sha2.h"
28 #include "google_apis/google_api_keys.h"
28 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
30 #include "net/base/escape.h"
29 #include "net/base/load_flags.h" 31 #include "net/base/load_flags.h"
30 #include "net/http/http_response_headers.h" 32 #include "net/http/http_response_headers.h"
31 #include "net/http/http_status_code.h" 33 #include "net/http/http_status_code.h"
32 #include "net/url_request/url_fetcher.h" 34 #include "net/url_request/url_fetcher.h"
33 #include "net/url_request/url_request_context_getter.h" 35 #include "net/url_request/url_request_context_getter.h"
34 #include "net/url_request/url_request_status.h" 36 #include "net/url_request/url_request_status.h"
35 37
36 using content::BrowserThread; 38 using content::BrowserThread;
37 39
38 namespace safe_browsing { 40 namespace safe_browsing {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 std::string request_data; 298 std::string request_data;
297 if (!request->SerializeToString(&request_data)) { 299 if (!request->SerializeToString(&request_data)) {
298 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1); 300 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1);
299 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; 301 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?";
300 if (!callback.is_null()) 302 if (!callback.is_null())
301 callback.Run(GURL(request->url()), false); 303 callback.Run(GURL(request->url()), false);
302 return; 304 return;
303 } 305 }
304 306
305 net::URLFetcher* fetcher = net::URLFetcher::Create( 307 net::URLFetcher* fetcher = net::URLFetcher::Create(
306 0 /* ID used for testing */, GURL(kClientReportPhishingUrl), 308 0 /* ID used for testing */, GURL(GetClientReportPhishingUrl()),
307 net::URLFetcher::POST, this); 309 net::URLFetcher::POST, this);
308 310
309 // Remember which callback and URL correspond to the current fetcher object. 311 // Remember which callback and URL correspond to the current fetcher object.
310 ClientReportInfo* info = new ClientReportInfo; 312 ClientReportInfo* info = new ClientReportInfo;
311 info->callback = callback; 313 info->callback = callback;
312 info->phishing_url = GURL(request->url()); 314 info->phishing_url = GURL(request->url());
313 client_phishing_reports_[fetcher] = info; 315 client_phishing_reports_[fetcher] = info;
314 316
315 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); 317 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
316 fetcher->SetRequestContext(request_context_getter_.get()); 318 fetcher->SetRequestContext(request_context_getter_.get());
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 527 }
526 } 528 }
527 } 529 }
528 for (int i = 0; i < model.page_term_size(); ++i) { 530 for (int i = 0; i < model.page_term_size(); ++i) {
529 if (model.page_term(i) < 0 || model.page_term(i) > max_index) { 531 if (model.page_term(i) < 0 || model.page_term(i) > max_index) {
530 return false; 532 return false;
531 } 533 }
532 } 534 }
533 return true; 535 return true;
534 } 536 }
537
538 // static
539 std::string ClientSideDetectionService::GetClientReportPhishingUrl() {
540 std::string url = kClientReportPhishingUrl;
541 std::string api_key = google_apis::GetAPIKey();
542 if (!api_key.empty()) {
543 base::StringAppendF(&url, "?key=%s",
544 net::EscapeQueryParamValue(api_key, true).c_str());
545 }
546 return url;
547 }
535 } // namespace safe_browsing 548 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698