Skip to content

Commit 983503b

Browse files
author
Roger Tawa
committed
Don't clear brand for regular cros sessions.
If the brand code persisted in local prefs is empty, reinitialize to correct. Bug: 846033, 893451 Change-Id: I49cc299374d8530d3a46aee93cb7cb2518ff1dee Reviewed-on: https://chromium-review.googlesource.com/c/1272447 Reviewed-by: Xiyuan Xia <[email protected]> Reviewed-by: Wenzhao (Colin) Zang <[email protected]> Commit-Queue: Roger Tawa <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#599645}(cherry picked from commit 5d80e30) Reviewed-on: https://chromium-review.googlesource.com/c/1284532 Reviewed-by: Roger Tawa <[email protected]> Cr-Commit-Position: refs/branch-heads/3578@{#62} Cr-Branched-From: 4226ddf-refs/heads/master@{#599034}
1 parent 34fe7f7 commit 983503b

File tree

2 files changed

+93
-6
lines changed

2 files changed

+93
-6
lines changed

chrome/browser/chromeos/login/session/chrome_session_manager_browsertest.cc

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
#include "chrome/browser/chromeos/settings/stub_install_attributes.h"
2222
#include "chrome/browser/google/google_brand_chromeos.h"
2323
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
24+
#include "chrome/common/chrome_switches.h"
2425
#include "chromeos/chromeos_switches.h"
2526
#include "chromeos/system/fake_statistics_provider.h"
2627
#include "chromeos/system/statistics_provider.h"
28+
#include "components/user_manager/user_names.h"
2729
#include "content/public/test/test_utils.h"
2830
#include "google_apis/gaia/fake_gaia.h"
2931
#include "rlz/buildflags/buildflags.h"
@@ -235,13 +237,69 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerRlzTest, DeviceIsLocked) {
235237
}
236238

237239
IN_PROC_BROWSER_TEST_F(ChromeSessionManagerRlzTest, DeviceIsUnlocked) {
238-
// When the device is unlocked, the brand should be cleared after session
239-
// start.
240+
// When the device is unlocked, the brand should still stick after a
241+
// regular session start.
240242
stub_install_attributes()->set_device_locked(false);
241243
StartUserSession();
242-
EXPECT_EQ("", google_brand::chromeos::GetBrand());
244+
EXPECT_EQ("TEST", google_brand::chromeos::GetBrand());
245+
}
246+
247+
class GuestSessionRlzTest : public InProcessBrowserTest,
248+
public ::testing::WithParamInterface<bool> {
249+
public:
250+
GuestSessionRlzTest() : is_locked_(GetParam()) {}
251+
252+
protected:
253+
StubInstallAttributes* stub_install_attributes() {
254+
return scoped_stub_install_attributes_->Get();
255+
}
256+
257+
private:
258+
void SetUpInProcessBrowserTestFixture() override {
259+
// Set the default brand code to a known value.
260+
scoped_fake_statistics_provider_.reset(
261+
new system::ScopedFakeStatisticsProvider());
262+
scoped_fake_statistics_provider_->SetMachineStatistic(
263+
system::kRlzBrandCodeKey, "TEST");
264+
265+
// Lock the device as needed for this test.
266+
scoped_stub_install_attributes_ =
267+
std::make_unique<ScopedStubInstallAttributes>(
268+
StubInstallAttributes::CreateUnset());
269+
scoped_stub_install_attributes_->Get()->set_device_locked(is_locked_);
270+
271+
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
272+
}
273+
274+
void SetUpCommandLine(base::CommandLine* command_line) override {
275+
command_line->AppendSwitch(chromeos::switches::kGuestSession);
276+
command_line->AppendSwitch(::switches::kIncognito);
277+
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash");
278+
command_line->AppendSwitchASCII(
279+
chromeos::switches::kLoginUser,
280+
user_manager::GuestAccountId().GetUserEmail());
281+
}
282+
283+
// Test instance parameters.
284+
const bool is_locked_;
285+
286+
std::unique_ptr<system::ScopedFakeStatisticsProvider>
287+
scoped_fake_statistics_provider_;
288+
std::unique_ptr<ScopedStubInstallAttributes> scoped_stub_install_attributes_;
289+
290+
DISALLOW_COPY_AND_ASSIGN(GuestSessionRlzTest);
291+
};
292+
293+
IN_PROC_BROWSER_TEST_P(GuestSessionRlzTest, DeviceIsLocked) {
294+
const char* const expected_brand =
295+
stub_install_attributes()->IsDeviceLocked() ? "TEST" : "";
296+
EXPECT_EQ(expected_brand, google_brand::chromeos::GetBrand());
243297
}
244298

