Commit fd4f2300 authored by rogerta@chromium.org's avatar rogerta@chromium.org

Add support for reactivating a chrome install that originally used an

organic brand code.  Also added unit tests for reactivation since none
existed.

BUG=b/5683002
TEST=See unit tests.  Pings should only be sent out for non-organic brand
codes, and not for organic brand codes.  Should test will all four combinations
(main is either organic or not, and reactivation is either organic or not).
This only works with google chrome builds.  Chromium builds never send pings
regardless of brand codes.

Review URL: http://codereview.chromium.org/8726041

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112868 0039d316-1c4b-4281-b951-d872f2087c98
parent c0a311b5
......@@ -40,6 +40,10 @@ using content::BrowserThread;
namespace {
bool IsBrandOrganic(const std::string& brand) {
return brand.empty() || google_util::IsOrganic(brand);
}
void RecordProductEvents(bool first_run, bool google_default_search,
bool google_default_homepage, bool already_ran,
bool omnibox_used, bool homepage_used) {
......@@ -106,21 +110,6 @@ bool SendFinancialPing(const std::string& brand,
rlz_lib::NO_ACCESS_POINT};
std::string lang_ascii(WideToASCII(lang));
std::string referral_ascii(WideToASCII(referral));
// If chrome has been reactivated, send a ping for this brand as well.
// 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::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.c_str(),
referral_ascii.c_str(), lang_ascii.c_str(),
false, NULL, true);
}
return rlz_lib::SendFinancialPing(rlz_lib::CHROME, points, "chrome",
brand.c_str(), referral_ascii.c_str(),
lang_ascii.c_str(), false, NULL, true);
......@@ -209,34 +198,40 @@ void RLZTracker::ScheduleDelayedInit(int delay) {
}
void RLZTracker::DelayedInit() {
bool schedule_ping = false;
// For organic brandcodes do not use rlz at all. Empty brandcode usually
// means a chromium install. This is ok.
std::string brand;
if (!google_util::GetBrand(&brand) || brand.empty() ||
google_util::IsOrganic(brand))
return;
RecordProductEvents(first_run_, google_default_search_,
google_default_homepage_, already_ran_,
omnibox_used_, homepage_used_);
if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand)) {
RecordProductEvents(first_run_, google_default_search_,
google_default_homepage_, already_ran_,
omnibox_used_, homepage_used_);
schedule_ping = true;
}
// If chrome has been reactivated, record the events for this brand
// as well.
std::string reactivation_brand;
if (google_util::GetReactivationBrand(&reactivation_brand)) {
if (google_util::GetReactivationBrand(&reactivation_brand) &&
!IsBrandOrganic(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_);
schedule_ping = true;
}
already_ran_ = true;
ScheduleFinancialPing();
if (schedule_ping)
ScheduleFinancialPing();
}
void RLZTracker::ScheduleFinancialPing() {
// Investigate why _beginthread() is used here, and not chrome's threading
// API. Tracked in bug http://crbug.com/106213
_beginthread(PingNow, 0, this);
}
......@@ -254,11 +249,12 @@ void RLZTracker::PingNowImpl() {
GoogleUpdateSettings::GetLanguage(&lang);
if (lang.empty())
lang = L"en";
std::string brand;
google_util::GetBrand(&brand);
string16 referral;
GoogleUpdateSettings::GetReferral(&referral);
if (SendFinancialPing(brand, lang, referral)) {
std::string brand;
if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand) &&
SendFinancialPing(brand, lang, referral)) {
GoogleUpdateSettings::ClearReferral();
{
......@@ -270,6 +266,14 @@ void RLZTracker::PingNowImpl() {
GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, NULL);
GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL);
}
std::string reactivation_brand;
if (google_util::GetReactivationBrand(&reactivation_brand) &&
!IsBrandOrganic(reactivation_brand)) {
string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand);
rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str());
SendFinancialPing(reactivation_brand, lang, referral);
}
}
bool RLZTracker::SendFinancialPing(const std::string& brand,
......
......@@ -11,6 +11,7 @@
#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/env_vars.h"
......@@ -83,7 +84,7 @@ class TestRLZTracker : public RLZTracker {
using RLZTracker::DelayedInit;
using RLZTracker::Observe;
TestRLZTracker() : pingnow_called_(false), assume_not_ui_thread_(false) {
TestRLZTracker() : assume_not_ui_thread_(false) {
set_tracker(this);
}
......@@ -91,8 +92,8 @@ class TestRLZTracker : public RLZTracker {
set_tracker(NULL);
}
bool pingnow_called() const {
return pingnow_called_;
bool was_ping_sent_for_brand(const std::string& brand) const {
return pinged_brands_.count(brand) > 0;
}
void set_assume_not_ui_thread(bool assume_not_ui_thread) {
......@@ -118,8 +119,9 @@ class TestRLZTracker : public RLZTracker {
virtual bool SendFinancialPing(const std::string& brand,
const string16& lang,
const string16& referral) OVERRIDE {
// Don't ping the server during tests.
pingnow_called_ = true;
// Don't ping the server during tests, just pretend as if we did.
EXPECT_FALSE(brand.empty());
pinged_brands_.insert(brand);
// Set new access points RLZ string, like the actual server ping would have
// done.
......@@ -129,7 +131,7 @@ class TestRLZTracker : public RLZTracker {
return true;
}
bool pingnow_called_;
std::set<std::string> pinged_brands_;
bool assume_not_ui_thread_;
DISALLOW_COPY_AND_ASSIGN(TestRLZTracker);
......@@ -140,12 +142,17 @@ class RlzLibTest : public testing::Test {
virtual void TearDown() OVERRIDE;
protected:
void SetMainBrand(const char* brand);
void SetReactivationBrand(const char* brand);
void SetRegistryBrandValue(const wchar_t* name, const char* brand);
void SimulateOmniboxUsage();
void SimulateHomepageUsage();
void InvokeDelayedInit();
void ExpectEventRecorded(const char* event_name, bool expected);
void ExpectRlzPingSent(bool expected);
void ExpectReactivationRlzPingSent(bool expected);
TestRLZTracker tracker_;
RegistryOverrideManager override_manager_;
......@@ -187,17 +194,42 @@ 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();
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"));
SetMainBrand("TEST");
SetReactivationBrand("");
}
void RlzLibTest::TearDown() {
testing::Test::TearDown();
}
void RlzLibTest::SetMainBrand(const char* brand) {
SetRegistryBrandValue(google_update::kRegRLZBrandField, brand);
std::string check_brand;
google_util::GetBrand(&check_brand);
EXPECT_EQ(brand, check_brand);
}
void RlzLibTest::SetReactivationBrand(const char* brand) {
SetRegistryBrandValue(google_update::kRegRLZReactivationBrandField, brand);
std::string check_brand;
google_util::GetReactivationBrand(&check_brand);
EXPECT_EQ(brand, check_brand);
}
void RlzLibTest::SetRegistryBrandValue(const wchar_t* name,
const char* brand) {
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
string16 reg_path = dist->GetStateKey();
RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE);
if (*brand == 0) {
LONG result = key.DeleteValue(name);
ASSERT_TRUE(ERROR_SUCCESS == result || ERROR_FILE_NOT_FOUND == result);
} else {
string16 brand16 = ASCIIToWide(brand);
ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(name, brand16.c_str()));
}
}
void RlzLibTest::SimulateOmniboxUsage() {
tracker_.Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
content::NotificationService::AllSources(),
......@@ -227,7 +259,15 @@ void RlzLibTest::ExpectEventRecorded(const char* event_name, bool expected) {
}
void RlzLibTest::ExpectRlzPingSent(bool expected) {
EXPECT_EQ(expected, tracker_.pingnow_called());
std::string brand;
google_util::GetBrand(&brand);
EXPECT_EQ(expected, tracker_.was_ping_sent_for_brand(brand.c_str()));
}
void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) {
std::string brand;
google_util::GetReactivationBrand(&brand);
EXPECT_EQ(expected, tracker_.was_ping_sent_for_brand(brand.c_str()));
}
TEST_F(RlzLibTest, RecordProductEvent) {
......@@ -549,3 +589,47 @@ TEST_F(RlzLibTest, ObserveHandlesBadArgs) {
content::NotificationService::AllSources(),
content::Details<NavigationEntry>(&entry));
}
TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) {
SetReactivationBrand("REAC");
RLZTracker::InitRlzDelayed(true, 20, true, true);
InvokeDelayedInit();
ExpectRlzPingSent(true);
ExpectReactivationRlzPingSent(true);
}
TEST_F(RlzLibTest, ReactivationOrganicNonOrganic) {
SetMainBrand("GGLS");
SetReactivationBrand("REAC");
RLZTracker::InitRlzDelayed(true, 20, true, true);
InvokeDelayedInit();
ExpectRlzPingSent(false);
ExpectReactivationRlzPingSent(true);
}
TEST_F(RlzLibTest, ReactivationNonOrganicOrganic) {
SetMainBrand("TEST");
SetReactivationBrand("GGLS");
RLZTracker::InitRlzDelayed(true, 20, true, true);
InvokeDelayedInit();
ExpectRlzPingSent(true);
ExpectReactivationRlzPingSent(false);
}
TEST_F(RlzLibTest, ReactivationOrganicOrganic) {
SetMainBrand("GGLS");
SetReactivationBrand("GGRS");
RLZTracker::InitRlzDelayed(true, 20, true, true);
InvokeDelayedInit();
ExpectRlzPingSent(false);
ExpectReactivationRlzPingSent(false);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment