Skip to content

Commit

Permalink
Assume SystemUtil::IsWindowsX64() returns true
Browse files Browse the repository at this point in the history
  • Loading branch information
yukawa committed Oct 29, 2023
1 parent d3151bb commit 66b149f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 159 deletions.
6 changes: 2 additions & 4 deletions src/config/stats_config_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ bool WinStatsConfigUtilImpl::IsEnabled() {
#ifdef CHANNEL_DEV
return true;
#else // CHANNEL_DEV
const REGSAM sam_desired =
KEY_QUERY_VALUE | (SystemUtil::IsWindowsX64() ? KEY_WOW64_32KEY : 0);
constexpr REGSAM sam_desired = KEY_QUERY_VALUE | KEY_WOW64_32KEY;
// Like the crash handler, check the "ClientStateMedium" key first.
// Then we check "ClientState" key.
{
Expand Down Expand Up @@ -132,8 +131,7 @@ bool WinStatsConfigUtilImpl::SetEnabled(bool val) {
#endif // CHANNEL_DEV

ATL::CRegKey key;
const REGSAM sam_desired =
KEY_WRITE | (SystemUtil::IsWindowsX64() ? KEY_WOW64_32KEY : 0);
constexpr REGSAM sam_desired = KEY_WRITE | KEY_WOW64_32KEY;
LONG result = key.Create(HKEY_LOCAL_MACHINE, kOmahaUsageKey, REG_NONE,
REG_OPTION_NON_VOLATILE, sam_desired);
if (ERROR_SUCCESS != result) {
Expand Down
3 changes: 1 addition & 2 deletions src/win32/base/omaha_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ const wchar_t kClientStateKey[] =
const wchar_t kChannelKeyName[] = L"ap";

LONG OpenClientStateKey(CRegKey *key, REGSAM base_sam) {
const REGSAM sam_desired =
base_sam | (SystemUtil::IsWindowsX64() ? KEY_WOW64_32KEY : 0);
constexpr REGSAM sam_desired = base_sam | KEY_WOW64_32KEY;
return key->Create(HKEY_LOCAL_MACHINE, kClientStateKey, REG_NONE,
REG_OPTION_NON_VOLATILE, sam_desired);
}
Expand Down
168 changes: 20 additions & 148 deletions src/win32/base/omaha_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,22 @@ class RegistryEmulator {
static HKEY GetClientStateKey(REGSAM regsam) {
const REGSAM kReadWrite = (KEY_WRITE | KEY_READ);
const REGSAM kRead = KEY_READ;
if (SystemUtil::IsWindowsX64()) {
// 64-bit OS
const bool contain_wow64_64_key =
((regsam & KEY_WOW64_64KEY) == KEY_WOW64_64KEY);
const bool contain_wow64_32_key =
((regsam & KEY_WOW64_32KEY) == KEY_WOW64_32KEY);

EXPECT_TRUE(contain_wow64_32_key)
<< "KEY_WOW64_32KEY should be specified just in case.";

if ((regsam & kReadWrite) == kReadWrite) {
return contain_wow64_64_key ? kHKLM64_ClientState_ReadWrite
: kHKLM32_ClientState_ReadWrite;
}
if ((regsam & kRead) == kRead) {
return contain_wow64_64_key ? kHKLM64_ClientState_Read
: kHKLM32_ClientState_Read;
}
} else {
// 32-bit OS
if ((regsam & kReadWrite) == kReadWrite) {
return kHKLM32_ClientState_ReadWrite;
}
if ((regsam & kRead) == kRead) {
return kHKLM32_ClientState_Read;
}
// 64-bit OS
const bool contain_wow64_64_key =
((regsam & KEY_WOW64_64KEY) == KEY_WOW64_64KEY);
const bool contain_wow64_32_key =
((regsam & KEY_WOW64_32KEY) == KEY_WOW64_32KEY);

EXPECT_TRUE(contain_wow64_32_key)
<< "KEY_WOW64_32KEY should be specified just in case.";

if ((regsam & kReadWrite) == kReadWrite) {
return contain_wow64_64_key ? kHKLM64_ClientState_ReadWrite
: kHKLM32_ClientState_ReadWrite;
}
if ((regsam & kRead) == kRead) {
return contain_wow64_64_key ? kHKLM64_ClientState_Read
: kHKLM32_ClientState_Read;
}
ADD_FAILURE() << "Unexpected combination found. regsam = " << regsam;
return KRegKey_NotFound;
Expand Down Expand Up @@ -448,77 +438,9 @@ class RegistryEmulator {

} // namespace

class OmahaUtilTestOn32bitMachine : public testing::Test {
protected:
virtual void SetUp() {
SystemUtil::SetIsWindowsX64ModeForTest(
SystemUtil::IS_WINDOWS_X64_EMULATE_32BIT_MACHINE);
}

virtual void TearDown() {
SystemUtil::SetIsWindowsX64ModeForTest(
SystemUtil::IS_WINDOWS_X64_DEFAULT_MODE);
}
};

class OmahaUtilTestOn64bitMachine : public testing::Test {
protected:
virtual void SetUp() {
SystemUtil::SetIsWindowsX64ModeForTest(
SystemUtil::IS_WINDOWS_X64_EMULATE_64BIT_MACHINE);
}

virtual void TearDown() {
SystemUtil::SetIsWindowsX64ModeForTest(
SystemUtil::IS_WINDOWS_X64_DEFAULT_MODE);
}
};

#if defined(GOOGLE_JAPANESE_INPUT_BUILD)

TEST_F(OmahaUtilTestOn32bitMachine, ReadWriteClearChannel) {
RegistryEmulator<__COUNTER__> test;

// ClientStateKey does not exist.
test.property()->Clear();
test.property()->set_omaha_key_exists(false);
EXPECT_TRUE(OmahaUtil::WriteChannel(L"internal-stable"));
// The ClientState key should be created.
EXPECT_TRUE(test.property()->omaha_key_exists());
EXPECT_EQ(test.property()->ap_value(), L"internal-stable");
EXPECT_EQ(OmahaUtil::ReadChannel(), L"internal-stable");
EXPECT_TRUE(OmahaUtil::ClearChannel());
EXPECT_TRUE(test.property()->omaha_key_exists());
EXPECT_FALSE(test.property()->has_ap_value());
EXPECT_EQ(OmahaUtil::ReadChannel(), L"");

// ClientStateKey exists. "ap" value does not exist.
test.property()->Clear();
test.property()->set_omaha_key_exists(true);
EXPECT_TRUE(OmahaUtil::WriteChannel(L"internal-stable"));
EXPECT_TRUE(test.property()->omaha_key_exists());
EXPECT_EQ(test.property()->ap_value(), L"internal-stable");
EXPECT_EQ(OmahaUtil::ReadChannel(), L"internal-stable");
EXPECT_TRUE(OmahaUtil::ClearChannel());
EXPECT_TRUE(test.property()->omaha_key_exists());
EXPECT_FALSE(test.property()->has_ap_value());
EXPECT_EQ(OmahaUtil::ReadChannel(), L"");

// ClientStateKey exists. "ap" value exists.
test.property()->Clear();
test.property()->set_omaha_key_exists(true);
test.property()->mutable_ap_value()->assign(L"internal-dev");
EXPECT_TRUE(OmahaUtil::WriteChannel(L"internal-stable"));
EXPECT_TRUE(test.property()->omaha_key_exists());
EXPECT_EQ(test.property()->ap_value(), L"internal-stable");
EXPECT_EQ(OmahaUtil::ReadChannel(), L"internal-stable");
EXPECT_TRUE(OmahaUtil::ClearChannel());
EXPECT_TRUE(test.property()->omaha_key_exists());
EXPECT_FALSE(test.property()->has_ap_value());
EXPECT_EQ(OmahaUtil::ReadChannel(), L"");
}

TEST_F(OmahaUtilTestOn64bitMachine, ReadWriteClearChannel) {
TEST(OmahaUtilTestOn64bitMachine, ReadWriteClearChannel) {
RegistryEmulator<__COUNTER__> test;

// ClientStateKey does not exist.
Expand Down Expand Up @@ -560,30 +482,7 @@ TEST_F(OmahaUtilTestOn64bitMachine, ReadWriteClearChannel) {
EXPECT_EQ(OmahaUtil::ReadChannel(), L"");
}

TEST_F(OmahaUtilTestOn32bitMachine, WriteClearOmahaError) {
RegistryEmulator<__COUNTER__> test;

// ClientStateKey does not exist.
test.property()->Clear();
test.property()->set_omaha_key_exists(false);
EXPECT_TRUE(OmahaUtil::WriteOmahaError(L"xx", L"yy"));
// The ClientState key should be created.
EXPECT_TRUE(test.property()->omaha_key_exists());
EXPECT_EQ(test.property()->installer_result(), 1);
EXPECT_EQ(test.property()->installer_result_ui_string(), L"yy\r\nxx");

// If the header does not exist, CRLF disappears.
EXPECT_TRUE(OmahaUtil::WriteOmahaError(L"xx", L""));
EXPECT_EQ(test.property()->installer_result_ui_string(), L"xx");

// Check if we can clear the error code.
EXPECT_TRUE(OmahaUtil::ClearOmahaError());
EXPECT_TRUE(test.property()->omaha_key_exists());
EXPECT_EQ(test.property()->installer_result(), 0);
EXPECT_EQ(test.property()->installer_result_ui_string(), L"");
}

TEST_F(OmahaUtilTestOn64bitMachine, WriteClearOmahaError) {
TEST(OmahaUtilTestOn64bitMachine, WriteClearOmahaError) {
RegistryEmulator<__COUNTER__> test;

// ClientStateKey does not exist.
Expand All @@ -608,22 +507,7 @@ TEST_F(OmahaUtilTestOn64bitMachine, WriteClearOmahaError) {

#else // !GOOGLE_JAPANESE_INPUT_BUILD

TEST_F(OmahaUtilTestOn32bitMachine, ReadWriteClearChannel) {
RegistryEmulator<__COUNTER__> test;

// ClientStateKey does not exist.
test.property()->Clear();
test.property()->set_omaha_key_exists(false);
EXPECT_TRUE(OmahaUtil::WriteChannel(L"internal-stable"));
// The ClientState key should not be created.
EXPECT_FALSE(test.property()->omaha_key_exists());
EXPECT_TRUE(OmahaUtil::ClearChannel());
EXPECT_FALSE(test.property()->omaha_key_exists());
EXPECT_FALSE(test.property()->has_ap_value());
EXPECT_EQ(OmahaUtil::ReadChannel(), L"");
}

TEST_F(OmahaUtilTestOn64bitMachine, ReadWriteClearChannel) {
TEST(OmahaUtilTestOn64bitMachine, ReadWriteClearChannel) {
RegistryEmulator<__COUNTER__> test;

// ClientStateKey does not exist.
Expand All @@ -638,19 +522,7 @@ TEST_F(OmahaUtilTestOn64bitMachine, ReadWriteClearChannel) {
EXPECT_EQ(OmahaUtil::ReadChannel(), L"");
}

TEST_F(OmahaUtilTestOn32bitMachine, WriteClearOmahaError) {
RegistryEmulator<__COUNTER__> test;

// ClientStateKey does not exist.
test.property()->Clear();
test.property()->set_omaha_key_exists(false);
EXPECT_TRUE(OmahaUtil::WriteOmahaError(L"xx", L"yy"));
EXPECT_FALSE(test.property()->omaha_key_exists());
EXPECT_FALSE(test.property()->has_installer_result());
EXPECT_FALSE(test.property()->has_installer_result_ui_string());
}

TEST_F(OmahaUtilTestOn64bitMachine, WriteClearOmahaError) {
TEST(OmahaUtilTestOn64bitMachine, WriteClearOmahaError) {
RegistryEmulator<__COUNTER__> test;

// ClientStateKey does not exist.
Expand Down
8 changes: 3 additions & 5 deletions src/win32/custom_action/custom_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,9 @@ UINT __stdcall EnsureAllApplicationPackagesPermisssions(MSIHANDLE msi_handle) {
GetMozcComponentPath(mozc::kMozcTIP32))) {
return ERROR_INSTALL_FAILURE;
}
if (mozc::SystemUtil::IsWindowsX64()) {
if (!mozc::WinSandbox::EnsureAllApplicationPackagesPermisssion(
GetMozcComponentPath(mozc::kMozcTIP64))) {
return ERROR_INSTALL_FAILURE;
}
if (!mozc::WinSandbox::EnsureAllApplicationPackagesPermisssion(
GetMozcComponentPath(mozc::kMozcTIP64))) {
return ERROR_INSTALL_FAILURE;
}
return ERROR_SUCCESS;
}
Expand Down

0 comments on commit 66b149f

Please sign in to comment.