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

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

Issue 360059: Remove build time differences between Chrome Frame and Google Chrome in the... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "base/file_version_info.h" 7 #include "base/file_version_info.h"
8 #include "base/histogram.h" 8 #include "base/histogram.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // New MAC client key requests URL. 44 // New MAC client key requests URL.
45 static const char* const kSbNewKeyUrl = 45 static const char* const kSbNewKeyUrl =
46 "https://sb-ssl.google.com/safebrowsing/newkey?client=%s&appver=%s" 46 "https://sb-ssl.google.com/safebrowsing/newkey?client=%s&appver=%s"
47 "&pver=2.2"; 47 "&pver=2.2";
48 48
49 // URL for reporting malware pages. 49 // URL for reporting malware pages.
50 static const char* const kSbMalwareReportUrl = 50 static const char* const kSbMalwareReportUrl =
51 "http://safebrowsing.clients.google.com/safebrowsing/report?evts=malblhit" 51 "http://safebrowsing.clients.google.com/safebrowsing/report?evts=malblhit"
52 "&evtd=%s&evtr=%s&evhr=%s&client=%s&appver=%s"; 52 "&evtd=%s&evtr=%s&evhr=%s&client=%s&appver=%s";
53 53
54 #if defined(CHROME_FRAME_BUILD)
55 static const char* const kSbClientName = "googlechromeframe";
56 #elif defined(GOOGLE_CHROME_BUILD)
57 static const char* const kSbClientName = "googlechrome";
58 #else
59 static const char* const kSbClientName = "chromium";
60 #endif
61
62 // Maximum back off multiplier. 54 // Maximum back off multiplier.
63 static const int kSbMaxBackOff = 8; 55 static const int kSbMaxBackOff = 8;
64 56
65 57
66 // SafeBrowsingProtocolManager implementation ---------------------------------- 58 // SafeBrowsingProtocolManager implementation ----------------------------------
67 59
68 SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( 60 SafeBrowsingProtocolManager::SafeBrowsingProtocolManager(
69 SafeBrowsingService* sb_service, 61 SafeBrowsingService* sb_service,
62 const std::string& client_name,
70 const std::string& client_key, 63 const std::string& client_key,
71 const std::string& wrapped_key) 64 const std::string& wrapped_key)
72 : sb_service_(sb_service), 65 : sb_service_(sb_service),
73 request_type_(NO_REQUEST), 66 request_type_(NO_REQUEST),
74 update_error_count_(0), 67 update_error_count_(0),
75 gethash_error_count_(0), 68 gethash_error_count_(0),
76 update_back_off_mult_(1), 69 update_back_off_mult_(1),
77 gethash_back_off_mult_(1), 70 gethash_back_off_mult_(1),
78 next_update_sec_(-1), 71 next_update_sec_(-1),
79 update_state_(FIRST_REQUEST), 72 update_state_(FIRST_REQUEST),
80 initial_request_(true), 73 initial_request_(true),
81 chunk_pending_to_write_(false), 74 chunk_pending_to_write_(false),
82 client_key_(client_key), 75 client_key_(client_key),
83 wrapped_key_(wrapped_key), 76 wrapped_key_(wrapped_key),
84 update_size_(0) { 77 update_size_(0),
78 client_name_(client_name) {
85 // Set the backoff multiplier fuzz to a random value between 0 and 1. 79 // Set the backoff multiplier fuzz to a random value between 0 and 1.
86 back_off_fuzz_ = static_cast<float>(base::RandDouble()); 80 back_off_fuzz_ = static_cast<float>(base::RandDouble());
87 81
88 // The first update must happen between 0-5 minutes of start up. 82 // The first update must happen between 0-5 minutes of start up.
89 next_update_sec_ = base::RandInt(60, kSbTimerStartIntervalSec); 83 next_update_sec_ = base::RandInt(60, kSbTimerStartIntervalSec);
90 84
91 scoped_ptr<FileVersionInfo> version_info( 85 scoped_ptr<FileVersionInfo> version_info(
92 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); 86 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
93 if (!version_info.get()) 87 if (!version_info.get())
94 version_ = "0.1"; 88 version_ = "0.1";
(...skipping 23 matching lines...) Expand all
118 // If we are in GetHash backoff, we need to check if we're past the next 112 // If we are in GetHash backoff, we need to check if we're past the next
119 // allowed time. If we are, we can proceed with the request. If not, we are 113 // allowed time. If we are, we can proceed with the request. If not, we are
120 // required to return empty results (i.e. treat the page as safe). 114 // required to return empty results (i.e. treat the page as safe).
121 if (gethash_error_count_ && Time::Now() <= next_gethash_time_) { 115 if (gethash_error_count_ && Time::Now() <= next_gethash_time_) {
122 std::vector<SBFullHashResult> full_hashes; 116 std::vector<SBFullHashResult> full_hashes;
123 sb_service_->HandleGetHashResults(check, full_hashes, false); 117 sb_service_->HandleGetHashResults(check, full_hashes, false);
124 return; 118 return;
125 } 119 }
126 120
127 std::string url = StringPrintf(kSbGetHashUrl, 121 std::string url = StringPrintf(kSbGetHashUrl,
128 kSbClientName, 122 client_name_.c_str(),
129 version_.c_str()); 123 version_.c_str());
130 if (!client_key_.empty()) { 124 if (!client_key_.empty()) {
131 url.append("&wrkey="); 125 url.append("&wrkey=");
132 url.append(wrapped_key_); 126 url.append(wrapped_key_);
133 } 127 }
134 128
135 GURL gethash_url(url); 129 GURL gethash_url(url);
136 URLFetcher* fetcher = new URLFetcher(gethash_url, URLFetcher::POST, this); 130 URLFetcher* fetcher = new URLFetcher(gethash_url, URLFetcher::POST, this);
137 hash_requests_[fetcher] = check; 131 hash_requests_[fetcher] = check;
138 132
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 request_type_ = CHUNK_REQUEST; 511 request_type_ = CHUNK_REQUEST;
518 request_.reset(new URLFetcher(chunk_url, URLFetcher::GET, this)); 512 request_.reset(new URLFetcher(chunk_url, URLFetcher::GET, this));
519 request_->set_load_flags(net::LOAD_DISABLE_CACHE); 513 request_->set_load_flags(net::LOAD_DISABLE_CACHE);
520 request_->set_request_context(Profile::GetDefaultRequestContext()); 514 request_->set_request_context(Profile::GetDefaultRequestContext());
521 chunk_request_start_ = base::Time::Now(); 515 chunk_request_start_ = base::Time::Now();
522 request_->Start(); 516 request_->Start();
523 } 517 }
524 518
525 void SafeBrowsingProtocolManager::IssueKeyRequest() { 519 void SafeBrowsingProtocolManager::IssueKeyRequest() {
526 GURL key_url(StringPrintf(kSbNewKeyUrl, 520 GURL key_url(StringPrintf(kSbNewKeyUrl,
527 kSbClientName, 521 client_name_.c_str(),
528 version_.c_str())); 522 version_.c_str()));
529 request_type_ = GETKEY_REQUEST; 523 request_type_ = GETKEY_REQUEST;
530 request_.reset(new URLFetcher(key_url, URLFetcher::GET, this)); 524 request_.reset(new URLFetcher(key_url, URLFetcher::GET, this));
531 request_->set_load_flags(net::LOAD_DISABLE_CACHE); 525 request_->set_load_flags(net::LOAD_DISABLE_CACHE);
532 request_->set_request_context(Profile::GetDefaultRequestContext()); 526 request_->set_request_context(Profile::GetDefaultRequestContext());
533 request_->Start(); 527 request_->Start();
534 } 528 }
535 529
536 void SafeBrowsingProtocolManager::OnGetChunksComplete( 530 void SafeBrowsingProtocolManager::OnGetChunksComplete(
537 const std::vector<SBListChunkRanges>& lists, bool database_error) { 531 const std::vector<SBListChunkRanges>& lists, bool database_error) {
(...skipping 24 matching lines...) Expand all
562 // lists. 556 // lists.
563 if (!found_phishing) 557 if (!found_phishing)
564 list_data.append(FormatList( 558 list_data.append(FormatList(
565 SBListChunkRanges(safe_browsing_util::kPhishingList), use_mac)); 559 SBListChunkRanges(safe_browsing_util::kPhishingList), use_mac));
566 560
567 if (!found_malware) 561 if (!found_malware)
568 list_data.append(FormatList( 562 list_data.append(FormatList(
569 SBListChunkRanges(safe_browsing_util::kMalwareList), use_mac)); 563 SBListChunkRanges(safe_browsing_util::kMalwareList), use_mac));
570 564
571 std::string url = StringPrintf(kSbUpdateUrl, 565 std::string url = StringPrintf(kSbUpdateUrl,
572 kSbClientName, 566 client_name_.c_str(),
573 version_.c_str()); 567 version_.c_str());
574 if (use_mac) { 568 if (use_mac) {
575 url.append("&wrkey="); 569 url.append("&wrkey=");
576 url.append(wrapped_key_); 570 url.append(wrapped_key_);
577 } 571 }
578 572
579 GURL update_url(url); 573 GURL update_url(url);
580 request_.reset(new URLFetcher(update_url, URLFetcher::POST, this)); 574 request_.reset(new URLFetcher(update_url, URLFetcher::POST, this));
581 request_->set_load_flags(net::LOAD_DISABLE_CACHE); 575 request_->set_load_flags(net::LOAD_DISABLE_CACHE);
582 request_->set_request_context(Profile::GetDefaultRequestContext()); 576 request_->set_request_context(Profile::GetDefaultRequestContext());
(...skipping 26 matching lines...) Expand all
609 } 603 }
610 604
611 void SafeBrowsingProtocolManager::ReportMalware(const GURL& malware_url, 605 void SafeBrowsingProtocolManager::ReportMalware(const GURL& malware_url,
612 const GURL& page_url, 606 const GURL& page_url,
613 const GURL& referrer_url) { 607 const GURL& referrer_url) {
614 std::string report_str = StringPrintf( 608 std::string report_str = StringPrintf(
615 kSbMalwareReportUrl, 609 kSbMalwareReportUrl,
616 EscapeQueryParamValue(malware_url.spec()).c_str(), 610 EscapeQueryParamValue(malware_url.spec()).c_str(),
617 EscapeQueryParamValue(page_url.spec()).c_str(), 611 EscapeQueryParamValue(page_url.spec()).c_str(),
618 EscapeQueryParamValue(referrer_url.spec()).c_str(), 612 EscapeQueryParamValue(referrer_url.spec()).c_str(),
619 kSbClientName, 613 client_name_.c_str(),
620 version_.c_str()); 614 version_.c_str());
621 GURL report_url(report_str); 615 GURL report_url(report_str);
622 URLFetcher* report = new URLFetcher(report_url, URLFetcher::GET, this); 616 URLFetcher* report = new URLFetcher(report_url, URLFetcher::GET, this);
623 report->set_load_flags(net::LOAD_DISABLE_CACHE); 617 report->set_load_flags(net::LOAD_DISABLE_CACHE);
624 report->set_request_context(Profile::GetDefaultRequestContext()); 618 report->set_request_context(Profile::GetDefaultRequestContext());
625 report->Start(); 619 report->Start();
626 malware_reports_.insert(report); 620 malware_reports_.insert(report);
627 } 621 }
628 622
629 // static 623 // static
(...skipping 28 matching lines...) Expand all
658 void SafeBrowsingProtocolManager::HandleGetHashError(const Time& now) { 652 void SafeBrowsingProtocolManager::HandleGetHashError(const Time& now) {
659 int next = GetNextBackOffTime(&gethash_error_count_, &gethash_back_off_mult_); 653 int next = GetNextBackOffTime(&gethash_error_count_, &gethash_back_off_mult_);
660 next_gethash_time_ = now + TimeDelta::FromSeconds(next); 654 next_gethash_time_ = now + TimeDelta::FromSeconds(next);
661 } 655 }
662 656
663 void SafeBrowsingProtocolManager::UpdateFinished(bool success) { 657 void SafeBrowsingProtocolManager::UpdateFinished(bool success) {
664 UMA_HISTOGRAM_COUNTS("SB2.UpdateSize", update_size_); 658 UMA_HISTOGRAM_COUNTS("SB2.UpdateSize", update_size_);
665 update_size_ = 0; 659 update_size_ = 0;
666 sb_service_->UpdateFinished(success); 660 sb_service_->UpdateFinished(success);
667 } 661 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | chrome/browser/safe_browsing/protocol_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698