0

Trim dependency creep in setup.exe by splitting RLZ into non-net and net bits.

This change introduces the //rlz:rlz_lib_no_network source_set for use
by Chrome's installer on Windows. This breaks a dependency on a slew of
networking pieces that bloat setup.exe. Results from building
chrome/installer/setup at r718552:

- before: 6536 build targets -- 2,590,720 bytes
- after : 2390 build targets -- 2,298,880 bytes

-   4,146 fewer build targets (63.43% reduction)
- 291,840 bytes smaller (11.26% reduction)

BUG=1026780

Change-Id: I99892e6b0b9f730e1467a9af1af55c42ddeb8903
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1932803
Reviewed-by: Roger Tawa <rogerta@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719145}
This commit is contained in:
Greg Thompson
2019-11-26 15:07:39 +00:00
committed by Commit Bot
parent 5a9394beac
commit b2170dcecf
27 changed files with 360 additions and 211 deletions

@ -42,7 +42,7 @@ if (is_win) {
"//components/crash/content/app:crash_export_thunks",
"//components/crash/content/app:run_as_crashpad_handler",
"//content/public/common:static_switches",
"//rlz:rlz_lib",
"//rlz:rlz_lib_no_network",
]
libs = [ "netapi32.lib" ]

@ -58,7 +58,8 @@
#include "chrome/installer/util/util_constants.h"
#include "chrome/installer/util/work_item.h"
#include "content/public/common/result_codes.h"
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/rlz_lib_clear.h"
#include "rlz/lib/supplementary_branding.h"
using base::win::RegKey;

