diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 14:17:58 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 14:17:58 +0000 |
commit | 7a336d6ec8064a899458123d34b9a6739e49a0d9 (patch) | |
tree | 327c4a92d7ca092e6938ecd0bdee8d42429769c3 /chrome/browser/rlz | |
parent | d4e744e5fd8bd1aa831510cb23044d8017f14e17 (diff) | |
download | chromium_src-7a336d6ec8064a899458123d34b9a6739e49a0d9.zip chromium_src-7a336d6ec8064a899458123d34b9a6739e49a0d9.tar.gz chromium_src-7a336d6ec8064a899458123d34b9a6739e49a0d9.tar.bz2 |
Move brand code related function to a common place for all platforms. These
are Google specific APIs.
BUG=None
TEST=Make sure RLZ still uses correct brand code.
Review URL: http://codereview.chromium.org/8136006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104479 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/rlz')
-rw-r--r-- | chrome/browser/rlz/rlz.cc | 77 | ||||
-rw-r--r-- | chrome/browser/rlz/rlz.h | 14 | ||||
-rw-r--r-- | chrome/browser/rlz/rlz_unittest.cc | 21 |
3 files changed, 53 insertions, 59 deletions
diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc index 52c9db4..9c59f64 100644 --- a/chrome/browser/rlz/rlz.cc +++ b/chrome/browser/rlz/rlz.cc @@ -23,6 +23,7 @@ #include "base/threading/thread_restrictions.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/google/google_util.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" @@ -36,11 +37,6 @@ namespace { -// Organic brands all start with GG, such as GGCM. -static bool is_organic(const std::wstring& brand) { - return (brand.size() < 2) ? false : (brand.substr(0, 2) == L"GG"); -} - void RecordProductEvents(bool first_run, bool google_default_search, bool google_default_homepage, bool already_ran, bool omnibox_used, bool homepage_used) { @@ -99,14 +95,12 @@ void RecordProductEvents(bool first_run, bool google_default_search, } } -bool SendFinancialPing(const std::wstring& brand, - const std::wstring& lang, - const std::wstring& referral, - bool exclude_id) { +bool SendFinancialPing(const std::string& brand, + const string16& lang, + const string16& referral) { rlz_lib::AccessPoint points[] = {rlz_lib::CHROME_OMNIBOX, rlz_lib::CHROME_HOME_PAGE, rlz_lib::NO_ACCESS_POINT}; - std::string brand_ascii(WideToASCII(brand)); std::string lang_ascii(WideToASCII(lang)); std::string referral_ascii(WideToASCII(referral)); @@ -114,19 +108,19 @@ bool SendFinancialPing(const std::wstring& brand, // We ignore the return value of SendFinancialPing() since we'll try again // later anyway. Callers of this function are only interested in whether // the ping for the main brand succeeded or not. - std::wstring reactivation_brand; - if (GoogleUpdateSettings::GetReactivationBrand(&reactivation_brand)) { - std::string reactivation_brand_ascii(WideToASCII(reactivation_brand)); - rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); + std::string reactivation_brand; + if (google_util::GetReactivationBrand(&reactivation_brand)) { + string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand); + rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str()); rlz_lib::SendFinancialPing(rlz_lib::CHROME, points, "chrome", - reactivation_brand_ascii.c_str(), + reactivation_brand.c_str(), referral_ascii.c_str(), lang_ascii.c_str(), - exclude_id, NULL, true); + false, NULL, true); } return rlz_lib::SendFinancialPing(rlz_lib::CHROME, points, "chrome", - brand_ascii.c_str(), referral_ascii.c_str(), - lang_ascii.c_str(), exclude_id, NULL, true); + brand.c_str(), referral_ascii.c_str(), + lang_ascii.c_str(), false, NULL, true); } } // namespace @@ -212,9 +206,9 @@ void RLZTracker::ScheduleDelayedInit(int delay) { void RLZTracker::DelayedInit() { // For organic brandcodes do not use rlz at all. Empty brandcode usually // means a chromium install. This is ok. - std::wstring brand; - if (!GoogleUpdateSettings::GetBrand(&brand) || brand.empty() || - GoogleUpdateSettings::IsOrganic(brand)) + std::string brand; + if (!google_util::GetBrand(&brand) || brand.empty() || + google_util::IsOrganic(brand)) return; RecordProductEvents(first_run_, google_default_search_, @@ -223,9 +217,10 @@ void RLZTracker::DelayedInit() { // If chrome has been reactivated, record the events for this brand // as well. - std::wstring reactivation_brand; - if (GoogleUpdateSettings::GetReactivationBrand(&reactivation_brand)) { - rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); + std::string reactivation_brand; + if (google_util::GetReactivationBrand(&reactivation_brand)) { + string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand); + rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str()); RecordProductEvents(first_run_, google_default_search_, google_default_homepage_, already_ran_, omnibox_used_, homepage_used_); @@ -250,15 +245,15 @@ void RLZTracker::PingNowImpl() { // This is the entry point of a background thread, so I/O is allowed. base::ThreadRestrictions::ScopedAllowIO allow_io; - std::wstring lang; + string16 lang; GoogleUpdateSettings::GetLanguage(&lang); if (lang.empty()) lang = L"en"; - std::wstring brand; - GoogleUpdateSettings::GetBrand(&brand); - std::wstring referral; + std::string brand; + google_util::GetBrand(&brand); + string16 referral; GoogleUpdateSettings::GetReferral(&referral); - if (SendFinancialPing(brand, lang, referral, is_organic(brand))) { + if (SendFinancialPing(brand, lang, referral)) { GoogleUpdateSettings::ClearReferral(); { @@ -272,11 +267,10 @@ void RLZTracker::PingNowImpl() { } } -bool RLZTracker::SendFinancialPing(const std::wstring& brand, - const std::wstring& lang, - const std::wstring& referral, - bool exclude_id) { - return ::SendFinancialPing(brand, lang, referral, exclude_id); +bool RLZTracker::SendFinancialPing(const std::string& brand, + const string16& lang, + const string16& referral) { + return ::SendFinancialPing(brand, lang, referral); } void RLZTracker::Observe(int type, @@ -336,9 +330,10 @@ bool RLZTracker::RecordProductEvent(rlz_lib::Product product, bool ret = rlz_lib::RecordProductEvent(product, point, event_id); // If chrome has been reactivated, record the event for this brand as well. - std::wstring reactivation_brand; - if (GoogleUpdateSettings::GetReactivationBrand(&reactivation_brand)) { - rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); + std::string reactivation_brand; + if (google_util::GetReactivationBrand(&reactivation_brand)) { + string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand); + rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str()); ret &= rlz_lib::RecordProductEvent(product, point, event_id); } @@ -348,14 +343,14 @@ bool RLZTracker::RecordProductEvent(rlz_lib::Product product, // GetAccessPointRlz() caches RLZ strings for all access points. If we had // a successful ping, then we update the cached value. bool RLZTracker::GetAccessPointRlz(rlz_lib::AccessPoint point, - std::wstring* rlz) { + string16* rlz) { return GetInstance()->GetAccessPointRlzImpl(point, rlz); } // GetAccessPointRlz() caches RLZ strings for all access points. If we had // a successful ping, then we update the cached value. bool RLZTracker::GetAccessPointRlzImpl(rlz_lib::AccessPoint point, - std::wstring* rlz) { + string16* rlz) { // If the RLZ string for the specified access point is already cached, // simply return its value. { @@ -376,7 +371,7 @@ bool RLZTracker::GetAccessPointRlzImpl(rlz_lib::AccessPoint point, if (!rlz_lib::GetAccessPointRlz(point, str_rlz, rlz_lib::kMaxRlzLength, NULL)) return false; - std::wstring rlz_local(ASCIIToWide(std::string(str_rlz))); + string16 rlz_local(ASCIIToWide(std::string(str_rlz))); if (rlz) *rlz = rlz_local; @@ -389,7 +384,7 @@ bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) return false; - std::wstring* not_used = NULL; + string16* not_used = NULL; BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, NewRunnableFunction(&RLZTracker::GetAccessPointRlz, point, not_used)); diff --git a/chrome/browser/rlz/rlz.h b/chrome/browser/rlz/rlz.h index c335cbd..e30f8cc 100644 --- a/chrome/browser/rlz/rlz.h +++ b/chrome/browser/rlz/rlz.h @@ -16,6 +16,7 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "base/memory/singleton.h" +#include "base/string16.h" #include "base/task.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" @@ -52,7 +53,7 @@ class RLZTracker : public NotificationObserver { // Get the RLZ value of the access point. // Returns false if the rlz string could not be obtained. In some cases // an empty string can be returned which is not an error. - static bool GetAccessPointRlz(rlz_lib::AccessPoint point, std::wstring* rlz); + static bool GetAccessPointRlz(rlz_lib::AccessPoint point, string16* rlz); // Invoked during shutdown to clean up any state created by RLZTracker. static void CleanupRlz(); @@ -94,7 +95,7 @@ class RLZTracker : public NotificationObserver { bool google_default_homepage); // Implementation called from RecordProductEvent() static method. - bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, std::wstring* rlz); + bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, string16* rlz); // Schedules the delayed initialization. This method is virtual to allow // tests to override how the scheduling is done. @@ -116,10 +117,9 @@ class RLZTracker : public NotificationObserver { // Sends the financial ping to the RLZ servers. This method is virtual to // allow tests to override. - virtual bool SendFinancialPing(const std::wstring& brand, - const std::wstring& lang, - const std::wstring& referral, - bool exclude_id); + virtual bool SendFinancialPing(const std::string& brand, + const string16& lang, + const string16& referral); // Tracker used for testing purposes only. If this value is non-NULL, it // will be returned from GetInstance() instead of the regular singleton. @@ -139,7 +139,7 @@ class RLZTracker : public NotificationObserver { // The cache must be protected by a lock since it may be accessed from // the UI thread for reading and the IO thread for reading and/or writing. base::Lock cache_lock_; - std::map<rlz_lib::AccessPoint, std::wstring> rlz_cache_; + std::map<rlz_lib::AccessPoint, string16> rlz_cache_; // Keeps track of whether the omnibox or host page have been used. bool omnibox_used_; diff --git a/chrome/browser/rlz/rlz_unittest.cc b/chrome/browser/rlz/rlz_unittest.cc index 2040f19..1c0416a 100644 --- a/chrome/browser/rlz/rlz_unittest.cc +++ b/chrome/browser/rlz/rlz_unittest.cc @@ -115,10 +115,9 @@ class TestRLZTracker : public RLZTracker { return !assume_not_ui_thread_; } - virtual bool SendFinancialPing(const std::wstring& brand, - const std::wstring& lang, - const std::wstring& referral, - bool exclude_id) OVERRIDE { + virtual bool SendFinancialPing(const std::string& brand, + const string16& lang, + const string16& referral) OVERRIDE { // Don't ping the server during tests. pingnow_called_ = true; @@ -159,7 +158,7 @@ void RlzLibTest::SetUp() { // so that the rlz_lib calls work. This needs to be done before we do the // override. - std::wstring temp_hklm_path = base::StringPrintf( + string16 temp_hklm_path = base::StringPrintf( L"%ls\\%ls", RegistryOverrideManager::kTempTestKeyPath, kRlzTempHklm); @@ -169,7 +168,7 @@ void RlzLibTest::SetUp() { temp_hklm_path.c_str(), KEY_READ)); - std::wstring temp_hkcu_path = base::StringPrintf( + string16 temp_hkcu_path = base::StringPrintf( L"%ls\\%ls", RegistryOverrideManager::kTempTestKeyPath, kRlzTempHkcu); @@ -189,7 +188,7 @@ void RlzLibTest::SetUp() { // Make sure a non-organic brand code is set in the registry or the RLZTracker // is pretty much a no-op. BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - std::wstring reg_path = dist->GetStateKey(); + string16 reg_path = dist->GetStateKey(); RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE); ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(google_update::kRegRLZBrandField, L"TEST")); @@ -467,7 +466,7 @@ TEST_F(RlzLibTest, GetAccessPointRlzOnIoThread) { // Set dummy RLZ string. rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString); - std::wstring rlz; + string16 rlz; tracker_.set_assume_not_ui_thread(true); EXPECT_TRUE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz)); @@ -478,7 +477,7 @@ TEST_F(RlzLibTest, GetAccessPointRlzNotOnIoThread) { // Set dummy RLZ string. rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString); - std::wstring rlz; + string16 rlz; tracker_.set_assume_not_ui_thread(false); EXPECT_FALSE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz)); @@ -488,7 +487,7 @@ TEST_F(RlzLibTest, GetAccessPointRlzIsCached) { // Set dummy RLZ string. rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString); - std::wstring rlz; + string16 rlz; tracker_.set_assume_not_ui_thread(false); EXPECT_FALSE(RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz)); @@ -507,7 +506,7 @@ TEST_F(RlzLibTest, PingUpdatesRlzCache) { rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, kOmniboxRlzString); rlz_lib::SetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, kHomepageRlzString); - std::wstring rlz; + string16 rlz; // Prime the cache. tracker_.set_assume_not_ui_thread(true); |