299+
INSTANTIATE_TEST_CASE_P(GuestSessionRlzTest,
300+
GuestSessionRlzTest,
301+
::testing::Values(false, true));
302+
245303
#endif // BUILDFLAG(ENABLE_RLZ)
246304

247305
} // namespace chromeos

chrome/browser/chromeos/login/session/user_session_manager.cc

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,15 @@ bool UserSessionManager::UserSessionsRestoreInProgress() const {
680680

681681
void UserSessionManager::InitRlz(Profile* profile) {
682682
#if BUILDFLAG(ENABLE_RLZ)
683-
if (!g_browser_process->local_state()->HasPrefPath(prefs::kRLZBrand)) {
683+
// Initialize the brand code in the local prefs if it does not exist yet or
684+
// if it is empty. The latter is to correct a problem in older builds where
685+
// an empty brand code would be persisted if the first login after OOBE was
686+
// a guest session.
687+
if (!g_browser_process->local_state()->HasPrefPath(prefs::kRLZBrand) ||
688+
g_browser_process->local_state()
689+
->Get(prefs::kRLZBrand)
690+
->GetString()
691+
.empty()) {
684692
// Read brand code asynchronously from an OEM data and repost ourselves.
685693
google_brand::chromeos::InitBrand(
686694
base::Bind(&UserSessionManager::InitRlz, AsWeakPtr(), profile));
@@ -1674,9 +1682,30 @@ void UserSessionManager::RestoreAuthSessionImpl(
16741682
void UserSessionManager::InitRlzImpl(Profile* profile,
16751683
const RlzInitParams& params) {
16761684
#if BUILDFLAG(ENABLE_RLZ)
1677-
// RLZ is disabled if disabled explicitly or if the device is not yet locked.
1685+
// If RLZ is disabled then clear the brand for the session.
1686+
//
1687+
// RLZ is disabled if disabled explicitly OR if the device's enrollment
1688+
// state is not yet known. The device's enrollment state is definitively
1689+
// known once the device is locked. Note that for enrolled devices, the
1690+
// enrollment login locks the device.
1691+
//
1692+
// There the following cases to consider when a session starts:
1693+
//
1694+
// 1) This is a regular session.
1695+
// 1a) The device is LOCKED. Thus, the enrollment state is KNOWN.
1696+
// 1b) The device is NOT LOCKED. This should only happen on the first
1697+
// regular login (due to lock race condition with this code) if the
1698+
// device is NOT enrolled; thus, the enrollment state is also KNOWN.
1699+
//
1700+
// 2) This is a guest session.
1701+
// 2a) The device is LOCKED. Thus, the enrollment state is KNOWN.
1702+
// 2b) The device is NOT locked. This should happen if ONLY Guest mode
1703+
// sessions have ever been used on this device. This is the only
1704+
// situation where the enrollment state is NOT KNOWN at this point.
1705+
16781706
PrefService* local_state = g_browser_process->local_state();
1679-
if (params.disabled || !InstallAttributes::Get()->IsDeviceLocked()) {
1707+
if (params.disabled || (profile->IsGuestSession() &&
1708+
!InstallAttributes::Get()->IsDeviceLocked())) {
16801709
// Empty brand code means an organic install (no RLZ pings are sent).
16811710
google_brand::chromeos::ClearBrandForCurrentSession();
16821711
}

0 commit comments

Comments
 (0)