diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 06:11:18 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 06:11:18 +0000 |
commit | 1a8715142df9c7139371ae5fe9df45193deae291 (patch) | |
tree | 75774e85b0126015654d81d40606746ff0c2e3cc /chrome | |
parent | b377fe8556b64260c99171c1ed9101bd2d621568 (diff) | |
download | chromium_src-1a8715142df9c7139371ae5fe9df45193deae291.zip chromium_src-1a8715142df9c7139371ae5fe9df45193deae291.tar.gz chromium_src-1a8715142df9c7139371ae5fe9df45193deae291.tar.bz2 |
Remove build time differences between Chrome Frame and Google Chrome in the
SafeBrowsing code.
BUG=26012
TEST=None
Review URL: http://codereview.chromium.org/360059
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31209 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
10 files changed, 51 insertions, 16 deletions
diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc index aeef7b2..855359b 100644 --- a/chrome/browser/safe_browsing/protocol_manager.cc +++ b/chrome/browser/safe_browsing/protocol_manager.cc @@ -51,14 +51,6 @@ static const char* const kSbMalwareReportUrl = "http://safebrowsing.clients.google.com/safebrowsing/report?evts=malblhit" "&evtd=%s&evtr=%s&evhr=%s&client=%s&appver=%s"; -#if defined(CHROME_FRAME_BUILD) -static const char* const kSbClientName = "googlechromeframe"; -#elif defined(GOOGLE_CHROME_BUILD) -static const char* const kSbClientName = "googlechrome"; -#else -static const char* const kSbClientName = "chromium"; -#endif - // Maximum back off multiplier. static const int kSbMaxBackOff = 8; @@ -67,6 +59,7 @@ static const int kSbMaxBackOff = 8; SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( SafeBrowsingService* sb_service, + const std::string& client_name, const std::string& client_key, const std::string& wrapped_key) : sb_service_(sb_service), @@ -81,7 +74,8 @@ SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( chunk_pending_to_write_(false), client_key_(client_key), wrapped_key_(wrapped_key), - update_size_(0) { + update_size_(0), + client_name_(client_name) { // Set the backoff multiplier fuzz to a random value between 0 and 1. back_off_fuzz_ = static_cast<float>(base::RandDouble()); @@ -125,7 +119,7 @@ void SafeBrowsingProtocolManager::GetFullHash( } std::string url = StringPrintf(kSbGetHashUrl, - kSbClientName, + client_name_.c_str(), version_.c_str()); if (!client_key_.empty()) { url.append("&wrkey="); @@ -524,7 +518,7 @@ void SafeBrowsingProtocolManager::IssueChunkRequest() { void SafeBrowsingProtocolManager::IssueKeyRequest() { GURL key_url(StringPrintf(kSbNewKeyUrl, - kSbClientName, + client_name_.c_str(), version_.c_str())); request_type_ = GETKEY_REQUEST; request_.reset(new URLFetcher(key_url, URLFetcher::GET, this)); @@ -569,7 +563,7 @@ void SafeBrowsingProtocolManager::OnGetChunksComplete( SBListChunkRanges(safe_browsing_util::kMalwareList), use_mac)); std::string url = StringPrintf(kSbUpdateUrl, - kSbClientName, + client_name_.c_str(), version_.c_str()); if (use_mac) { url.append("&wrkey="); @@ -616,7 +610,7 @@ void SafeBrowsingProtocolManager::ReportMalware(const GURL& malware_url, EscapeQueryParamValue(malware_url.spec()).c_str(), EscapeQueryParamValue(page_url.spec()).c_str(), EscapeQueryParamValue(referrer_url.spec()).c_str(), - kSbClientName, + client_name_.c_str(), version_.c_str()); GURL report_url(report_str); URLFetcher* report = new URLFetcher(report_url, URLFetcher::GET, this); diff --git a/chrome/browser/safe_browsing/protocol_manager.h b/chrome/browser/safe_browsing/protocol_manager.h index e267bcb..7bf2d48 100644 --- a/chrome/browser/safe_browsing/protocol_manager.h +++ b/chrome/browser/safe_browsing/protocol_manager.h @@ -49,6 +49,7 @@ class SafeBrowsingProtocolManager : public URLFetcher::Delegate { public: SafeBrowsingProtocolManager(SafeBrowsingService* sb_service, + const std::string& client_name, const std::string& client_key, const std::string& wrapped_key); ~SafeBrowsingProtocolManager(); @@ -232,6 +233,9 @@ class SafeBrowsingProtocolManager : public URLFetcher::Delegate { // Track outstanding malware report fetchers for clean up. std::set<const URLFetcher*> malware_reports_; + // The safe browsing client name sent in each request. + std::string client_name_; + DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); }; diff --git a/chrome/browser/safe_browsing/protocol_manager_unittest.cc b/chrome/browser/safe_browsing/protocol_manager_unittest.cc index 40b8b77..2330a68 100644 --- a/chrome/browser/safe_browsing/protocol_manager_unittest.cc +++ b/chrome/browser/safe_browsing/protocol_manager_unittest.cc @@ -16,7 +16,7 @@ class SafeBrowsingProtocolManagerTest : public testing::Test { // Ensure that we respect section 5 of the SafeBrowsing protocol specification. TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) { - SafeBrowsingProtocolManager pm(NULL, "", ""); + SafeBrowsingProtocolManager pm(NULL, "", "", ""); pm.next_update_sec_ = 1800; DCHECK(pm.back_off_fuzz_ >= 0.0 && pm.back_off_fuzz_ <= 1.0); @@ -54,7 +54,7 @@ TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) { // Test string combinations with and without MAC. TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) { - SafeBrowsingProtocolManager pm(NULL, "", ""); + SafeBrowsingProtocolManager pm(NULL, "", "", ""); // Add and Sub chunks. SBListChunkRanges phish("goog-phish-shavar"); @@ -87,7 +87,7 @@ TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) { } TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes) { - SafeBrowsingProtocolManager pm(NULL, "", ""); + SafeBrowsingProtocolManager pm(NULL, "", "", ""); // No errors or back off time yet. EXPECT_EQ(pm.gethash_error_count_, 0); diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index 768f325..b527a54 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -25,6 +25,9 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/url_constants.h" +#if defined(OS_WIN) +#include "chrome/installer/util/browser_distribution.h" +#endif #include "net/base/registry_controlled_domain.h" using base::Time; @@ -91,7 +94,23 @@ void SafeBrowsingService::OnIOInitialize(const std::string& client_key, const std::string& wrapped_key) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); enabled_ = true; + + // On Windows, get the safe browsing client name from the browser + // distribution classes in installer util. These classes don't yet have + // an analog on non-Windows builds so just keep the name specified here. +#if defined(OS_WIN) + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); + std::string client_name(dist->GetSafeBrowsingName()); +#else +#if defined(GOOGLE_CHROME_BUILD) + std::string client_name("googlechrome"); +#else + std::string client_name("chromium"); +#endif +#endif + protocol_manager_ = new SafeBrowsingProtocolManager(this, + client_name, client_key, wrapped_key); // We want to initialize the protocol manager only after the database has diff --git a/chrome/installer/util/browser_distribution.cc b/chrome/installer/util/browser_distribution.cc index 844817c..da796aa 100644 --- a/chrome/installer/util/browser_distribution.cc +++ b/chrome/installer/util/browser_distribution.cc @@ -73,6 +73,10 @@ int BrowserDistribution::GetInstallReturnCode( return install_status; } +std::string BrowserDistribution::GetSafeBrowsingName() { + return "chromium"; +} + std::wstring BrowserDistribution::GetStateKey() { return L"Software\\Chromium"; } diff --git a/chrome/installer/util/browser_distribution.h b/chrome/installer/util/browser_distribution.h index aa0aa5f..5d26219 100644 --- a/chrome/installer/util/browser_distribution.h +++ b/chrome/installer/util/browser_distribution.h @@ -38,6 +38,8 @@ class BrowserDistribution { virtual int GetInstallReturnCode( installer_util::InstallStatus install_status); + virtual std::string GetSafeBrowsingName(); + virtual std::wstring GetStateKey(); virtual std::wstring GetStateMediumKey(); diff --git a/chrome/installer/util/chrome_frame_distribution.cc b/chrome/installer/util/chrome_frame_distribution.cc index 85317e6..8d79289 100644 --- a/chrome/installer/util/chrome_frame_distribution.cc +++ b/chrome/installer/util/chrome_frame_distribution.cc @@ -53,6 +53,10 @@ std::wstring ChromeFrameDistribution::GetAppDescription() { return L"Chrome in a Frame."; } +std::string ChromeFrameDistribution::GetSafeBrowsingName() { + return "googlechromeframe"; +} + std::wstring ChromeFrameDistribution::GetStateKey() { std::wstring key(google_update::kRegPathClientState); key.append(L"\\"); diff --git a/chrome/installer/util/chrome_frame_distribution.h b/chrome/installer/util/chrome_frame_distribution.h index ca9790c..6e5b702 100644 --- a/chrome/installer/util/chrome_frame_distribution.h +++ b/chrome/installer/util/chrome_frame_distribution.h @@ -27,6 +27,8 @@ class ChromeFrameDistribution : public BrowserDistribution { virtual std::wstring GetAppDescription(); + virtual std::string GetSafeBrowsingName(); + virtual std::wstring GetStateKey(); virtual std::wstring GetStateMediumKey(); diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc index c5a14d2..1f6538b 100644 --- a/chrome/installer/util/google_chrome_distribution.cc +++ b/chrome/installer/util/google_chrome_distribution.cc @@ -302,6 +302,10 @@ int GoogleChromeDistribution::GetInstallReturnCode( } } +std::string GoogleChromeDistribution::GetSafeBrowsingName() { + return "googlechrome"; +} + std::wstring GoogleChromeDistribution::GetStateKey() { std::wstring key(google_update::kRegPathClientState); key.append(L"\\"); diff --git a/chrome/installer/util/google_chrome_distribution.h b/chrome/installer/util/google_chrome_distribution.h index b72c534..78fcdec8 100644 --- a/chrome/installer/util/google_chrome_distribution.h +++ b/chrome/installer/util/google_chrome_distribution.h @@ -60,6 +60,8 @@ class GoogleChromeDistribution : public BrowserDistribution { virtual int GetInstallReturnCode( installer_util::InstallStatus install_status); + virtual std::string GetSafeBrowsingName(); + virtual std::wstring GetStateKey(); virtual std::wstring GetStateMediumKey(); |