cros: Convert access point rlz with dynamic brand code
Create an UpdateExistingAccessPointRlz function to convert the rlz strings with dynamic brand code. Bug: 846033 Change-Id: I1af461d7b617728e52f33b20d1b4ea66085978e2 Reviewed-on: https://chromium-review.googlesource.com/c/1263047 Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org> Reviewed-by: Roger Tawa <rogerta@chromium.org> Cr-Commit-Position: refs/heads/master@{#599020}
This commit is contained in:
@ -302,6 +302,8 @@ bool RLZTracker::Init(bool first_run,
|
||||
if (delegate_->IsBrandOrganic(brand_) &&
|
||||
delegate_->IsBrandOrganic(reactivation_brand_)) {
|
||||
SYSLOG(INFO) << "RLZ is disabled";
|
||||
} else {
|
||||
rlz_lib::UpdateExistingAccessPointRlz(brand_);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "base/path_service.h"
|
||||
#include "base/sequenced_task_runner.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_piece.h"
|
||||
#include "base/values.h"
|
||||
#include "chromeos/dbus/dbus_thread_manager.h"
|
||||
#include "chromeos/dbus/debug_daemon_client.h"
|
||||
@ -85,6 +86,30 @@ std::string GetKeyName(const std::string& key, Product product) {
|
||||
return key + "." + GetProductName(product) + "." + brand;
|
||||
}
|
||||
|
||||
// Uses |brand| to replace the brand code contained in |rlz|. No-op if |rlz| is
|
||||
// in incorrect format or already contains |brand|. Returns whether the
|
||||
// replacement took place.
|
||||
bool ConvertToDynamicRlz(const std::string& brand,
|
||||
std::string* rlz,
|
||||
AccessPoint access_point) {
|
||||
if (brand.size() != 4) {
|
||||
LOG(ERROR) << "Invalid brand code format: " + brand;
|
||||
return false;
|
||||
}
|
||||
// Do a sanity check for the rlz string format. It must start with a
|
||||
// single-digit rlz encoding version, followed by a two-alphanum access point
|
||||
// name, and a four-letter brand code.
|
||||
if (rlz->size() < 7 ||
|
||||
rlz->substr(1, 2) != GetAccessPointName(access_point)) {
|
||||
LOG(ERROR) << "Invalid rlz string format: " + *rlz;
|
||||
return false;
|
||||
}
|
||||
if (rlz->substr(3, 4) == brand)
|
||||
return false;
|
||||
rlz->replace(3, 4, brand);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const int RlzValueStoreChromeOS::kMaxRetryCount = 3;
|
||||
@ -180,6 +205,24 @@ bool RlzValueStoreChromeOS::ClearAccessPointRlz(AccessPoint access_point) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RlzValueStoreChromeOS::UpdateExistingAccessPointRlz(
|
||||
const std::string& brand) {
|
||||
DCHECK(SupplementaryBranding::GetBrand().empty());
|
||||
bool updated = false;
|
||||
for (int i = NO_ACCESS_POINT + 1; i < LAST_ACCESS_POINT; ++i) {
|
||||
AccessPoint access_point = static_cast<AccessPoint>(i);
|
||||
const std::string access_point_key =
|
||||
GetKeyName(kAccessPointKey, access_point);
|
||||
std::string rlz;
|
||||
if (rlz_store_->GetString(access_point_key, &rlz) &&
|
||||
ConvertToDynamicRlz(brand, &rlz, access_point)) {
|
||||
rlz_store_->SetString(access_point_key, rlz);
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
bool RlzValueStoreChromeOS::AddProductEvent(Product product,
|
||||
const char* event_rlz) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
|
@ -46,6 +46,7 @@ class RlzValueStoreChromeOS : public RlzValueStore {
|
||||
char* rlz,
|
||||
size_t rlz_size) override;
|
||||
bool ClearAccessPointRlz(AccessPoint access_point) override;
|
||||
bool UpdateExistingAccessPointRlz(const std::string& brand) override;
|
||||
|
||||
bool AddProductEvent(Product product, const char* event_rlz) override;
|
||||
bool ReadProductEvents(Product product,
|
||||
|
@ -353,6 +353,14 @@ bool SetAccessPointRlz(AccessPoint point, const char* new_rlz) {
|
||||
return store->WriteAccessPointRlz(point, normalized_rlz);
|
||||
}
|
||||
|
||||
bool UpdateExistingAccessPointRlz(const std::string& brand) {
|
||||
ScopedRlzValueStoreLock lock;
|
||||
RlzValueStore* store = lock.GetStore();
|
||||
if (!store || !store->HasAccess(RlzValueStore::kWriteAccess))
|
||||
return false;
|
||||
return store->UpdateExistingAccessPointRlz(brand);
|
||||
}
|
||||
|
||||
// Financial Server pinging functions.
|
||||
|
||||
bool FormFinancialPingRequest(Product product, const AccessPoint* access_points,
|
||||
|
@ -137,6 +137,13 @@ bool RLZ_LIB_API GetAccessPointRlz(AccessPoint point, char* rlz,
|
||||
// Access: HKCU write.
|
||||
bool RLZ_LIB_API SetAccessPointRlz(AccessPoint point, const char* new_rlz);
|
||||
|
||||
// Use |brand| to replace the brand code contained in existing access point RLZ
|
||||
// strings found in the RLZ data file. Return true if at least one access point
|
||||
// RLZ string is updated, otherwise return false (and the function is a no-op).
|
||||
// See https://crbug.com/846033.
|
||||
// Access: HKCU write.
|
||||
bool RLZ_LIB_API UpdateExistingAccessPointRlz(const std::string& brand);
|
||||
|
||||
// Financial Server pinging functions.
|
||||
// These functions deal with pinging the RLZ financial server and parsing and
|
||||
// acting upon the response. Clients should SendFinancialPing() to avoid needing
|
||||
|
@ -49,6 +49,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(OS_CHROMEOS)
|
||||
#include "base/files/important_file_writer.h"
|
||||
#include "chromeos/dbus/dbus_thread_manager.h"
|
||||
#include "chromeos/dbus/fake_debug_daemon_client.h"
|
||||
#include "rlz/chromeos/lib/rlz_value_store_chromeos.h"
|
||||
@ -229,6 +230,78 @@ TEST_F(RlzLibTest, SetAccessPointRlzOnlyOnce) {
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, rlz_50, 50));
|
||||
EXPECT_STREQ("First", rlz_50);
|
||||
}
|
||||
|
||||
TEST_F(RlzLibTest, UpdateExistingAccessPointRlz) {
|
||||
const std::string json_data = R"({
|
||||
"access_points": {
|
||||
"CA": {
|
||||
"_": "1CANPEC_enUS818"
|
||||
},
|
||||
"CB": {
|
||||
"_": "1CBNPE"
|
||||
},
|
||||
"CC": {
|
||||
"_": "1CANPEC_enUS818"
|
||||
}
|
||||
},
|
||||
"product_events": {
|
||||
"C": {
|
||||
"_": [ "CAS" ]
|
||||
}
|
||||
}
|
||||
})";
|
||||
ASSERT_TRUE(base::ImportantFileWriter::WriteFileAtomically(
|
||||
base::FilePath(rlz_lib::testing::RlzStoreFilenameStr()), json_data));
|
||||
// Verify that the initial values are read correctly.
|
||||
char data[50];
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_OMNIBOX, data, 50));
|
||||
EXPECT_STREQ("1CANPEC_enUS818", data);
|
||||
EXPECT_TRUE(
|
||||
rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_HOME_PAGE, data, 50));
|
||||
EXPECT_STREQ("1CBNPE", data);
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_APP_LIST, data, 50));
|
||||
EXPECT_STREQ("1CANPEC_enUS818", data);
|
||||
EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::CHROME, data, 50));
|
||||
EXPECT_STREQ("events=CAS", data);
|
||||
|
||||
// Verify that if the brand code doesn't consist of four letters, none of the
|
||||
// access point RLZ strings is updated.
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_OMNIBOX, data, 50));
|
||||
EXPECT_STREQ("1CANPEC_enUS818", data);
|
||||
EXPECT_TRUE(
|
||||
rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_HOME_PAGE, data, 50));
|
||||
EXPECT_STREQ("1CBNPE", data);
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_APP_LIST, data, 50));
|
||||
EXPECT_STREQ("1CANPEC_enUS818", data);
|
||||
|
||||
// Update the RLZ strings with a valid brand code. Verify that the RLZ string
|
||||
// is updated if it also has valid format.
|
||||
EXPECT_TRUE(rlz_lib::UpdateExistingAccessPointRlz("BMGD"));
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_OMNIBOX, data, 50));
|
||||
EXPECT_STREQ("1CABMGD_enUS818", data);
|
||||
// The RLZ string remains unchanged if it has fewer than seven characters.
|
||||
EXPECT_TRUE(
|
||||
rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_HOME_PAGE, data, 50));
|
||||
EXPECT_STREQ("1CBNPE", data);
|
||||
// The RLZ string remains unchanged if the access point names don't match.
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_APP_LIST, data, 50));
|
||||
EXPECT_STREQ("1CANPEC_enUS818", data);
|
||||
// The product events remain unchanged.
|
||||
EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::CHROME, data, 50));
|
||||
EXPECT_STREQ("events=CAS", data);
|
||||
|
||||
// Verify a second update is no-op.
|
||||
EXPECT_FALSE(rlz_lib::UpdateExistingAccessPointRlz("BMGD"));
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_OMNIBOX, data, 50));
|
||||
EXPECT_STREQ("1CABMGD_enUS818", data);
|
||||
EXPECT_TRUE(
|
||||
rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_HOME_PAGE, data, 50));
|
||||
EXPECT_STREQ("1CBNPE", data);
|
||||
EXPECT_TRUE(rlz_lib::GetAccessPointRlz(rlz_lib::CHROMEOS_APP_LIST, data, 50));
|
||||
EXPECT_STREQ("1CANPEC_enUS818", data);
|
||||
EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::CHROME, data, 50));
|
||||
EXPECT_STREQ("events=CAS", data);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(RlzLibTest, GetAccessPointRlz) {
|
||||
|
@ -50,6 +50,7 @@ class RlzValueStore {
|
||||
char* rlz, // At most kMaxRlzLength + 1 bytes
|
||||
size_t rlz_size) = 0;
|
||||
virtual bool ClearAccessPointRlz(AccessPoint access_point) = 0;
|
||||
virtual bool UpdateExistingAccessPointRlz(const std::string& brand) = 0;
|
||||
|
||||
// Product events.
|
||||
// Stores |event_rlz| for product |product| as product event.
|
||||
|
@ -34,6 +34,7 @@ class RlzValueStoreMac : public RlzValueStore {
|
||||
char* rlz,
|
||||
size_t rlz_size) override;
|
||||
bool ClearAccessPointRlz(AccessPoint access_point) override;
|
||||
bool UpdateExistingAccessPointRlz(const std::string& brand) override;
|
||||
|
||||
bool AddProductEvent(Product product, const char* event_rlz) override;
|
||||
bool ReadProductEvents(Product product,
|
||||
|
@ -132,6 +132,9 @@ bool RlzValueStoreMac::ClearAccessPointRlz(AccessPoint access_point) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RlzValueStoreMac::UpdateExistingAccessPointRlz(const std::string& brand) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RlzValueStoreMac::AddProductEvent(Product product,
|
||||
const char* event_rlz) {
|
||||
|
@ -254,6 +254,11 @@ bool RlzValueStoreRegistry::ClearAccessPointRlz(AccessPoint access_point) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RlzValueStoreRegistry::UpdateExistingAccessPointRlz(
|
||||
const std::string& brand) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RlzValueStoreRegistry::AddProductEvent(Product product,
|
||||
const char* event_rlz) {
|
||||
base::string16 event_rlz16(ASCIIToUTF16(event_rlz));
|
||||
|
@ -31,6 +31,7 @@ class RlzValueStoreRegistry : public RlzValueStore {
|
||||
char* rlz,
|
||||
size_t rlz_size) override;
|
||||
bool ClearAccessPointRlz(AccessPoint access_point) override;
|
||||
bool UpdateExistingAccessPointRlz(const std::string& brand) override;
|
||||
|
||||
bool AddProductEvent(Product product, const char* event_rlz) override;
|
||||
bool ReadProductEvents(Product product,
|
||||
|
Reference in New Issue
Block a user