Fix the path used when looking at registry for some policies (#32628)

* Fix the path used when looking at registry for UserDataDir policy

This only overrides a specific case for UserDataDir when suffix is not appended.

Fixes https://github.com/brave/brave-browser/issues/41854

Co-authored-by: Simon Hong <shong@brave.com>
This commit is contained in:
Brian Clifton
2025-12-02 12:09:32 -07:00
committed by GitHub
co-authored by Simon Hong
parent fbceb44f69
commit ad6b43a4a8
2 changed files with 46 additions and 4 deletions
@@ -20,14 +20,12 @@ inline bool EndsWith(const std::wstring& value, const std::wstring& ending) {
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
}
#if defined(OFFICIAL_BUILD)
const wchar_t kPolicyRegistryKey[] =
L"SOFTWARE\\Policies\\BraveSoftware\\Brave-Browser";
L"SOFTWARE\\Policies\\BraveSoftware\\Brave";
#if defined(OFFICIAL_BUILD)
const wchar_t kUserDataDirNameSuffix[] =
L"\\BraveSoftware\\Brave-Browser\\User Data";
#else
const wchar_t kPolicyRegistryKey[] =
L"SOFTWARE\\Policies\\BraveSoftware\\Brave-Browser-Development";
const wchar_t kUserDataDirNameSuffix[] =
L"\\BraveSoftware\\Brave-Browser-Development\\User Data";
#endif
@@ -0,0 +1,44 @@
/* Copyright (c) 2025 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "chrome/install_static/user_data_dir.h"
#include <string>
#include "chrome/install_static/install_util.h"
namespace install_static {
std::wstring& BraveAppendChromeInstallSubDirectory(const InstallConstants& mode,
bool include_suffix,
std::wstring* path);
} // namespace install_static
#define AppendChromeInstallSubDirectory BraveAppendChromeInstallSubDirectory
#include <chrome/install_static/user_data_dir.cc>
#undef AppendChromeInstallSubDirectory
namespace install_static {
std::wstring& BraveAppendChromeInstallSubDirectory(const InstallConstants& mode,
bool include_suffix,
std::wstring* path) {
AppendChromeInstallSubDirectory(mode, include_suffix, path);
// Special case to handle the Policy version of the path for Brave.
// Brave uses `SOFTWARE\Policies\BraveSoftware\Brave`
// instead of `SOFTWARE\Policies\BraveSoftware\Brave-Browser`
if (!include_suffix && path->starts_with(L"SOFTWARE\\Policies\\") &&
path->ends_with(kProductPathName)) {
*path = path->substr(0, (path->length() - kProductPathNameLength));
path->append(L"Brave");
}
return *path;
}
} // namespace install_static