@ -7,7 +7,7 @@
import("//testing/test.gni")
config("rlz_config") {
config("rlz_lib_config") {
defines = [ "RLZ_NETWORK_IMPLEMENTATION_CHROME_NET" ]
}
@ -27,32 +27,32 @@ source_set("rlz_utils") {
"lib/string_utils.h",
]
public_configs = [ ":rlz_config" ]
public_deps = [
"//base",
]
deps = [
"//base",
"//net",
"//third_party/zlib",
"//url",
]
}
if (!is_android) {
source_set("rlz_lib") {
source_set("rlz_lib_no_network") {
sources = [
"chromeos/lib/rlz_value_store_chromeos.cc",
"chromeos/lib/rlz_value_store_chromeos.h",
"ios/lib/machine_id_ios.cc",
"lib/crc8.cc",
"lib/crc8.h",
"lib/financial_ping.cc",
"lib/financial_ping.h",
"lib/machine_deal_win.h",
"lib/machine_id.cc",
"lib/machine_id.h",
"lib/rlz_lib.cc",
"lib/rlz_lib.h",
"lib/rlz_lib_clear.cc",
"lib/rlz_lib_clear.h",
"lib/rlz_value_store.h",
"lib/supplementary_branding.cc",
"lib/supplementary_branding.h",
"lib/time_util.h",
"mac/lib/machine_id_mac.cc",
"mac/lib/rlz_value_store_mac.h",
"mac/lib/rlz_value_store_mac.mm",
@ -70,27 +70,17 @@ if (!is_android) {
"win/lib/rlz_value_store_registry.h",
]
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
public_configs = [ ":rlz_config" ]
if (is_win) {
sources += [ "lib/time_util_win.cc" ]
} else {
sources += [ "lib/time_util_base.cc" ]
}
deps = [
":rlz_utils",
"//base",
"//base/third_party/dynamic_annotations",
"//net",
"//services/network/public/cpp:cpp",
"//services/network/public/mojom",
"//url",
]
if (is_posix) {
sources += [
"lib/recursive_cross_process_lock_posix.cc",
"lib/recursive_cross_process_lock_posix.h",
]
}
if (is_chromeos) {
deps += [
"//chromeos/dbus",
@ -114,6 +104,48 @@ if (!is_android) {
]
set_sources_assignment_filter(sources_assignment_filter)
}
if (is_posix) {
sources += [
"lib/recursive_cross_process_lock_posix.cc",
"lib/recursive_cross_process_lock_posix.h",
]
}
}
source_set("rlz_lib") {
sources = [
"lib/financial_ping.cc",
"lib/financial_ping.h",
"lib/rlz_lib.cc",
"lib/rlz_lib.h",
]
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
public_deps = [
":rlz_lib_no_network",
"//base",
]
deps = [
":rlz_utils",
"//base/third_party/dynamic_annotations",
"//net",
"//services/network/public/cpp:cpp",
"//services/network/public/mojom",
"//url",
]
if (is_chromeos) {
deps += [
"//chromeos/dbus",
"//chromeos/system",
]
}
public_configs = [ ":rlz_lib_config" ]
}
source_set("test_support") {
@ -122,15 +154,16 @@ if (!is_android) {
"test/rlz_test_helpers.cc",
"test/rlz_test_helpers.h",
]
deps = [
":rlz_lib",
public_deps = [
"//base",
"//base/test:test_support",
"//services/network/public/cpp:cpp",
"//testing/gtest",
]
deps = [
":rlz_lib",
]
if (is_chromeos) {
deps += [ "//chromeos/system" ]
public_deps += [ "//chromeos/system" ]
}
}

@ -25,10 +25,10 @@
#include "chromeos/system/factory_ping_embargo_check.h"
#include "chromeos/system/statistics_provider.h"
#include "dbus/bus.h"
#include "rlz/lib/financial_ping.h"
#include "rlz/lib/lib_values.h"
#include "rlz/lib/recursive_cross_process_lock_posix.h"
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/supplementary_branding.h"
#include "rlz/lib/time_util.h"
namespace rlz_lib {
@ -189,7 +189,7 @@ bool RlzValueStoreChromeOS::ReadPingTime(Product product, int64_t* time) {
// TODO(wzang): make sure time is correct (check that npupdate has updated
// successfully).
if (!HasRlzEmbargoEndDatePassed()) {
*time = FinancialPing::GetSystemTimeAsInt64();
*time = GetSystemTimeAsInt64();
return true;
}
@ -216,11 +216,8 @@ bool RlzValueStoreChromeOS::WriteAccessPointRlz(AccessPoint access_point,
// |new_rlz| will contain only install cohort. The second time it will
// contain both install and first search cohorts. Ignoring the second
// means the first search cohort will never be stored.
char dummy[kMaxRlzLength + 1];
if (ReadAccessPointRlz(access_point, dummy, base::size(dummy)) &&
dummy[0] != 0) {
if (HasAccessPointRlz(access_point))
return true;
}
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
rlz_store_->SetString(
@ -438,6 +435,13 @@ bool RlzValueStoreChromeOS::RemoveValueFromList(const std::string& list_name,
return true;
}
bool RlzValueStoreChromeOS::HasAccessPointRlz(AccessPoint access_point) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const auto* value =
rlz_store_->FindStringKey(GetKeyName(kAccessPointKey, access_point));
return value && !value->empty();
}
namespace {
// RlzValueStoreChromeOS keeps its data in memory and only writes it to disk

@ -77,6 +77,9 @@ class RlzValueStoreChromeOS : public RlzValueStore {
bool RemoveValueFromList(const std::string& list_name,
const base::Value& value);
// Returns true if the store contains |access_point|.
bool HasAccessPointRlz(AccessPoint access_point) const;
// In-memory store with RLZ data.
std::unique_ptr<base::DictionaryValue> rlz_store_;

@ -29,6 +29,7 @@
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/rlz_value_store.h"
#include "rlz/lib/string_utils.h"
#include "rlz/lib/time_util.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
@ -473,23 +474,6 @@ bool FinancialPing::ClearLastPingTime(Product product) {
return store->ClearPingTime(product);
}
int64_t FinancialPing::GetSystemTimeAsInt64() {
#if defined(OS_WIN)
FILETIME now_as_file_time;
// Relative to Jan 1, 1601 (UTC).
GetSystemTimeAsFileTime(&now_as_file_time);
LARGE_INTEGER integer;
integer.HighPart = now_as_file_time.dwHighDateTime;
integer.LowPart = now_as_file_time.dwLowDateTime;
return integer.QuadPart;
#else
// Seconds since epoch (Jan 1, 1970).
double now_seconds = base::Time::Now().ToDoubleT();
return static_cast<int64_t>(now_seconds * 1000 * 1000 * 10);
#endif
}
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
namespace test {

@ -58,11 +58,6 @@ class FinancialPing {
// Ping the financial server with request. Writes to RlzValueStore.
static PingResponse PingServer(const char* request, std::string* response);
// Returns the time relative to a fixed point in the past in multiples of
// 100 ns stepts. The point in the past is arbitrary but can't change, as the
// result of this value is stored on disk.
static int64_t GetSystemTimeAsInt64();
#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
static bool SetURLLoaderFactory(network::mojom::URLLoaderFactory* factory);
#endif

@ -28,6 +28,7 @@
#include "rlz/lib/machine_id.h"
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/rlz_value_store.h"
#include "rlz/lib/time_util.h"
#include "rlz/test/rlz_test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -224,7 +225,7 @@ static void SetLastPingTime(int64_t time, rlz_lib::Product product) {
}
TEST_F(FinancialPingTest, IsPingTime) {
int64_t now = rlz_lib::FinancialPing::GetSystemTimeAsInt64();
int64_t now = rlz_lib::GetSystemTimeAsInt64();
int64_t last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval;
SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER);
@ -276,7 +277,7 @@ TEST_F(FinancialPingTest, BrandingIsPingTime) {
if (!rlz_lib::SupplementaryBranding::GetBrand().empty())
return;
int64_t now = rlz_lib::FinancialPing::GetSystemTimeAsInt64();
int64_t now = rlz_lib::GetSystemTimeAsInt64();
int64_t last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval;
SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER);
@ -311,7 +312,7 @@ TEST_F(FinancialPingTest, BrandingIsPingTime) {
}
TEST_F(FinancialPingTest, ClearLastPingTime) {
int64_t now = rlz_lib::FinancialPing::GetSystemTimeAsInt64();
int64_t now = rlz_lib::GetSystemTimeAsInt64();
int64_t last_ping = now - rlz_lib::kEventsPingInterval + k1MinuteInterval;
SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER);

@ -0,0 +1,52 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef RLZ_LIB_MACHINE_DEAL_WIN_H_
#define RLZ_LIB_MACHINE_DEAL_WIN_H_
#include <stddef.h>
#include "rlz/lib/rlz_api.h"
// OEM Deal confirmation storage functions.
namespace rlz_lib {
// The maximum length of an access points RLZ in bytes.
const size_t kMaxDccLength = 128;
// Makes the OEM Deal Confirmation code writable by all users on the machine.
// This should be called before calling SetMachineDealCode from a non-admin
// account.
// Access: HKLM write.
bool RLZ_LIB_API CreateMachineState(void);
// Set the OEM Deal Confirmation Code (DCC). This information is used for RLZ
// initialization.
// Access: HKLM write, or
// HKCU read if rlz_lib::CreateMachineState() has been successfully called.
bool RLZ_LIB_API SetMachineDealCode(const char* dcc);
// Get the DCC cgi argument string to append to a daily ping.
// Should be used only by OEM deal trackers. Applications should use the
// GetMachineDealCode method which has an AccessPoint parameter.
// Access: HKLM read.
bool RLZ_LIB_API GetMachineDealCodeAsCgi(char* cgi, size_t cgi_size);
// Get the DCC value stored in registry.
// Should be used only by OEM deal trackers. Applications should use the
// GetMachineDealCode method which has an AccessPoint parameter.
// Access: HKLM read.
bool RLZ_LIB_API GetMachineDealCode(char* dcc, size_t dcc_size);
// Parses a ping response, checks if it is valid and sets the machine DCC
// from the response. The ping must also contain the current DCC value in
// order to be considered valid.
// Access: HKLM write;
// HKCU write if CreateMachineState() has been successfully called.
bool RLZ_LIB_API SetMachineDealCodeFromPingResponse(const char* response);
} // namespace rlz_lib
#endif // RLZ_LIB_MACHINE_DEAL_WIN_H_

@ -24,6 +24,10 @@
#include "rlz/lib/string_utils.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#if defined(OS_WIN)
#include "rlz/lib/machine_deal_win.h"
#endif
namespace {
// Event information returned from ping response.

@ -20,6 +20,7 @@
#include "rlz/lib/rlz_api.h"
#include "rlz/lib/rlz_enums.h"
#include "rlz/lib/supplementary_branding.h"
// Define one of
// + RLZ_NETWORK_IMPLEMENTATION_WIN_INET: Uses win inet to send financial pings.
@ -66,12 +67,8 @@ namespace rlz_lib {
// need be passed when running as SYSTEM.
// Functions which do not access registry will be marked with "no restrictions".
class ScopedRlzValueStoreLock;
// The maximum length of an access points RLZ in bytes.
const size_t kMaxRlzLength = 64;
// The maximum length of an access points RLZ in bytes.
const size_t kMaxDccLength = 128;
// The maximum length of a CGI string in bytes.
const size_t kMaxCgiLength = 2048;
@ -108,22 +105,6 @@ bool RLZ_LIB_API ClearProductEvent(Product product, AccessPoint point,
// Access: HKCU write.
bool RLZ_LIB_API ClearAllProductEvents(Product product);
// Clears all product-specifc state from the RLZ registry.
// Should be called during product uninstallation.
// This removes outstanding product events, product financial ping times,
// the product RLS argument (if any), and any RLZ's for access points being
// uninstalled with the product.
// access_points is an array terminated with NO_ACCESS_POINT.
// IMPORTANT: These are the access_points the product is removing as part
// of the uninstallation, not necessarily all the access points passed to
// SendFinancialPing() and GetPingParams().
// access_points can be NULL if no points are being uninstalled.
// No return value - this is best effort. Will assert in debug mode on
// failed attempts.
// Access: HKCU write.
void RLZ_LIB_API ClearProductState(Product product,
const AccessPoint* access_points);
// Get the RLZ value of the access point. If the access point is not Google, the
// RLZ will be the empty string and the function will return false.
// Access: HKCU read.
@ -239,82 +220,6 @@ bool RLZ_LIB_API GetPingParams(Product product,
const AccessPoint* access_points,
char* unescaped_cgi, size_t unescaped_cgi_size);
#if defined(OS_WIN)
// OEM Deal confirmation storage functions. OEM Deals are windows-only.
// Makes the OEM Deal Confirmation code writable by all users on the machine.
// This should be called before calling SetMachineDealCode from a non-admin
// account.
// Access: HKLM write.
bool RLZ_LIB_API CreateMachineState(void);
// Set the OEM Deal Confirmation Code (DCC). This information is used for RLZ
// initalization.
// Access: HKLM write, or
// HKCU read if rlz_lib::CreateMachineState() has been successfully called.
bool RLZ_LIB_API SetMachineDealCode(const char* dcc);
// Get the DCC cgi argument string to append to a daily ping.
// Should be used only by OEM deal trackers. Applications should use the
// GetMachineDealCode method which has an AccessPoint paramter.
// Access: HKLM read.
bool RLZ_LIB_API GetMachineDealCodeAsCgi(char* cgi, size_t cgi_size);
// Get the DCC value stored in registry.
// Should be used only by OEM deal trackers. Applications should use the
// GetMachineDealCode method which has an AccessPoint paramter.
// Access: HKLM read.
bool RLZ_LIB_API GetMachineDealCode(char* dcc, size_t dcc_size);
// Parses a ping response, checks if it is valid and sets the machine DCC
// from the response. The ping must also contain the current DCC value in
// order to be considered valid.
// Access: HKLM write;
// HKCU write if CreateMachineState() has been successfully called.
bool RLZ_LIB_API SetMachineDealCodeFromPingResponse(const char* response);
#endif
// Segment RLZ persistence based on branding information.
// All information for a given product is persisted under keys with the either
// product's name or its access point's name. This assumes that only
// one instance of the product is installed on the machine, and that only one
// product brand is associated with it.
//
// In some cases, a given product may be using supplementary brands. The RLZ
// information must be kept separately for each of these brands. To achieve
// this segmentation, scope all RLZ library calls that deal with supplementary
// brands within the lifetime of an rlz_lib::ProductBranding instance.
//
// For example, to record events for a supplementary brand, do the following:
//
// {
// rlz_lib::SupplementaryBranding branding("AAAA");
// // This call to RecordProductEvent is scoped to the AAAA brand.
// rlz_lib::RecordProductEvent(rlz_lib::DESKTOP, rlz_lib::GD_DESKBAND,
// rlz_lib::INSTALL);
// }
//
// // This call to RecordProductEvent is not scoped to any supplementary brand.
// rlz_lib::RecordProductEvent(rlz_lib::DESKTOP, rlz_lib::GD_DESKBAND,
// rlz_lib::INSTALL);
//
// In particular, this affects the recording of stateful events and the sending
// of financial pings. In the former case, a stateful event recorded while
// scoped to a supplementary brand will be recorded again when scoped to a
// different supplementary brand (or not scoped at all). In the latter case,
// the time skip check is specific to each supplementary brand.
class SupplementaryBranding {
public:
explicit SupplementaryBranding(const char* brand);
~SupplementaryBranding();
static const std::string& GetBrand();
private:
ScopedRlzValueStoreLock* lock_;
};
} // namespace rlz_lib
#endif // RLZ_LIB_RLZ_LIB_H_

@ -2,24 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The methods in this file belong conceptually to rlz_lib.cc. However, some
// programs depend on rlz only to call ClearAllProductEvents(), so this file
// contains this in fairly self-contained form to make it easier for linkers
// to strip away most of rlz. In particular, this file should not reference any
// symbols defined in financial_ping.cc.
#include "rlz/lib/rlz_lib_clear.h"
#include "rlz/lib/rlz_lib.h"
#include "base/lazy_instance.h"
#include "rlz/lib/assert.h"
#include "rlz/lib/rlz_value_store.h"
namespace rlz_lib {
bool ClearAllProductEvents(Product product) {
rlz_lib::ScopedRlzValueStoreLock lock;
rlz_lib::RlzValueStore* store = lock.GetStore();
if (!store || !store->HasAccess(rlz_lib::RlzValueStore::kWriteAccess))
ScopedRlzValueStoreLock lock;
RlzValueStore* store = lock.GetStore();
if (!store || !store->HasAccess(RlzValueStore::kWriteAccess))
return false;
bool result;
@ -29,9 +22,9 @@ bool ClearAllProductEvents(Product product) {
}
void ClearProductState(Product product, const AccessPoint* access_points) {
rlz_lib::ScopedRlzValueStoreLock lock;
rlz_lib::RlzValueStore* store = lock.GetStore();
if (!store || !store->HasAccess(rlz_lib::RlzValueStore::kWriteAccess))
ScopedRlzValueStoreLock lock;
RlzValueStore* store = lock.GetStore();
if (!store || !store->HasAccess(RlzValueStore::kWriteAccess))
return;
// Delete all product specific state.
@ -48,35 +41,4 @@ void ClearProductState(Product product, const AccessPoint* access_points) {
store->CollectGarbage();
}
static base::LazyInstance<std::string>::Leaky g_supplemental_branding;
SupplementaryBranding::SupplementaryBranding(const char* brand)
: lock_(new ScopedRlzValueStoreLock) {
if (!lock_->GetStore())
return;
if (!g_supplemental_branding.Get().empty()) {
ASSERT_STRING("ProductBranding: existing brand is not empty");
return;
}
if (brand == NULL || brand[0] == 0) {
ASSERT_STRING("ProductBranding: new brand is empty");
return;
}
g_supplemental_branding.Get() = brand;
}
SupplementaryBranding::~SupplementaryBranding() {
if (lock_->GetStore())
g_supplemental_branding.Get().clear();
delete lock_;
}
// static
const std::string& SupplementaryBranding::GetBrand() {
return g_supplemental_branding.Get();
}
} // namespace rlz_lib

31
rlz/lib/rlz_lib_clear.h Normal file

@ -0,0 +1,31 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef RLZ_LIB_RLZ_LIB_CLEAR_H_
#define RLZ_LIB_RLZ_LIB_CLEAR_H_
#include "rlz/lib/rlz_api.h"
#include "rlz/lib/rlz_enums.h"
namespace rlz_lib {
// Clears all product-specifc state from the RLZ registry.
// Should be called during product uninstallation.
// This removes outstanding product events, product financial ping times,
// the product RLS argument (if any), and any RLZ's for access points being
// uninstalled with the product.
// access_points is an array terminated with NO_ACCESS_POINT.
// IMPORTANT: These are the access_points the product is removing as part
// of the uninstallation, not necessarily all the access points passed to
// SendFinancialPing() and GetPingParams().
// access_points can be null if no points are being uninstalled.
// No return value - this is best effort. Will assert in debug mode on
// failed attempts.
// Access: HKCU write.
void RLZ_LIB_API ClearProductState(Product product,
const AccessPoint* access_points);
} // namespace rlz_lib
#endif // RLZ_LIB_RLZ_LIB_CLEAR_H_

@ -28,6 +28,7 @@
#include "rlz/lib/lib_values.h"
#include "rlz/lib/net_response_check.h"
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/rlz_lib_clear.h"
#include "rlz/lib/rlz_value_store.h"
#include "rlz/test/rlz_test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"

@ -0,0 +1,54 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "rlz/lib/supplementary_branding.h"
#include <string>
#include "base/no_destructor.h"
#include "rlz/lib/assert.h"
#include "rlz/lib/rlz_value_store.h"
namespace rlz_lib {
namespace {
std::string& GetSupplementaryBrandingStorage() {
static base::NoDestructor<std::string> instance;
return *instance;
}
} // namespace
SupplementaryBranding::SupplementaryBranding(const char* brand)
: lock_(new ScopedRlzValueStoreLock) {
if (!lock_->GetStore())
return;
auto& supplementary_brand = GetSupplementaryBrandingStorage();
if (!supplementary_brand.empty()) {
ASSERT_STRING("ProductBranding: existing brand is not empty");
return;
}
if (brand == nullptr || brand[0] == 0) {
ASSERT_STRING("ProductBranding: new brand is empty");
return;
}
supplementary_brand = brand;
}
SupplementaryBranding::~SupplementaryBranding() {
if (lock_->GetStore())
GetSupplementaryBrandingStorage().clear();
delete lock_;
}
// static
const std::string& SupplementaryBranding::GetBrand() {
return GetSupplementaryBrandingStorage();
}
} // namespace rlz_lib

@ -0,0 +1,56 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef RLZ_LIB_SUPPLEMENTARY_BRANDING_H_
#define RLZ_LIB_SUPPLEMENTARY_BRANDING_H_
#include <string>
namespace rlz_lib {
class ScopedRlzValueStoreLock;
// Segment RLZ persistence based on branding information.
// All information for a given product is persisted under keys with the either
// product's name or its access point's name. This assumes that only
// one instance of the product is installed on the machine, and that only one
// product brand is associated with it.
//
// In some cases, a given product may be using supplementary brands. The RLZ
// information must be kept separately for each of these brands. To achieve
// this segmentation, scope all RLZ library calls that deal with supplementary
// brands within the lifetime of an rlz_lib::ProductBranding instance.
//
// For example, to record events for a supplementary brand, do the following:
//
// {
// rlz_lib::SupplementaryBranding branding("AAAA");
// // This call to RecordProductEvent is scoped to the AAAA brand.
// rlz_lib::RecordProductEvent(rlz_lib::DESKTOP, rlz_lib::GD_DESKBAND,
// rlz_lib::INSTALL);
// }
//
// // This call to RecordProductEvent is not scoped to any supplementary brand.
// rlz_lib::RecordProductEvent(rlz_lib::DESKTOP, rlz_lib::GD_DESKBAND,
// rlz_lib::INSTALL);
//
// In particular, this affects the recording of stateful events and the sending
// of financial pings. In the former case, a stateful event recorded while
// scoped to a supplementary brand will be recorded again when scoped to a
// different supplementary brand (or not scoped at all). In the latter case,
// the time skip check is specific to each supplementary brand.
class SupplementaryBranding {
public:
explicit SupplementaryBranding(const char* brand);
~SupplementaryBranding();
static const std::string& GetBrand();
private:
ScopedRlzValueStoreLock* lock_;
};
} // namespace rlz_lib
#endif // RLZ_LIB_SUPPLEMENTARY_BRANDING_H_

19
rlz/lib/time_util.h Normal file

@ -0,0 +1,19 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef RLZ_LIB_TIME_UTIL_H_
#define RLZ_LIB_TIME_UTIL_H_
#include <stdint.h>
namespace rlz_lib {
// Returns the time relative to a fixed point in the past in multiples of 100 ns
// stepts. The point in the past is arbitrary but can't change, as the result of
// this value is stored on disk.
int64_t GetSystemTimeAsInt64();
} // namespace rlz_lib
#endif // RLZ_LIB_TIME_UTIL_H_

17
rlz/lib/time_util_base.cc Normal file

@ -0,0 +1,17 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "rlz/lib/time_util.h"
#include "base/time/time.h"
namespace rlz_lib {
int64_t GetSystemTimeAsInt64() {
// Seconds since epoch (Jan 1, 1970).
double now_seconds = base::Time::Now().ToDoubleT();
return static_cast<int64_t>(now_seconds * 1000 * 1000 * 10);
}
} // namespace rlz_lib

22
rlz/lib/time_util_win.cc Normal file

@ -0,0 +1,22 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "rlz/lib/time_util.h"
#include <windows.h>
namespace rlz_lib {
int64_t GetSystemTimeAsInt64() {
FILETIME now_as_file_time;
// Relative to Jan 1, 1601 (UTC).
::GetSystemTimeAsFileTime(&now_as_file_time);
LARGE_INTEGER integer;
integer.HighPart = now_as_file_time.dwHighDateTime;
integer.LowPart = now_as_file_time.dwLowDateTime;
return integer.QuadPart;
}
} // namespace rlz_lib

@ -11,7 +11,7 @@
#include "rlz/lib/assert.h"
#include "rlz/lib/lib_values.h"
#include "rlz/lib/recursive_cross_process_lock_posix.h"
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/supplementary_branding.h"
#import <Foundation/Foundation.h>
#include <pthread.h>

@ -20,6 +20,7 @@
#if defined(OS_WIN)
#include "base/win/registry.h"
#include "base/win/shlwapi.h"
#include "rlz/lib/machine_deal_win.h"
#elif defined(OS_POSIX)
#include "base/files/file_path.h"
#include "rlz/lib/rlz_value_store.h"

@ -6,8 +6,10 @@
#include <stddef.h>
#include "rlz/lib/machine_deal_win.h"
#include "rlz/lib/net_response_check.h"
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/rlz_lib_clear.h"
#define RLZ_DLL_EXPORT extern "C" __declspec(dllexport)

@ -17,6 +17,7 @@
#include "base/win/registry.h"
#include "rlz/lib/assert.h"
#include "rlz/lib/lib_values.h"
#include "rlz/lib/machine_deal_win.h"
#include "rlz/lib/net_response_check.h"
#include "rlz/win/lib/lib_mutex.h"
#include "rlz/win/lib/registry_util.h"

@ -8,7 +8,7 @@
#define RLZ_WIN_LIB_MACHINE_DEAL_H_
#include <string>
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/rlz_enums.h"
namespace rlz_lib {

@ -11,13 +11,14 @@
// These tests require write access to HKLM and HKCU, unless
// rlz_lib::CreateMachineState() has been successfully called.
#include "rlz/win/lib/machine_deal.h"
#include "base/logging.h"
#include "rlz/lib/machine_deal_win.h"
#include "rlz/test/rlz_test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "rlz/test/rlz_test_helpers.h"
#include "rlz/win/lib/machine_deal.h"
class MachineDealCodeHelper : public rlz_lib::MachineDealCode {
public:
static bool Clear() { return rlz_lib::MachineDealCode::Clear(); }

@ -5,7 +5,7 @@
// A library to manage RLZ information for access-points shared
// across different client applications.
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/machine_deal_win.h"
#include <windows.h>
#include <aclapi.h>

@ -10,8 +10,8 @@
#include "base/win/registry.h"
#include "rlz/lib/assert.h"
#include "rlz/lib/lib_values.h"
#include "rlz/lib/rlz_lib.h"
#include "rlz/lib/string_utils.h"
#include "rlz/lib/supplementary_branding.h"
#include "rlz/win/lib/registry_util.h"
using base::ASCIIToUTF16;