Skip to content

Commit

Permalink
Add BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
Browse files Browse the repository at this point in the history
This replaces the custom CHROME_CLEANER_OFFICIAL_BUILD define with a
standard chromium buildflag.

R=proberge

Bug: 981556
Change-Id: I692325007150942b375bf6b1cabe1e0a6b8ee2da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1686932
Reviewed-by: proberge <proberge@chromium.org>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/master@{#675059}
  • Loading branch information
JoeNotCharlesGoogle authored and Commit Bot committed Jul 5, 2019
1 parent 2e87fd8 commit 538fcc1
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 21 deletions.
8 changes: 8 additions & 0 deletions chrome/chrome_cleaner/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/buildflag_header.gni")
import("//chrome/chrome_cleaner/chrome_cleaner_args.gni")
import("//testing/test.gni")

# Generate a buildflag header so code can check is_official_chrome_cleaner_build.
buildflag_header("buildflags") {
header = "buildflags.h"
flags =
[ "IS_OFFICIAL_CHROME_CLEANER_BUILD=$is_official_chrome_cleaner_build" ]
}

group("engine_definitions") {
if (is_official_chrome_cleaner_build) {
deps = [
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_cleaner/components/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ source_set("components") {

deps = [
"//base",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/chrome_utils:chrome_util_lib",
"//chrome/chrome_cleaner/chrome_utils:extension_file_logger_lib",
"//chrome/chrome_cleaner/chrome_utils:extensions_util_lib",
Expand Down
3 changes: 2 additions & 1 deletion chrome/chrome_cleaner/components/recovery_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "base/process/launch.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/components/component_unpacker.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#include "chrome/chrome_cleaner/http/http_agent.h"
Expand Down Expand Up @@ -133,7 +134,7 @@ bool RecoveryComponent::IsAvailable() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
// Only add the recovery component in official builds, unless it's forced, and
// not if it's explicitly disabled.
#if defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
return !command_line->HasSwitch(kNoRecoveryComponentSwitch);
#else
return command_line->HasSwitch(kForceRecoveryComponentSwitch);
Expand Down
4 changes: 4 additions & 0 deletions chrome/chrome_cleaner/constants/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ source_set("common_strings") {
"common_registry_names.cc",
"common_registry_names.h",
]

public_deps = [
"//chrome/chrome_cleaner:buildflags",
]
}

source_set("uws_id") {
Expand Down
4 changes: 3 additions & 1 deletion chrome/chrome_cleaner/constants/chrome_cleaner_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"

#include "chrome/chrome_cleaner/buildflags.h"

namespace chrome_cleaner {

// Command line switches
Expand Down Expand Up @@ -163,7 +165,7 @@ const char kUserResponseTimeoutMinutesSwitch[] = "user-response-timeout";
// shouldn't be set if |kExecutionModeSwitch| is not ExecutionMode::kCleaner.
const char kWithCleanupModeLogsSwitch[] = "with-cleanup-mode-logs";

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
// Don't allow EnableSecureDllLoading to run when this is set. This is only to
// be used in tests.
const char kAllowUnsecureDLLsSwitch[] = "allow-unsecure-dlls";
Expand Down
4 changes: 3 additions & 1 deletion chrome/chrome_cleaner/constants/chrome_cleaner_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef CHROME_CHROME_CLEANER_CONSTANTS_CHROME_CLEANER_SWITCHES_H_
#define CHROME_CHROME_CLEANER_CONSTANTS_CHROME_CLEANER_SWITCHES_H_

#include "chrome/chrome_cleaner/buildflags.h"

namespace chrome_cleaner {

// Command line switches.
Expand Down Expand Up @@ -47,7 +49,7 @@ extern const char kUserResponseTimeoutMinutesSwitch[];
extern const char kWithCleanupModeLogsSwitch[];

// Unoffical build only switches.
#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
extern const char kAllowUnsecureDLLsSwitch[];
extern const char kRunWithoutSandboxForTestingSwitch[];
#endif // CHROME_CLEANER_OFFICIAL_BUILD
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_cleaner/engines/broker/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source_set("common") {
deps = [
":interface_metadata_observer",
"//base",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/constants:quarantine_constants",
"//chrome/chrome_cleaner/constants:uws_id",
Expand Down
3 changes: 2 additions & 1 deletion chrome/chrome_cleaner/engines/broker/engine_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/constants/quarantine_constants.h"
#include "chrome/chrome_cleaner/interfaces/engine_file_requests.mojom.h"
#include "chrome/chrome_cleaner/interfaces/engine_requests.mojom.h"
Expand Down Expand Up @@ -293,7 +294,7 @@ void EngineClient::InitializeAsync(InitializeCallback result_callback) {

// Expose the logging directory for writing debug logs.
base::FilePath logging_path;
#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
if (!GetAppDataProductDirectory(&logging_path))
LOG(ERROR) << "Couldn't get development log directory for sandboxed engine";
#endif
Expand Down
7 changes: 4 additions & 3 deletions chrome/chrome_cleaner/engines/broker/sandbox_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#include "chrome/chrome_cleaner/engines/common/engine_result_codes.h"
#include "chrome/chrome_cleaner/settings/settings.h"
#include "mojo/public/cpp/system/message_pipe.h"

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
Expand All @@ -33,7 +34,7 @@ namespace chrome_cleaner {

namespace {

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
ResultCode SpawnWithoutSandboxForTesting(
Engine::Name engine_name,
scoped_refptr<EngineClient> engine_client,
Expand Down Expand Up @@ -129,7 +130,7 @@ std::pair<ResultCode, scoped_refptr<EngineClient>> SpawnEngineSandbox(
connection_error_callback, mojo_task_runner,
std::move(interface_metadata_observer));

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
if (chrome_cleaner::Settings::GetInstance()
->run_without_sandbox_for_testing()) {
ResultCode result_code = SpawnWithoutSandboxForTesting(
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_cleaner/engines/target/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ source_set("common") {

deps = [
"//base",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/crash:crash_keys",
"//chrome/chrome_cleaner/engines/common",
Expand Down
9 changes: 5 additions & 4 deletions chrome/chrome_cleaner/engines/target/libraries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/engines/common/engine_resources.h"
#include "chrome/chrome_cleaner/os/digest_verifier.h"
#include "chrome/chrome_cleaner/os/file_path_sanitization.h"
Expand Down Expand Up @@ -67,7 +68,7 @@ bool ExtractEmbeddedLibraries(Engine::Name engine,

void VerifyEngineLibraryAllowed(Engine::Name engine,
const base::string16& requested_library) {
#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
if (Settings::GetInstance()->run_without_sandbox_for_testing())
return;
#endif
Expand All @@ -81,7 +82,7 @@ void VerifyEngineLibraryAllowed(Engine::Name engine,
}

void VerifyRunningInSandbox() {
#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
if (Settings::GetInstance()->run_without_sandbox_for_testing())
return;
#endif
Expand All @@ -98,7 +99,7 @@ extern "C" FARPROC WINAPI DllLoadHook(unsigned dliNotify, PDelayLoadInfo pdli) {

VerifyEngineLibraryAllowed(engine, requested_library);

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
const std::unordered_map<base::string16, base::string16>
library_replacements = GetLibraryTestReplacements(engine);
if (library_replacements.count(requested_library)) {
Expand Down Expand Up @@ -179,7 +180,7 @@ bool LoadAndValidateLibraries(Engine::Name engine,
// just because they can't be loaded.
const bool enable_validation = GetLibraryTestReplacements(engine).empty();

#if defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
CHECK(enable_validation)
<< "Library validation should not be disabled in official build";
#endif
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_cleaner/executables/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ template("chrome_cleaner_executable") {
":shutdown_sequence",
"//base",
"//build/win:default_exe_manifest",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/constants:version_header",
"//chrome/chrome_cleaner/crash:crashpad_lib",
Expand Down
5 changes: 3 additions & 2 deletions chrome/chrome_cleaner/executables/chrome_cleaner_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/version.h"
#include "base/win/scoped_com_initializer.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/components/recovery_component.h"
#include "chrome/chrome_cleaner/components/system_report_component.h"
#include "chrome/chrome_cleaner/components/system_restore_point_component.h"
Expand Down Expand Up @@ -107,7 +108,7 @@ void AddComponents(chrome_cleaner::MainController* main_controller,
base::CommandLine* command_line,
chrome_cleaner::JsonParserAPI* json_parser,
chrome_cleaner::SandboxedShortcutParser* shortcut_parser) {
#if defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
// Ensure that the system restore point component runs first.
main_controller->AddComponent(
std::make_unique<chrome_cleaner::SystemRestorePointComponent>(
Expand Down Expand Up @@ -308,7 +309,7 @@ chrome_cleaner::ResultCode ReturnWithResultCode(

bool self_delete = CanSelfDelete(result_code);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
#if defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
self_delete = self_delete &&
!command_line->HasSwitch(chrome_cleaner::kNoSelfDeleteSwitch);
#else
Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome_cleaner/ipc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ source_set("sandbox") {

deps = [
"//base",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/crash:crashpad_lib",
"//chrome/chrome_cleaner/os:common_os",
Expand Down Expand Up @@ -89,6 +90,7 @@ source_set("unittest_sources") {
":sandbox",
"//base",
"//base/test:test_support",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/interfaces:mojo_sandbox_hooks_test_interface",
"//chrome/chrome_cleaner/logging:common",
"//chrome/chrome_cleaner/os:common_os",
Expand Down
3 changes: 2 additions & 1 deletion chrome/chrome_cleaner/ipc/sandbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "base/synchronization/waitable_event.h"
#include "base/time/time.h"
#include "base/win/win_util.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#include "chrome/chrome_cleaner/crash/crash_reporter.h"
#include "chrome/chrome_cleaner/os/disk_util.h"
Expand Down Expand Up @@ -110,7 +111,7 @@ scoped_refptr<sandbox::TargetPolicy> GetSandboxPolicy(
sandbox::TargetPolicy::FAKE_USER_GDI_INIT, nullptr);
CHECK_EQ(sandbox::SBOX_ALL_OK, sandbox_result);

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
base::FilePath product_path;
GetAppDataProductDirectory(&product_path);
if (!product_path.value().empty()) {
Expand Down
3 changes: 2 additions & 1 deletion chrome/chrome_cleaner/ipc/sandbox_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "base/strings/string_util.h"
#include "base/test/multiprocess_test.h"
#include "base/win/scoped_handle.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/ipc/mojo_task_runner.h"
#include "chrome/chrome_cleaner/logging/scoped_logging.h"
#include "chrome/chrome_cleaner/os/disk_util.h"
Expand Down Expand Up @@ -149,7 +150,7 @@ MULTIPROCESS_TEST_MAIN(MockSandboxProcessMain) {
base::DeleteFile(temp_file, /*recursive=*/false);
}

#if defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
CHECK(!have_write_access);
#else
CHECK(have_write_access);
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_cleaner/os/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ source_set("common_os") {

deps = [
"//base",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/constants:version_header",
"//chrome/chrome_cleaner/proto:file_digest_proto",
Expand Down
5 changes: 3 additions & 2 deletions chrome/chrome_cleaner/os/secure_dll_loading.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include <windows.h>

#include "base/logging.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/os/secure_dll_loading.h"

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
#include "base/command_line.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#endif // CHROME_CLEANER_OFFICIAL_BUILD
Expand All @@ -17,7 +18,7 @@ namespace chrome_cleaner {
const wchar_t kEmptyDll[] = L"empty_dll.dll";

bool EnableSecureDllLoading() {
#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
// We can't use base::CommandLine::ForCurrentProcess() here because that
// initializes CommandLine, which breaks expectations later about CommandLine
// being unset.
Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome_cleaner/settings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ source_set("settings") {
deps = [
":settings_types",
"//base",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/constants:common_strings",
"//components/chrome_cleaner/public/constants:constants",
]
Expand Down Expand Up @@ -126,6 +127,7 @@ source_set("unittest_sources") {
":settings_definitions",
"//base",
"//base/test:test_support",
"//chrome/chrome_cleaner:buildflags",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/test:test_util",
"//components/chrome_cleaner/public/constants:constants",
Expand Down
3 changes: 2 additions & 1 deletion chrome/chrome_cleaner/settings/cleaner_settings_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#include "components/chrome_cleaner/public/constants/constants.h"
#include "components/chrome_cleaner/test/test_name_helper.h"
Expand Down Expand Up @@ -73,7 +74,7 @@ TEST_P(CleanerSettingsTest, CleanerLogsPermissions) {

bool logs_upload_allowed =
expect_logs_collection_enabled && !uploading_blocked_;
#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
if (!with_test_logging_url_)
logs_upload_allowed = false;
#endif
Expand Down
3 changes: 2 additions & 1 deletion chrome/chrome_cleaner/settings/reporter_settings_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/chrome_cleaner/settings/settings.h"

#include "base/command_line.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#include "components/chrome_cleaner/public/constants/constants.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -36,7 +37,7 @@ TEST_F(ReporterSettingsTest, ReporterLogsPermissions) {
EXPECT_EQ(sber, settings->logs_collection_enabled());

bool expect_logs_upload_allowed = sber && uploading_enabled;
#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
if (!with_test_logging_url)
expect_logs_upload_allowed = false;
#endif
Expand Down
5 changes: 3 additions & 2 deletions chrome/chrome_cleaner/settings/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "chrome/chrome_cleaner/buildflags.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#include "chrome/chrome_cleaner/settings/engine_settings.h"
#include "chrome/chrome_cleaner/settings/settings_definitions.h"
Expand Down Expand Up @@ -90,7 +91,7 @@ bool GetLogsUploadAllowed(const base::CommandLine& command_line,
if (command_line.HasSwitch(kNoReportUploadSwitch))
return false;

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
// Unofficial builds upload logs only if test a logging URL is specified.
if (!command_line.HasSwitch(kTestLoggingURLSwitch))
return false;
Expand Down Expand Up @@ -366,7 +367,7 @@ void Settings::Initialize(const base::CommandLine& command_line,
has_parent_pipe_handle_ =
command_line.HasSwitch(mojo::PlatformChannel::kHandleSwitch);

#if !defined(CHROME_CLEANER_OFFICIAL_BUILD)
#if !BUILDFLAG(IS_OFFICIAL_CHROME_CLEANER_BUILD)
remove_report_only_uws_ = command_line.HasSwitch(kRemoveScanOnlyUwS);
run_without_sandbox_for_testing_ =
command_line.HasSwitch(kRunWithoutSandboxForTestingSwitch);
Expand Down

0 comments on commit 538fcc1

Please sign in to comment.