Commit e63be647 authored by Olivier Li's avatar Olivier Li Committed by Commit Bot

Add logging and chrome_utils directories

Bug: 830892
Change-Id: I8c121dff724dea526a7cc7ce198da51cc1b8d045
Reviewed-on: https://chromium-review.googlesource.com/1158719Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Commit-Queue: Oliver Li <olivierli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580163}
parent c6e5932f
......@@ -11,6 +11,7 @@ test("chrome_cleaner_unittests") {
]
deps = [
":other_executable_definitions",
"//chrome/chrome_cleaner/engines:resources",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
......@@ -18,6 +19,7 @@ test("chrome_cleaner_unittests") {
# Tests from sub-directories.
"//chrome/chrome_cleaner/http:unittest_sources",
"//chrome/chrome_cleaner/logging:unittest_sources",
"//chrome/chrome_cleaner/os:unittest_sources",
"//chrome/chrome_cleaner/pup_data:unittest_sources",
"//chrome/chrome_cleaner/settings:unittest_sources",
......@@ -34,3 +36,18 @@ test("chrome_cleaner_unittests") {
"//testing/gtest",
]
}
# This library should only be included in executable targets.
static_library("other_executable_definitions") {
sources = [
"//chrome/chrome_cleaner/logging/other_logging_definitions.cc",
"//chrome/chrome_cleaner/settings/other_settings_definitions.cc",
]
deps = [
"//chrome/chrome_cleaner/logging:logging_definitions",
"//chrome/chrome_cleaner/logging:noop_logging",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
"//chrome/chrome_cleaner/settings:settings_definitions",
]
}
include_rules = [
"+sandbox/win/src",
"+testing/gtest",
"+components/chrome_cleaner",
"+third_party/protobuf/src/google/protobuf",
]
# Copyright 2018 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.
source_set("chrome_util_lib") {
sources = [
"chrome_util.cc",
"chrome_util.h",
]
deps = [
"//base:base",
"//chrome/chrome_cleaner/os:common_os",
"//components/chrome_cleaner/public/constants:constants",
]
}
source_set("extensions_util_lib") {
sources = [
"extensions_util.cc",
"extensions_util.h",
]
deps = [
"//base:base",
"//chrome/chrome_cleaner/os:common_os",
]
}
source_set("unittest_sources") {
testonly = true
sources = [
"extensions_util_unittest.cc",
]
deps = [
":chrome_util_lib",
":extensions_util_lib",
"//base:base",
"//base/test:test_support",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/test:test_util",
"//testing/gtest",
]
}
include_rules = [
"+components/chrome_cleaner",
]
// Copyright 2018 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 "chrome/chrome_cleaner/chrome_utils/chrome_util.h"
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/strings/pattern.h"
#include "base/strings/string_util.h"
#include "base/win/registry.h"
#include "base/win/windows_version.h"
#include "chrome/chrome_cleaner/os/disk_util.h"
#include "chrome/chrome_cleaner/os/file_path_sanitization.h"
#include "chrome/chrome_cleaner/os/registry.h"
#include "chrome/chrome_cleaner/os/system_util.h"
#include "components/chrome_cleaner/public/constants/constants.h"
namespace chrome_cleaner {
// Chrome shortcut filename.
const wchar_t kChromeShortcutFilename[] = L"Google Chrome.lnk";
// The KO language version doesn't have the term Google in the filename.
const wchar_t kKOChromeShortcutFilename[] = L"Chrome.lnk";
bool RetrieveChromeVersionAndInstalledDomain(base::string16* chrome_version,
bool* system_install) {
DCHECK(chrome_version);
const base::CommandLine* const command_line =
base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(kChromeVersionSwitch)) {
LOG(WARNING) << "Can't get Chrome version information from flag: "
<< "The " << kChromeVersionSwitch << " switch was not set.";
return false;
}
*chrome_version = command_line->GetSwitchValueNative(kChromeVersionSwitch);
// The system install flag should be set only by Chrome, in which case the
// Chrome version flag will also be set. Therefore, the presence or absence
// of the system install flag at this point fully determines whether or not
// we have a system-level install of Chrome.
if (system_install)
*system_install = command_line->HasSwitch(kChromeSystemInstallSwitch);
return true;
}
bool RetrieveChromeExePathFromCommandLine(base::FilePath* chrome_exe_path) {
DCHECK(chrome_exe_path);
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(kChromeExePathSwitch)) {
LOG(WARNING) << "Failed to locate Chrome executable from flag: "
<< "The " << kChromeExePathSwitch << " switch was not set.";
return false;
}
base::FilePath chrome_exe_from_flag =
command_line->GetSwitchValuePath(kChromeExePathSwitch);
if (!base::PathExists(chrome_exe_from_flag)) {
LOG(WARNING) << "Failed to locate Chrome executable from flag: "
<< kChromeExePathSwitch << " = '"
<< SanitizePath(chrome_exe_from_flag) << "'";
return false;
}
*chrome_exe_path = chrome_exe_from_flag;
return true;
}
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_CHROME_UTILS_CHROME_UTIL_H_
#define CHROME_CHROME_CLEANER_CHROME_UTILS_CHROME_UTIL_H_
#include <set>
#include "base/strings/string16.h"
namespace base {
class FilePath;
} // namespace base
namespace chrome_cleaner {
// Chrome shortcut filename.
extern const wchar_t kChromeShortcutFilename[];
// The KO language version doesn't have the term Google in the filename.
extern const wchar_t kKOChromeShortcutFilename[];
// Retrieve installed chrome version to |chrome_version|. The flag
// |system_install| receives whether the chrome is installed system wide or per
// user. |system_install| is optional and can be null.
// Return true on success.
bool RetrieveChromeVersionAndInstalledDomain(base::string16* chrome_version,
bool* system_install);
// Retrieve path to Chrome's executable from the path given on the command
// line. Return true if Chrome's exe path was given on the command line and the
// path exists.
bool RetrieveChromeExePathFromCommandLine(base::FilePath* chrome_exe_path);
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_CHROME_UTILS_CHROME_UTIL_H_
// Copyright 2018 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 "chrome/chrome_cleaner/chrome_utils/extensions_util.h"
#include "base/stl_util.h"
#include "base/win/registry.h"
#include "chrome/chrome_cleaner/os/registry_util.h"
#include "chrome/chrome_cleaner/os/system_util.h"
namespace chrome_cleaner {
namespace {
const int kExtensionIdLength = 32;
struct RegistryKey {
HKEY hkey;
const wchar_t* path;
};
const RegistryKey extension_forcelist_keys[] = {
{HKEY_LOCAL_MACHINE,
L"software\\policies\\google\\chrome\\ExtensionInstallForcelist"},
{HKEY_CURRENT_USER,
L"software\\policies\\google\\chrome\\ExtensionInstallForcelist"}};
void GetForcelistPoliciesForAccessMask(
REGSAM access_mask,
std::vector<ExtensionRegistryPolicy>* policies) {
for (size_t i = 0; i < base::size(extension_forcelist_keys); ++i) {
base::win::RegistryValueIterator forcelist_it(
extension_forcelist_keys[i].hkey, extension_forcelist_keys[i].path,
access_mask);
for (; forcelist_it.Valid(); ++forcelist_it) {
base::string16 entry;
GetRegistryValueAsString(forcelist_it.Value(), forcelist_it.ValueSize(),
forcelist_it.Type(), &entry);
// Extract the extension ID from the beginning of the registry entry,
// since it also contains an update URL.
if (entry.length() >= kExtensionIdLength) {
base::string16 extension_id = entry.substr(0, kExtensionIdLength);
policies->emplace_back(extension_id, extension_forcelist_keys[i].hkey,
extension_forcelist_keys[i].path,
forcelist_it.Name());
}
}
}
}
} // namespace
ExtensionRegistryPolicy::ExtensionRegistryPolicy(
const base::string16& extension_id,
HKEY hkey,
const base::string16& path,
const base::string16& name)
: extension_id(extension_id), hkey(hkey), path(path), name(name) {}
ExtensionRegistryPolicy::ExtensionRegistryPolicy(ExtensionRegistryPolicy&&) =
default;
ExtensionRegistryPolicy& ExtensionRegistryPolicy::operator=(
ExtensionRegistryPolicy&&) = default;
void GetExtensionForcelistRegistryPolicies(
std::vector<ExtensionRegistryPolicy>* policies) {
GetForcelistPoliciesForAccessMask(KEY_WOW64_32KEY, policies);
if (IsX64Architecture())
GetForcelistPoliciesForAccessMask(KEY_WOW64_64KEY, policies);
}
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_CHROME_UTILS_EXTENSIONS_UTIL_H_
#define CHROME_CHROME_CLEANER_CHROME_UTILS_EXTENSIONS_UTIL_H_
#include <vector>
#include "base/macros.h"
#include "chrome/chrome_cleaner/os/registry_util.h"
namespace chrome_cleaner {
// A registry key that holds some form of policy for |extension_id|.
struct ExtensionRegistryPolicy {
base::string16 extension_id;
HKEY hkey;
base::string16 path;
base::string16 name;
ExtensionRegistryPolicy(const base::string16& extension_id,
HKEY hkey,
const base::string16& path,
const base::string16& name);
ExtensionRegistryPolicy(ExtensionRegistryPolicy&&);
ExtensionRegistryPolicy& operator=(ExtensionRegistryPolicy&&);
DISALLOW_COPY_AND_ASSIGN(ExtensionRegistryPolicy);
};
// Find all extension forcelist registry policies and append to |policies|.
void GetExtensionForcelistRegistryPolicies(
std::vector<ExtensionRegistryPolicy>* policies);
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_CHROME_UTILS_EXTENSIONS_UTIL_H_
// Copyright 2018 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 "chrome/chrome_cleaner/chrome_utils/extensions_util.h"
#include <vector>
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_reg_util_win.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chrome_cleaner {
namespace {
const int kExtensionIdLength = 32;
struct TestRegistryEntry {
HKEY hkey;
const base::string16 path;
const base::string16 name;
const base::string16 value;
};
const TestRegistryEntry extension_forcelist_entries[] = {
{HKEY_LOCAL_MACHINE,
L"software\\policies\\google\\chrome\\ExtensionInstallForcelist", L"test1",
L"ababababcdcdcdcdefefefefghghghgh;https://clients2.google.com/service/"
L"update2/crx"},
{HKEY_CURRENT_USER,
L"software\\policies\\google\\chrome\\ExtensionInstallForcelist", L"test2",
L"aaaabbbbccccddddeeeeffffgggghhhh;https://clients2.google.com/service/"
L"update2/crx"}};
bool ExtensionPolicyFound(
TestRegistryEntry test_entry,
const std::vector<ExtensionRegistryPolicy>& found_policies) {
for (const ExtensionRegistryPolicy& policy : found_policies) {
base::string16 test_entry_value(test_entry.value);
if (policy.extension_id == test_entry_value.substr(0, kExtensionIdLength) &&
policy.hkey == test_entry.hkey && policy.path == test_entry.path &&
policy.name == test_entry.name) {
return true;
}
}
return false;
}
} // namespace
TEST(ExtensionsUtilTest, GetExtensionForcelistRegistryPolicies) {
registry_util::RegistryOverrideManager registry_override;
registry_override.OverrideRegistry(HKEY_CURRENT_USER);
registry_override.OverrideRegistry(HKEY_LOCAL_MACHINE);
for (const TestRegistryEntry& policy : extension_forcelist_entries) {
base::win::RegKey policy_key;
ASSERT_EQ(ERROR_SUCCESS, policy_key.Create(policy.hkey, policy.path.c_str(),
KEY_ALL_ACCESS));
DCHECK(policy_key.Valid());
ASSERT_EQ(ERROR_SUCCESS,
policy_key.WriteValue(policy.name.c_str(), policy.value.c_str()));
}
std::vector<ExtensionRegistryPolicy> policies;
GetExtensionForcelistRegistryPolicies(&policies);
for (const TestRegistryEntry& expected_result : extension_forcelist_entries) {
EXPECT_TRUE(ExtensionPolicyFound(expected_result, policies));
}
}
} // namespace chrome_cleaner
......@@ -15,7 +15,8 @@ namespace chrome_cleaner {
HttpAgentFactory::~HttpAgentFactory() = default;
std::unique_ptr<chrome_cleaner::HttpAgent> HttpAgentFactory::CreateHttpAgent() {
std::unique_ptr<chrome_cleaner::HttpAgent> HttpAgentFactory::CreateHttpAgent()
const {
std::unique_ptr<FileVersionInfo> file_version_info(
FileVersionInfo::CreateFileVersionInfoForModule(CURRENT_MODULE()));
......
......@@ -21,7 +21,7 @@ class HttpAgentFactory {
virtual ~HttpAgentFactory();
// Returns an HttpAgent instance.
virtual std::unique_ptr<chrome_cleaner::HttpAgent> CreateHttpAgent();
virtual std::unique_ptr<chrome_cleaner::HttpAgent> CreateHttpAgent() const;
};
} // namespace chrome_cleaner
......
......@@ -208,7 +208,7 @@ MockHttpAgentFactory::MockHttpAgentFactory(MockHttpAgentConfig* config)
}
std::unique_ptr<chrome_cleaner::HttpAgent>
MockHttpAgentFactory::CreateHttpAgent() {
MockHttpAgentFactory::CreateHttpAgent() const {
// Set the configuration index to the next one (one per HttpAgent).
if (config_->current_index_ == MockHttpAgentConfig::kInvalidIndex)
config_->current_index_ = 0;
......
......@@ -126,7 +126,7 @@ class MockHttpAgentFactory : public HttpAgentFactory {
explicit MockHttpAgentFactory(MockHttpAgentConfig* config);
// HttpAgentFactory:
std::unique_ptr<chrome_cleaner::HttpAgent> CreateHttpAgent() override;
std::unique_ptr<chrome_cleaner::HttpAgent> CreateHttpAgent() const override;
private:
MockHttpAgentConfig* config_{nullptr};
......
# Copyright 2018 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.
source_set("scoped_timed_task_logger") {
sources = [
"scoped_timed_task_logger.cc",
"scoped_timed_task_logger.h",
]
deps = [
"//base:base",
]
}
source_set("common") {
sources = [
"detailed_info_sampler.cc",
"detailed_info_sampler.h",
"info_sampler.h",
"logging_service_api.cc",
"logging_service_api.h",
"network_checker.h",
"registry_logger.cc",
"registry_logger.h",
"safe_browsing_reporter.cc",
"safe_browsing_reporter.h",
"scoped_logging.cc",
"scoped_logging.h",
"utils.cc",
"utils.h",
]
deps = [
":logging_definitions",
":scoped_timed_task_logger",
"//base:base",
"//chrome/chrome_cleaner//http:http", # For safe_browsing_reporter
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/constants:version_header",
"//chrome/chrome_cleaner/http:http_status_codes",
"//chrome/chrome_cleaner/logging/proto:removal_status_proto",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//chrome/chrome_cleaner/settings:settings",
"//chrome/chrome_cleaner/settings:settings_types",
"//components/chrome_cleaner/public/constants:constants",
"//url:url",
]
public_deps = [
"//chrome/chrome_cleaner/logging/proto:shared_data_proto",
"//net/traffic_annotation:traffic_annotation",
]
libs = [
"iphlpapi.lib", # For NotifyAddrChange.
"wininet.lib", # For InternetCheckConnection.
]
}
source_set("logging_definitions") {
sources = [
"logging_definitions.h",
]
}
source_set("dummy_api_keys") {
sources = [
"api_keys.h",
"dummy_api_keys.cc",
]
}
static_library("cleaner_logging") {
sources = [
"cleaner_logging_service.cc",
"cleaner_logging_service.h",
"message_builder.cc",
"message_builder.h",
"pending_logs_service.cc",
"pending_logs_service.h",
]
deps = [
"//base",
"//chrome/chrome_cleaner/chrome_utils:chrome_util_lib",
"//chrome/chrome_cleaner/constants:chrome_cleanup_tool_branding_header",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/constants:version_header",
"//chrome/chrome_cleaner/logging/proto:chrome_cleaner_report_proto",
"//chrome/chrome_cleaner/logging/proto:removal_status_proto",
"//chrome/chrome_cleaner/os:cleaner_os",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//chrome/chrome_cleaner/settings:settings",
"//chrome/chrome_cleaner/strings",
"//components/chrome_cleaner/public/constants:constants",
]
if (is_official_build) {
deps += [ "//chrome_cleaner_internal/logging:api_keys" ]
} else {
deps += [ ":dummy_api_keys" ]
}
public_deps = [
":common",
]
}
static_library("reporter_logging") {
sources = [
"reporter_logging_service.cc",
"reporter_logging_service.h",
]
deps = [
"//base",
"//chrome/chrome_cleaner/chrome_utils:chrome_util_lib",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/constants:version_header",
"//chrome/chrome_cleaner/logging:noop_logging",
"//chrome/chrome_cleaner/logging/proto:reporter_logs_proto",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//chrome/chrome_cleaner/settings:settings",
"//components/chrome_cleaner/public/constants:constants",
]
if (is_official_build) {
deps += [ "//chrome_cleaner_internal/logging:api_keys" ]
} else {
deps += [ ":dummy_api_keys" ]
}
public_deps = [
":common",
]
}
static_library("interface_log_service") {
sources = [
"interface_log_service.cc",
"interface_log_service.h",
]
deps = [
"//base:base",
"//chrome/chrome_cleaner/constants:version_header",
"//chrome/chrome_cleaner/os:common_os",
]
public_deps = [
"//chrome/chrome_cleaner/logging/proto:interface_logger_proto",
]
all_dependent_configs = [ "//third_party/protobuf:using_proto" ]
}
static_library("noop_logging") {
sources = [
"noop_logging_service.cc",
"noop_logging_service.h",
]
deps = [
":common",
"//base",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//components/chrome_cleaner/public/constants:constants",
]
}
source_set("mock_logging_service") {
testonly = true
sources = [
"mock_logging_service.cc",
"mock_logging_service.h",
]
deps = [
"//base",
"//chrome/chrome_cleaner/logging:common",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//components/chrome_cleaner/public/constants:constants",
"//testing/gmock",
]
}
source_set("test_utils") {
testonly = true
sources = [
"test_utils.cc",
"test_utils.h",
]
deps = [
":common",
"//base",
"//chrome/chrome_cleaner/logging/proto:shared_data_proto",
"//url",
]
}
source_set("unittest_sources") {
testonly = true
sources = [
"cleaner_logging_service_unittest.cc",
"detailed_info_sampler_unittest.cc",
"interface_log_service_unittest.cc",
"message_builder_unittest.cc",
"pending_logs_service_unittest.cc",
"registry_logger_unittest.cc",
"reporter_logging_service_unittest.cc",
"safe_browsing_reporter_unittest.cc",
"scoped_timed_task_logger_unittest.cc",
"utils_unittest.cc",
]
deps = [
":cleaner_logging",
":mock_logging_service",
":reporter_logging",
":test_utils",
"//base:base",
"//base/test:test_support",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/constants:version_header",
"//chrome/chrome_cleaner/http:http",
"//chrome/chrome_cleaner/http:mock_http_agent_factory",
"//chrome/chrome_cleaner/logging:interface_log_service",
"//chrome/chrome_cleaner/logging:scoped_timed_task_logger",
"//chrome/chrome_cleaner/logging/proto:chrome_cleaner_report_proto",
"//chrome/chrome_cleaner/logging/proto:interface_logger_proto",
"//chrome/chrome_cleaner/logging/proto:removal_status_proto",
"//chrome/chrome_cleaner/logging/proto:reporter_logs_proto",
"//chrome/chrome_cleaner/os:cleaner_os",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//chrome/chrome_cleaner/test:test_branding_header",
"//chrome/chrome_cleaner/test:test_pup_data",
"//chrome/chrome_cleaner/test:test_util",
"//chrome/chrome_cleaner/test/resources:test_resources",
"//components/chrome_cleaner/public/constants:constants",
"//net/traffic_annotation:test_support",
"//testing/gmock",
"//testing/gtest",
]
}
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_API_KEYS_H_
#define CHROME_CHROME_CLEANER_LOGGING_API_KEYS_H_
namespace chrome_cleaner {
extern const char* kSafeBrowsingCleanerUrl;
extern const char* kSafeBrowsingReporterUrl;
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_API_KEYS_H_
// Copyright 2018 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.
// Provides the logging service instance to be used by the cleaner executable.
#include "chrome/chrome_cleaner/logging/cleaner_logging_service.h"
#include "chrome/chrome_cleaner/logging/logging_definitions.h"
namespace chrome_cleaner {
LoggingServiceAPI* GetLoggingServiceForCurrentBuild() {
return CleanerLoggingService::GetInstance();
}
} // namespace chrome_cleaner
This diff is collapsed.
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_CLEANER_LOGGING_SERVICE_H_
#define CHROME_CHROME_CLEANER_LOGGING_CLEANER_LOGGING_SERVICE_H_
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "base/callback_forward.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "base/values.h"
#include "chrome/chrome_cleaner/logging/detailed_info_sampler.h"
#include "chrome/chrome_cleaner/logging/logging_service_api.h"
#include "chrome/chrome_cleaner/logging/message_builder.h"
#include "chrome/chrome_cleaner/logging/proto/chrome_cleaner_report.pb.h"
#include "chrome/chrome_cleaner/logging/proto/shared_data.pb.h"
#include "chrome/chrome_cleaner/logging/safe_browsing_reporter.h"
#include "chrome/chrome_cleaner/pup_data/pup_data.h"
#include "components/chrome_cleaner/public/constants/result_codes.h"
namespace chrome_cleaner {
// Auxiliary functions to convert Cleaner proto messages to their string
// equivalent and append the result to a MessageBuilder.
void AppendMatchedFile(const MatchedFile& file, MessageBuilder* builder);
void AppendFolderInformation(const FolderInformation& folder,
MessageBuilder* builder);
void AppendMatchedRegistryEntry(const MatchedRegistryEntry& registry,
MessageBuilder* builder);
// Return the enumerator corresponding to the value of the chrome prompt flag
// as set on the command line. Used to set the cleaner_startup field in the
// cleaner logs. Exposed for testing.
ChromeCleanerReport::CleanerStartup GetCleanerStartupFromCommandLine(
const base::CommandLine* command_line);
// Manage where the logs are sent, and expose an API for more specific logging.
class CleanerLoggingService : public LoggingServiceAPI {
public:
// Return the singleton instance which will get destroyed by the AtExitMgr.
static CleanerLoggingService* GetInstance();
// LoggingServiceAPI:
void Initialize(RegistryLogger* registry_logger) override;
void Terminate() override;
void SendLogsToSafeBrowsing(const UploadResultCallback& done_callback,
RegistryLogger* registry_logger) override;
void CancelWaitForShutdown() override;
void EnableUploads(bool enabled, RegistryLogger* registry_logger) override;
bool uploads_enabled() const override;
void SetDetailedSystemReport(bool detailed_system_report) override;
bool detailed_system_report_enabled() const override;
void AddFoundUwS(const std::string& found_uws_name) override;
void AddDetectedUwS(const PUPData::PUP* found_uws,
UwSDetectedFlags flags) override;
void AddDetectedUwS(const UwS& uws) override;
void SetExitCode(ResultCode exit_code) override;
void AddLoadedModule(
const base::string16& name,
ModuleHost host,
const internal::FileInformation& file_information) override;
void AddInstalledProgram(const base::FilePath& folder_path) override;
void AddService(const base::string16& display_name,
const base::string16& service_name,
const internal::FileInformation& file_information) override;
void AddProcess(const base::string16& name,
const internal::FileInformation& file_information) override;
void AddRegistryValue(
const internal::RegistryValue& registry_value,
const std::vector<internal::FileInformation>& file_informations) override;
void AddLayeredServiceProvider(
const std::vector<base::string16>& guids,
const internal::FileInformation& file_information) override;
void SetWinInetProxySettings(const base::string16& config,
const base::string16& bypass,
const base::string16& auto_config_url,
bool autodetect) override;
void SetWinHttpProxySettings(const base::string16& config,
const base::string16& bypass) override;
void AddInstalledExtension(const base::string16& extension_id,
ExtensionInstallMethod install_method) override;
void AddScheduledTask(
const base::string16& name,
const base::string16& description,
const std::vector<internal::FileInformation>& actions) override;
void LogProcessInformation(SandboxType process_type,
const SystemResourceUsage& usage) override;
bool AllExpectedRemovalsConfirmed() const override;
std::string RawReportContent() override;
bool ReadContentFromFile(const base::FilePath& log_file) override;
void ScheduleFallbackLogsUpload(RegistryLogger* registry_logger,
ResultCode result_code) override;
private:
friend struct base::DefaultSingletonTraits<CleanerLoggingService>;
CleanerLoggingService();
~CleanerLoggingService() override;
// Callback for |safe_browsing_reporter_|.
void OnReportUploadResult(const UploadResultCallback& done_callback,
RegistryLogger* registry_logger,
SafeBrowsingReporter::Result result,
const std::string& serialized_report,
std::unique_ptr<ChromeFoilResponse> response);
// Return true if |chrome_cleaner_report_|'s values have changed since it has
// been cleared.
bool IsReportingNeeded() const;
// Clears the temporary log file and it's associated scheduled task.
void ClearTempLogFile(RegistryLogger* registry_logger);
// Callback for logging::SetLogMessageHandler.
static bool LogMessageHandlerFunction(int severity,
const char* file,
int line,
size_t message_start,
const std::string& str);
// Returns a copy of |chrome_cleaner_report_| in |chrome_cleaner_report|, with
// an updated Client ID.
void GetCurrentChromeCleanerReport(
ChromeCleanerReport* chrome_cleaner_report);
// Adds all files and folder paths to the corresponding FileInformation and
// FolderInformation objects. Expects the lock to be held by the caller.
void UpdateMatchedFilesAndFoldersMaps(UwS* added_uws);
// Reads the removal status of all files and folders from
// FileRemovalStatusUpdater and updates them in the report.
void UpdateFileRemovalStatuses();
// Cache of the strings extracted from the proper locale resource.
mutable std::map<uint32_t, base::string16> resource_strings_cache_;
// Any access to |chrome_cleaner_report_|, |matched_files_|, and
// |matched_folders_| must be protected by |lock_|. While under this lock, no
// outside function calls and no logging (this includes DCHECK) should be
// made. Trying to log while under this lock will result in a deadlock, since
// adding log lines to our raw_log_lines field requires acquiring the lock,
// and we do not allow reentrancy.
mutable base::Lock lock_;
ChromeCleanerReport chrome_cleaner_report_;
// Map files and folder names to the corresponding MatchedFile and
// MatchedFolder objects, to allow updates after paths are collected by
// the scanner (e.g. to update removal status according to information given
// by the cleaner). Each file path is associated with a vector in case it's
// matched for more than one UwS.
std::unordered_map<std::string, std::vector<MatchedFile*>> matched_files_;
std::unordered_map<std::string, std::vector<MatchedFolder*>> matched_folders_;
// Saves raw log lines that will be uploaded in the cleaner report.
std::vector<std::string> raw_log_lines_buffer_;
mutable base::Lock raw_log_lines_buffer_lock_;
// |uploads_enabled| must only be accessed from the thread that created the
// CleanerLoggingService.
THREAD_CHECKER(thread_checker_);
// The path to the temporary log file to retry uploading in case we fail.
// Set as we register a task to retry the logs upload and cleared if another
// one is scheduled at a later stage and when the logs upload succeeds.
base::FilePath temp_log_file_;
// Default to false, so EnableUploads must be called to set it to true.
bool uploads_enabled_;
// Whether the logging service has been initialized.
bool initialized_;
// Sampler to choose which files to log detailed info for.
DetailedInfoSampler sampler_;
DISALLOW_COPY_AND_ASSIGN(CleanerLoggingService);
};
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_CLEANER_LOGGING_SERVICE_H_
// Copyright 2018 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 "chrome/chrome_cleaner/logging/detailed_info_sampler.h"
#include <algorithm>
#include <random>
#include <vector>
#include "base/files/file_path.h"
#include "base/rand_util.h"
#include "chrome/chrome_cleaner/os/disk_util.h"
namespace chrome_cleaner {
DetailedInfoSampler::DetailedInfoSampler(int max_files)
: max_files_(max_files) {}
void DetailedInfoSampler::SelectPathSetToSample(const FilePathSet& file_paths,
FilePathSet* paths_to_sample) {
std::vector<base::FilePath> active_paths = file_paths.ToVector();
std::shuffle(active_paths.begin(), active_paths.end(),
std::default_random_engine(base::RandDouble()));
// There might already be some files in |path_to_sample|, hence we use
// |selected_files| to count how many files we are adding.
int selected_files = 0;
for (auto it = active_paths.begin();
selected_files < max_files_ && it != active_paths.end(); it++) {
paths_to_sample->Insert(*it);
selected_files++;
}
}
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_DETAILED_INFO_SAMPLER_H_
#define CHROME_CHROME_CLEANER_LOGGING_DETAILED_INFO_SAMPLER_H_
#include <memory>
#include "chrome/chrome_cleaner/logging/info_sampler.h"
#include "chrome/chrome_cleaner/os/file_path_set.h"
namespace chrome_cleaner {
class DetailedInfoSampler : public InfoSampler {
public:
// Maximum number of files for which we will collect detailed information by
// default.
static constexpr int kDefaultMaxFiles = 5;
explicit DetailedInfoSampler(int max_files);
void SelectPathSetToSample(const FilePathSet& file_paths,
FilePathSet* paths_to_sample) override;
private:
int max_files_;
};
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_DETAILED_INFO_SAMPLER_H_
// Copyright 2018 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 "chrome/chrome_cleaner/logging/detailed_info_sampler.h"
#include "base/files/file_path.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chrome_cleaner {
namespace {
const wchar_t kBinaryPath1[] = L"C:\\Folder\\Binary1.exe";
const wchar_t kBinaryPath2[] = L"C:\\Folder\\Binary2.exe";
const wchar_t kBinaryPath3[] = L"C:\\Folder\\Binary3.exe";
const wchar_t kBinaryPath4[] = L"C:\\Folder\\Binary4.exe";
const unsigned int kMaxNumberOfFiles = 3;
} // namespace
TEST(DetailedInfoSamplingTest, SampleOneFile) {
FilePathSet files_to_sample;
files_to_sample.Insert(base::FilePath(kBinaryPath1));
FilePathSet selected_paths;
DetailedInfoSampler sampler(kMaxNumberOfFiles);
sampler.SelectPathSetToSample(files_to_sample, &selected_paths);
EXPECT_EQ(1UL, selected_paths.size());
}
TEST(DetailedInfoSamplingTest, SampleMaxFiles) {
FilePathSet files_to_sample;
files_to_sample.Insert(base::FilePath(kBinaryPath1));
files_to_sample.Insert(base::FilePath(kBinaryPath2));
files_to_sample.Insert(base::FilePath(kBinaryPath3));
files_to_sample.Insert(base::FilePath(kBinaryPath4));
ASSERT_LT(kMaxNumberOfFiles, files_to_sample.size());
DetailedInfoSampler sampler(kMaxNumberOfFiles);
FilePathSet selected_paths;
sampler.SelectPathSetToSample(files_to_sample, &selected_paths);
EXPECT_EQ(kMaxNumberOfFiles, selected_paths.size());
EXPECT_EQ(4UL, files_to_sample.size());
// Count how many of the original list were found in out newly populated set.
size_t nb_found = 0;
for (const auto& path : files_to_sample.ToVector()) {
if (selected_paths.Contains(path))
nb_found++;
}
EXPECT_EQ(kMaxNumberOfFiles, nb_found);
}
TEST(DetailedInfoSamplingTest, SampleEmptyVector) {
FilePathSet files_to_sample;
FilePathSet selected_paths;
DetailedInfoSampler sampler(kMaxNumberOfFiles);
sampler.SelectPathSetToSample(files_to_sample, &selected_paths);
EXPECT_EQ(0UL, selected_paths.size());
}
} // namespace chrome_cleaner
// Copyright 2018 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 "chrome/chrome_cleaner/logging/api_keys.h"
namespace chrome_cleaner {
const char* kSafeBrowsingCleanerUrl =
"https://sb-ssl.google.com/safebrowsing/clientreport/chrome-cct"
"?key=DUMMY_KEY";
const char* kSafeBrowsingReporterUrl =
"https://sb-ssl.google.com/safebrowsing/clientreport/chrome-sw-reporter"
"?key=DUMMY_KEY";
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_INFO_SAMPLER_H_
#define CHROME_CHROME_CLEANER_LOGGING_INFO_SAMPLER_H_
#include "chrome/chrome_cleaner/os/file_path_set.h"
namespace chrome_cleaner {
class InfoSampler {
public:
virtual void SelectPathSetToSample(const FilePathSet& file_paths,
FilePathSet* sampled_file_paths) = 0;
};
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_INFO_SAMPLER_H_
// Copyright 2018 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.
// Simple class that takes care of logging all the calls to a given interface.
//
// This should run on the IPC thread.
#include "chrome/chrome_cleaner/logging/interface_log_service.h"
#include <string>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/chrome_cleaner/constants/version.h"
#include "chrome/chrome_cleaner/logging/proto/interface_logger.pb.h"
#include "chrome/chrome_cleaner/os/disk_util.h"
namespace chrome_cleaner {
namespace {
base::FilePath GetPathForLogFile(const base::string16& log_file_name) {
base::FilePath app_data_path;
GetAppDataProductDirectory(&app_data_path);
base::FilePath log_file_path = app_data_path.Append(log_file_name);
return log_file_path;
}
} // namespace
base::TimeDelta InterfaceLogService::GetTicksSinceCreation() const {
return base::TimeTicks::Now() - ticks_at_creation_;
}
LogInformation::LogInformation(std::string function_name, std::string file_name)
: function_name(function_name), file_name(file_name) {}
// static
std::unique_ptr<InterfaceLogService> InterfaceLogService::Create(
const base::string16& file_name) {
if (file_name.empty())
return nullptr;
base::FilePath file_path = GetPathForLogFile(file_name);
std::string file_path_utf8;
if (!base::UTF16ToUTF8(file_path.value().c_str(), file_path.value().size(),
&file_path_utf8)) {
LOG(ERROR) << "Can't open interface log file " << file_path.value()
<< ": name is invalid" << std::endl;
return nullptr;
}
std::ofstream stream(file_path_utf8);
if (!stream.is_open()) {
PLOG(ERROR) << "Can't open interface log file " << file_path_utf8;
return nullptr;
}
return base::WrapUnique<InterfaceLogService>(
new InterfaceLogService(file_name, std::move(stream)));
}
InterfaceLogService::~InterfaceLogService() = default;
void InterfaceLogService::AddCall(
const LogInformation& log_information,
const std::map<std::string, std::string>& params) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_check_);
if (log_information.function_name.empty())
return;
int64_t microseconds_since_start = GetTicksSinceCreation().InMicroseconds();
APICall* new_call = call_record_.add_api_calls();
new_call->set_function_name(log_information.function_name);
new_call->set_file_name(log_information.file_name);
new_call->set_microseconds_since_start(microseconds_since_start);
new_call->mutable_parameters()->insert(params.begin(), params.end());
csv_stream_ << microseconds_since_start << "," << log_information.file_name
<< "," << log_information.function_name << ",";
for (const auto& name_value : params)
csv_stream_ << name_value.first << "=" << name_value.second << ";";
csv_stream_ << std::endl;
}
void InterfaceLogService::AddCall(const LogInformation& log_information) {
AddCall(log_information, {});
}
std::vector<APICall> InterfaceLogService::GetCallHistory() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_check_);
std::vector<APICall> call_history;
for (auto it = call_record_.api_calls().begin();
it != call_record_.api_calls().end(); it++) {
call_history.push_back(*it);
}
return call_history;
}
std::string InterfaceLogService::GetBuildVersion() const {
return call_record_.build_version();
}
base::FilePath InterfaceLogService::GetLogFilePath() const {
return GetPathForLogFile(log_file_name_);
}
InterfaceLogService::InterfaceLogService(const base::string16& file_name,
std::ofstream csv_stream)
: log_file_name_(file_name), csv_stream_(std::move(csv_stream)) {
DETACH_FROM_SEQUENCE(sequence_check_);
base::string16 build_version_utf16 = LASTCHANGE_STRING;
std::string build_version_utf8;
if (!base::UTF16ToUTF8(build_version_utf16.c_str(),
build_version_utf16.size(), &build_version_utf8)) {
LOG(ERROR) << "Cannot convert build version to utf8";
build_version_utf8 = "UNKNOWN";
}
call_record_.set_build_version(build_version_utf8);
// Write build version and column headers.
csv_stream_ << "buildVersion," << build_version_utf8 << std::endl;
csv_stream_ << "timeCalledTicks,fileName,functionName,functionArguments"
<< std::endl;
}
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_INTERFACE_LOG_SERVICE_H_
#define CHROME_CHROME_CLEANER_LOGGING_INTERFACE_LOG_SERVICE_H_
#include <fstream>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/sequence_checker.h"
#include "base/strings/string16.h"
#include "chrome/chrome_cleaner/logging/proto/interface_logger.pb.h"
namespace chrome_cleaner {
struct LogInformation {
LogInformation(std::string function_name, std::string file_name);
std::string function_name;
std::string file_name;
};
class InterfaceLogService {
public:
static std::unique_ptr<InterfaceLogService> Create(
const base::string16& file_name);
~InterfaceLogService();
// Logs a call to |function_name| from the given |class_name| and also logs
// the passed parameters recorded on |params|.
void AddCall(const LogInformation& log_information,
const std::map<std::string, std::string>& params);
// Logs a call to |function_name| without parameters.
void AddCall(const LogInformation& log_information);
// Exposes the underlying call_record_, this is for testing purposes and
// to provide a way to print or log the recorded calls.
std::vector<APICall> GetCallHistory() const;
// Returns the build version of all the logged function calls.
std::string GetBuildVersion() const;
base::FilePath GetLogFilePath() const;
private:
InterfaceLogService(const base::string16& file_name,
std::ofstream csv_stream);
// TODO(joenotcharles): Currently the CallHistory is only used in the unit
// test. Decide whether it's worth keeping.
CallHistory call_record_;
base::string16 log_file_name_;
SEQUENCE_CHECKER(sequence_check_);
// Stream to output CSV records to.
std::ofstream csv_stream_;
// Time at the creation of the object
base::TimeTicks ticks_at_creation_{base::TimeTicks::Now()};
base::TimeDelta GetTicksSinceCreation() const;
DISALLOW_COPY_AND_ASSIGN(InterfaceLogService);
};
// Define a macro to make easier the use of AddCall.
#define CURRENT_FILE_AND_METHOD LogInformation(__func__, __FILE__)
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_INTERFACE_LOG_SERVICE_H_
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_LOGGING_DEFINITIONS_H_
#define CHROME_CHROME_CLEANER_LOGGING_LOGGING_DEFINITIONS_H_
// All executable targets build in this project should contain one
// *_logging_definitions.cc file to ensure that this function is defined.
namespace chrome_cleaner {
class LoggingServiceAPI;
LoggingServiceAPI* GetLoggingServiceForCurrentBuild();
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_LOGGING_DEFINITIONS_H_
// Copyright 2018 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 "chrome/chrome_cleaner/logging/logging_service_api.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#include "chrome/chrome_cleaner/logging/logging_definitions.h"
#include "chrome/chrome_cleaner/os/pre_fetched_paths.h"
#include "chrome/chrome_cleaner/settings/settings.h"
namespace chrome_cleaner {
namespace {
const wchar_t kProtoExtension[] = L"pb";
} // namespace
// static
LoggingServiceAPI* LoggingServiceAPI::logging_service_for_testing_ = nullptr;
// static
LoggingServiceAPI* LoggingServiceAPI::GetInstance() {
if (logging_service_for_testing_)
return logging_service_for_testing_;
return GetLoggingServiceForCurrentBuild();
}
// static
void LoggingServiceAPI::SetInstanceForTesting(
LoggingServiceAPI* logging_service) {
logging_service_for_testing_ = logging_service;
}
void LoggingServiceAPI::MaybeSaveLogsToFile(const base::string16& tag) {
#if !defined(NDEBUG)
// Always dump the raw logs in debug builds.
const bool dump_raw_logs = true;
#else
const bool dump_raw_logs =
base::CommandLine::ForCurrentProcess()->HasSwitch(kDumpRawLogsSwitch);
#endif
if (dump_raw_logs) {
base::FilePath exe_file_path =
PreFetchedPaths::GetInstance()->GetExecutablePath();
base::FilePath log_file_path(exe_file_path.ReplaceExtension(kProtoExtension)
.InsertBeforeExtension(tag));
std::string logs_proto = RawReportContent();
base::WriteFile(log_file_path, logs_proto.c_str(), logs_proto.length());
}
}
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_LOGGING_SERVICE_API_H_
#define CHROME_CHROME_CLEANER_LOGGING_LOGGING_SERVICE_API_H_
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "chrome/chrome_cleaner/logging/utils.h"
#include "chrome/chrome_cleaner/os/process.h"
#include "chrome/chrome_cleaner/pup_data/pup_data.h"
#include "chrome/chrome_cleaner/settings/settings_types.h"
#include "components/chrome_cleaner/public/constants/result_codes.h"
namespace base {
class FilePath;
} // namespace base
namespace chrome_cleaner {
class RegistryLogger;
namespace internal {
struct FileInformation;
struct RegistryValue;
} // namespace internal
// Manage where the logs are sent, and expose an API for more specific logging.
class LoggingServiceAPI {
public:
typedef base::RepeatingCallback<void(bool)> UploadResultCallback;
virtual ~LoggingServiceAPI() {}
// Return the singleton instance which will get destroyed by the AtExitMgr.
// The instance must have been initialized with |Initialize| before
// being used, and |Terminate| must be called before releasing (or destroying)
// the object.
// Tests can force their own logging service implemenation with
// SetInstanceForTesting().
static LoggingServiceAPI* GetInstance();
// Sets the logging service instance for testing purposes only.
// Using |logging_service| as null resets GetInstance() to its default
// behaviour.
// Recommended usage:
// void SetUp() override {
// LoggingServiceAPI::SetInstance(&my_logging_service_);
// LoggingServiceAPI::GetInstance()->Initialize(&my_registry_logger_);
// }
// void TearDown() override {
// LoggingServiceAPI::GetInstance()->Terminate();
// LoggingServiceAPI::SetInstance(nullptr);
// }
// Note: when my_logging_service_ is a MockLoggingService, Initialize() and
// Terminate() don't need to be called.
static void SetInstanceForTesting(LoggingServiceAPI* logging_service);
// All of the following functions must be called from the main UI thread:
// Start and stop intercepting logs. The function |Terminate| disables uploads
// and flushes current content of the logging report. |registry_logger| is
// needed to make sure there are no logs upload scheduled tasks left active
// when logs upload is disabled. It can be nullptr when caller is positive
// that there are none, i.e., when initializing for the first time.
virtual void Initialize(RegistryLogger* registry_logger) = 0;
virtual void Terminate() = 0;
// Send the current state of |chrome_cleaner_report_| to the Safe Browsing API
// and clear it. |registry_logger| is specified by the caller so that it can
// be mocked for testing.
virtual void SendLogsToSafeBrowsing(const UploadResultCallback& done_callback,
RegistryLogger* registry_logger) = 0;
// Cancel all current and future waits, to speed up system shutdown.
virtual void CancelWaitForShutdown() = 0;
// Enable / disable uploads of logs. |registry_logger| is needed to make sure
// there are no logs upload scheduled tasks left active when logs upload is
// disabled. It can be nullptr when caller is positive that there are none,
// i.e., when enabling for the first time.
virtual void EnableUploads(bool enabled, RegistryLogger* registry_logger) = 0;
// Schedule a task to upload logs in case we fail to progress beyond the point
// from where this is called, which can be identified by |result_code|. These
// fall back logs use the current state of raw log lines without flushing
// them, and use |result_code| as the protobuf exit code.
virtual void ScheduleFallbackLogsUpload(RegistryLogger* registry_logger,
ResultCode result_code) = 0;
// All of the following functions can be called from any thread:
virtual bool uploads_enabled() const = 0;
// Set |detailed_system_report| to |chrome_cleaner_report_|.
virtual void SetDetailedSystemReport(bool detailed_system_report) = 0;
virtual bool detailed_system_report_enabled() const = 0;
// Add |found_uws_name| to |chrome_cleaner_report_|.
virtual void AddFoundUwS(const std::string& found_uws_name) = 0;
// Add |found_uws| to |chrome_cleaner_report_| with the detail level of the
// UwS set according to |flags|.
// Can be called from any thread.
virtual void AddDetectedUwS(const PUPData::PUP* found_uws,
UwSDetectedFlags flags) = 0;
// Adds a converted UwS proto to the list of matched UwS.
virtual void AddDetectedUwS(const UwS& uws) = 0;
// Set |exit_code| to |chrome_cleaner_report_|. Can be called from any thread.
// Must not be called except when really done.
virtual void SetExitCode(ResultCode exit_code) = 0;
// Add a loaded module to the system report.
virtual void AddLoadedModule(
const base::string16& name,
ModuleHost host,
const internal::FileInformation& file_information) = 0;
// Add a running service to the system report.
virtual void AddService(
const base::string16& display_name,
const base::string16& service_name,
const internal::FileInformation& file_information) = 0;
// Add an installed program to the system report.
virtual void AddInstalledProgram(const base::FilePath& folder_path) = 0;
// Add a running process to the system report.
virtual void AddProcess(
const base::string16& name,
const internal::FileInformation& file_information) = 0;
// Add a registry value |registry_value| which may have |file_informations|
// associated with it to the system report.
virtual void AddRegistryValue(
const internal::RegistryValue& registry_value,
const std::vector<internal::FileInformation>& file_informations) = 0;
// Add a layered service provider to the system report.
virtual void AddLayeredServiceProvider(
const std::vector<base::string16>& guids,
const internal::FileInformation& file_information) = 0;
// Set the WinInetProxy settings of the system report.
virtual void SetWinInetProxySettings(const base::string16& config,
const base::string16& bypass,
const base::string16& auto_config_url,
bool autodetect) = 0;
// Set the WinHttpProxy settings of the system report.
virtual void SetWinHttpProxySettings(const base::string16& config,
const base::string16& bypass) = 0;
// Add an installed extension to the system report.
virtual void AddInstalledExtension(const base::string16& extension_id,
ExtensionInstallMethod install_method) = 0;
// Add a scheduled task to the system report.
virtual void AddScheduledTask(
const base::string16& name,
const base::string16& description,
const std::vector<internal::FileInformation>& actions) = 0;
// Log resource usage of a Chrome Cleanup process identified by
// |process_type|.
virtual void LogProcessInformation(SandboxType process_type,
const SystemResourceUsage& usage) = 0;
// Returns whether all files detected for removable UwS were successfully
// deleted.
virtual bool AllExpectedRemovalsConfirmed() const = 0;
// Return a raw representation of the current state of the report.
virtual std::string RawReportContent() = 0;
// Read the content of |log_file| as a protocol buffer and replace current
// state with it. Return false on failures.
virtual bool ReadContentFromFile(const base::FilePath& log_file) = 0;
// If in debug mode or switch --dump-raw-logs is present, save the serialized
// report proto to |executable||tag|.pb, where |executable| is the current
// binary name.
virtual void MaybeSaveLogsToFile(const base::string16& tag);
private:
static LoggingServiceAPI* logging_service_for_testing_;
};
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_LOGGING_SERVICE_API_H_
// Copyright 2018 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 "chrome/chrome_cleaner/logging/message_builder.h"
#include <utility>
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
namespace chrome_cleaner {
MessageBuilder::MessageItem::MessageItem(base::StringPiece16 value)
: value_(value.as_string()) {}
MessageBuilder::MessageItem::MessageItem(base::StringPiece value)
: value_(base::UTF8ToUTF16(value.as_string())) {}
MessageBuilder::MessageItem::MessageItem(int value)
: value_(base::IntToString16(value)) {}
MessageBuilder::ScopedIndent::ScopedIndent(MessageBuilder* builder)
: builder_(builder) {
builder_->IncreaseIdentationLevel();
}
MessageBuilder::ScopedIndent::ScopedIndent(
MessageBuilder::ScopedIndent&& other) {
operator=(std::move(other)); // Should call the move assignment operator.
}
MessageBuilder::ScopedIndent& MessageBuilder::ScopedIndent::operator=(
MessageBuilder::ScopedIndent&& other) {
std::swap(builder_, other.builder_);
return *this;
}
MessageBuilder::ScopedIndent::~ScopedIndent() {
builder_->DecreaseIdentationLevel();
}
void MessageBuilder::IncreaseIdentationLevel() {
++indentation_level_;
if (!content_.empty() && content_.back() != L'\n')
NewLine();
}
void MessageBuilder::DecreaseIdentationLevel() {
DCHECK_GT(indentation_level_, 0);
--indentation_level_;
if (!content_.empty() && content_.back() != L'\n')
NewLine();
}
MessageBuilder& MessageBuilder::NewLine() {
content_ += L"\n";
return *this;
}
void MessageBuilder::AddInternal(std::initializer_list<MessageItem> values) {
for (auto value : values)
content_ += value.value();
}
void MessageBuilder::IndentIfNewLine() {
if (content_.empty() || content_.back() != L'\n')
return;
for (int i = 0; i < indentation_level_; ++i)
content_ += L"\t";
}
MessageBuilder& MessageBuilder::AddHeaderLine(base::StringPiece16 title) {
Add(title, L":").NewLine();
return *this;
}
MessageBuilder::ScopedIndent MessageBuilder::Indent() {
return MessageBuilder::ScopedIndent(this);
}
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_MESSAGE_BUILDER_H_
#define CHROME_CHROME_CLEANER_LOGGING_MESSAGE_BUILDER_H_
#include <string>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
namespace chrome_cleaner {
// Provides a fluent interface for building messages to be presented to the
// user with functions to add values of basic types and common line patterns.
// The class also provides an interface for automatically increasing the
// indentation level and decrease it back when the current scope ends.
//
// Usage example:
// MessageBuilder builder;
// builder.AddHeaderLine(L"Main header");
// {
// MessageBuilder::ScopedIndent scoped_indent(&builder);
// builder
// .AddFieldValueLine(L"String16 field", L"abc")
// .AddFieldValueLine(L"Int field", 10)
// .AddFieldValueLine(L"String field", "xyz");
// {
// MessageBuilder::ScopedIndent scoped_indent(&builder);
// builder.Add(L"abc ", "xyz ", 10).NewLine();
// builder.AddFieldValueLine(L"Another field", L"pqr")
// MessageBuilder::ScopedIndent scoped_indent_2(&builder);
// builder.Add(1, L" ", 2, L" ", 4).NewLine();
// }
// builder.AddFieldValueLine(L"Last field", L"xyz")
// }
//
// At the end, builder.content() will contain (| represents the start of the
// line):
// |Main header:
// |\tString16 field: abc
// |\tInt field: 10
// |\tString field: xyz
// |\t\tabc xyz 10
// |\t\tAnother field: pqr
// |\t\t\t1 2 4
// |\tLast field: xyz
//
// Note: scoped indentation can also be introduced by the following idiom:
// auto scoped_indent = builder.Indent();
class MessageBuilder {
public:
// Increases the indentation level for |builder| in the current scope:
// - on construction, this object will indentation level is increased by 1,
// so all new lines will start with an additional tab;
// - on destruction, indentation level is restored to its previous value.
// For convenience, an EOL symbol is appended to the result string whenever
// the indentation level changes and the last appended character is not EOL.
class ScopedIndent {
public:
explicit ScopedIndent(MessageBuilder* builder);
ScopedIndent(ScopedIndent&& other);
~ScopedIndent();
ScopedIndent& operator=(ScopedIndent&& other);
private:
MessageBuilder* builder_;
DISALLOW_COPY_AND_ASSIGN(ScopedIndent);
};
MessageBuilder() = default;
// Appends an EOL character to the result string.
MessageBuilder& NewLine();
// Appends a list of values to the result string.
template <typename... Values>
MessageBuilder& Add(const Values&... values) {
IndentIfNewLine();
AddInternal({MessageItem(values)...});
return *this;
}
// Appends a list of values to the result string and then appends an EOL.
// Equivalent to:
// Add(...).NewLine()
template <typename... Values>
MessageBuilder& AddLine(const Values&... values) {
Add(values...).NewLine();
return *this;
}
// Adds a new line with |title| indented with |indentation_level| tabs.
// Equivalent to:
// Add(title, ":").NewLine()
MessageBuilder& AddHeaderLine(base::StringPiece16 title);
// AddFieldValueLine adds a new line for a pair (|field_name|, |value|)
// indented with |indentation_level| tabs.
// Equivalent to:
// Add(field_name, ": ", value).NewLine()
template <typename Value>
MessageBuilder& AddFieldValueLine(base::StringPiece16 field_name,
const Value& value) {
Add(field_name, L": ", value).NewLine();
return *this;
}
MessageBuilder::ScopedIndent Indent();
base::string16 content() const { return content_; }
protected:
// Updates the current indentation level and appends a L'\n' if it's not the
// last symbol appended to the result string.
void IncreaseIdentationLevel();
void DecreaseIdentationLevel();
private:
// Internal representation of a value that can be appended to the result
// string, so that values of different types can be added to the initializer
// list in AddInternal().
class MessageItem {
public:
explicit MessageItem(base::StringPiece16 value);
explicit MessageItem(base::StringPiece value);
explicit MessageItem(int value);
const base::string16& value() const { return value_; }
private:
base::string16 value_;
};
void AddInternal(std::initializer_list<MessageItem> values);
void IndentIfNewLine();
base::string16 content_;
int indentation_level_ = 0;
DISALLOW_COPY_AND_ASSIGN(MessageBuilder);
};
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_MESSAGE_BUILDER_H_
// Copyright 2018 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 "chrome/chrome_cleaner/logging/message_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chrome_cleaner {
TEST(MessageBuilderTest, NewLine) {
MessageBuilder builder;
builder.NewLine();
EXPECT_EQ(L"\n", builder.content());
builder.NewLine().NewLine();
EXPECT_EQ(L"\n\n\n", builder.content());
}
TEST(MessageBuilderTest, Add) {
MessageBuilder builder;
builder.Add(L"abc").Add(L" ").Add("xyz").Add(" ").Add(10);
EXPECT_EQ(L"abc xyz 10", builder.content());
builder.Add(" ").Add(true).Add(" ").Add(false);
EXPECT_EQ(L"abc xyz 10 1 0", builder.content());
}
TEST(MessageBuilderTest, AddLine) {
MessageBuilder builder;
builder.AddLine(L"abc", L" ", 10).AddLine("xyz", L" ", false);
base::string16 expected = L"abc 10\nxyz 0\n";
EXPECT_EQ(expected, builder.content());
builder.AddLine(" test ", true).AddLine(false);
expected += L" test 1\n0\n";
EXPECT_EQ(expected, builder.content());
}
TEST(MessageBuilderTest, ScopedIndentation) {
MessageBuilder builder;
builder.Add(L"*", L"*").NewLine();
base::string16 expected = L"**\n";
EXPECT_EQ(expected, builder.content());
{
MessageBuilder::ScopedIndent scoped_indent(&builder);
builder.Add(L"*", L"*").AddLine(L"*");
expected += L"\t***\n";
EXPECT_EQ(expected, builder.content());
{
auto scoped_indent = builder.Indent();
builder.Add(L"*", L"*", L"*").NewLine();
expected += L"\t\t***\n";
EXPECT_EQ(expected, builder.content());
builder.AddLine(L"*", L"*");
expected += L"\t\t**\n";
EXPECT_EQ(expected, builder.content());
MessageBuilder::ScopedIndent scoped_indent_2(&builder);
builder.Add(L"*", L"*").NewLine();
expected += L"\t\t\t**\n";
EXPECT_EQ(expected, builder.content());
}
builder.Add(L"*", L"*").NewLine();
expected += L"\t**\n";
EXPECT_EQ(expected, builder.content());
}
builder.Add(L"*");
expected += L"*";
EXPECT_EQ(expected, builder.content());
{
MessageBuilder::ScopedIndent scoped_indent(&builder);
expected += L"\n"; // Added due to change in indentation level.
EXPECT_EQ(expected, builder.content());
builder.Add(L"*", L"*");
expected += L"\t**";
EXPECT_EQ(expected, builder.content());
}
expected += L"\n"; // Added due to change in indentation level.
EXPECT_EQ(expected, builder.content());
builder.AddLine(L"*", L"*");
expected += L"**\n";
EXPECT_EQ(expected, builder.content());
{
auto scoped_indent = builder.Indent();
builder.AddLine(L"*", L"*");
expected += L"\t**\n";
EXPECT_EQ(expected, builder.content());
}
builder.Add(L"*", L"*").Add(L"*", L"*", L"*").NewLine();
expected += L"*****\n";
EXPECT_EQ(expected, builder.content());
}
TEST(MessageBuilderTest, AddHeaderLine) {
MessageBuilder builder;
builder.AddHeaderLine(L"Header1").AddHeaderLine(L"Header2");
base::string16 expected = L"Header1:\nHeader2:\n";
EXPECT_EQ(expected, builder.content());
MessageBuilder::ScopedIndent scoped_indent(&builder);
builder.AddHeaderLine(L"Header3");
expected += L"\tHeader3:\n";
EXPECT_EQ(expected, builder.content());
MessageBuilder::ScopedIndent scoped_indent_2(&builder);
builder.AddHeaderLine(L"Header4").AddHeaderLine(L"Header5");
expected += L"\t\tHeader4:\n\t\tHeader5:\n";
EXPECT_EQ(expected, builder.content());
}
TEST(MessageBuilderTest, AddFieldValueLine) {
MessageBuilder builder;
builder.AddFieldValueLine(L"Field1", "abc")
.AddFieldValueLine(L"Field2", L"xyz");
base::string16 expected = L"Field1: abc\nField2: xyz\n";
EXPECT_EQ(expected, builder.content());
MessageBuilder::ScopedIndent scoped_indent(&builder);
builder.AddFieldValueLine(L"Field3", 10);
expected += L"\tField3: 10\n";
EXPECT_EQ(expected, builder.content());
MessageBuilder::ScopedIndent scoped_indent_2(&builder);
builder.AddFieldValueLine(L"Field4", true)
.AddFieldValueLine(L"Field5", false);
expected += L"\t\tField4: 1\n\t\tField5: 0\n";
EXPECT_EQ(expected, builder.content());
}
} // namespace chrome_cleaner
// Copyright 2018 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 "chrome/chrome_cleaner/logging/mock_logging_service.h"
namespace chrome_cleaner {
MockLoggingService::MockLoggingService() = default;
MockLoggingService::~MockLoggingService() = default;
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_MOCK_LOGGING_SERVICE_H_
#define CHROME_CHROME_CLEANER_LOGGING_MOCK_LOGGING_SERVICE_H_
#include <string>
#include <vector>
#include "base/strings/string16.h"
#include "base/values.h"
#include "chrome/chrome_cleaner/logging/logging_service_api.h"
#include "chrome/chrome_cleaner/logging/proto/shared_data.pb.h"
#include "chrome/chrome_cleaner/logging/utils.h"
#include "chrome/chrome_cleaner/os/disk_util_types.h"
#include "chrome/chrome_cleaner/os/registry_util.h"
#include "chrome/chrome_cleaner/pup_data/pup_data.h"
#include "components/chrome_cleaner/public/constants/result_codes.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace chrome_cleaner {
// Mock for the LoggingService API.
class MockLoggingService : public LoggingServiceAPI {
public:
MockLoggingService();
~MockLoggingService() override;
// LoggingServiceAPI
MOCK_METHOD1(Initialize, void(RegistryLogger* registry_logger));
MOCK_METHOD0(Terminate, void());
MOCK_METHOD2(SendLogsToSafeBrowsing,
void(const UploadResultCallback& done_callback,
RegistryLogger* registry_logger));
MOCK_METHOD0(CancelWaitForShutdown, void());
MOCK_METHOD2(EnableUploads,
void(bool enabled, RegistryLogger* registry_logger));
MOCK_CONST_METHOD0(uploads_enabled, bool());
MOCK_METHOD1(SetDetailedSystemReport, void(bool detailed_system_report));
MOCK_CONST_METHOD0(detailed_system_report_enabled, bool());
MOCK_METHOD1(AddFoundUwS, void(const std::string& found_uws_name));
MOCK_METHOD2(AddDetectedUwS,
void(const PUPData::PUP* found_uws, UwSDetectedFlags flags));
MOCK_METHOD1(AddDetectedUwS, void(const UwS& uws));
MOCK_METHOD1(SetExitCode, void(ResultCode exit_code));
MOCK_METHOD3(AddLoadedModule,
void(const base::string16& name,
ModuleHost host,
const internal::FileInformation& file_information));
MOCK_METHOD1(AddInstalledProgram, void(const base::FilePath& folder_path));
MOCK_METHOD3(AddService,
void(const base::string16& display_name,
const base::string16& service_name,
const internal::FileInformation& file_information));
MOCK_METHOD2(AddProcess,
void(const base::string16& name,
const internal::FileInformation& file_information));
MOCK_METHOD2(
AddRegistryValue,
void(const internal::RegistryValue& registry_value,
const std::vector<internal::FileInformation>& file_informations));
MOCK_METHOD2(AddLayeredServiceProvider,
void(const std::vector<base::string16>& guids,
const internal::FileInformation& file_information));
MOCK_METHOD4(SetWinInetProxySettings,
void(const base::string16& config,
const base::string16& bypass,
const base::string16& auto_config_url,
bool autodetect));
MOCK_METHOD2(SetWinHttpProxySettings,
void(const base::string16& config,
const base::string16& bypass));
MOCK_METHOD2(AddInstalledExtension,
void(const base::string16& extension_id,
ExtensionInstallMethod install_method));
MOCK_METHOD3(AddScheduledTask,
void(const base::string16& name,
const base::string16& description,
const std::vector<internal::FileInformation>& actions));
MOCK_METHOD2(LogProcessInformation,
void(SandboxType process_type,
const SystemResourceUsage& usage));
MOCK_CONST_METHOD0(AllExpectedRemovalsConfirmed, bool());
MOCK_METHOD0(RawReportContent, std::string());
MOCK_METHOD1(ReadContentFromFile, bool(const base::FilePath& log_file));
MOCK_METHOD2(ScheduleFallbackLogsUpload,
void(RegistryLogger* registry_logger, ResultCode result_code));
};
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_MOCK_LOGGING_SERVICE_H_
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_NETWORK_CHECKER_H_
#define CHROME_CHROME_CLEANER_LOGGING_NETWORK_CHECKER_H_
#include "base/time/time.h"
#include "url/gurl.h"
namespace chrome_cleaner {
// Base class that provides methods to test whether Safe Browsing is reachable
// or not, and to wait for it to be reachable.
class NetworkChecker {
public:
virtual ~NetworkChecker() = default;
// Returns whether Safe Browsing is currently reachable or not.
virtual bool IsSafeBrowsingReachable(const GURL& upload_url) const = 0;
// Blocks until Safe Browsing is reachable, up to |wait_time|, whichever
// happens first. Returns whether Safe Browsing is reachable or not when this
// function exits.
virtual bool WaitForSafeBrowsing(const GURL& upload_url,
const base::TimeDelta& wait_time) = 0;
// Cancels all current and future waits, to speed up system shutdown.
virtual void CancelWaitForShutdown() = 0;
};
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_NETWORK_CHECKER_H_
// Copyright 2018 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 "chrome/chrome_cleaner/logging/noop_logging_service.h"
#include <vector>
#include "base/logging.h"
#include "base/memory/singleton.h"
namespace chrome_cleaner {
NoOpLoggingService* NoOpLoggingService::GetInstance() {
return base::Singleton<NoOpLoggingService>::get();
}
NoOpLoggingService::NoOpLoggingService() {}
void NoOpLoggingService::Initialize(RegistryLogger* registry_logger) {}
void NoOpLoggingService::Terminate() {}
void NoOpLoggingService::SendLogsToSafeBrowsing(
const UploadResultCallback& done_callback,
RegistryLogger* registry_logger) {
done_callback.Run(false);
}
void NoOpLoggingService::CancelWaitForShutdown() {}
void NoOpLoggingService::EnableUploads(bool enabled,
RegistryLogger* registry_logger) {
DCHECK(!enabled);
}
bool NoOpLoggingService::uploads_enabled() const {
return false;
}
void NoOpLoggingService::SetDetailedSystemReport(
bool /*detailed_system_report*/) {}
bool NoOpLoggingService::detailed_system_report_enabled() const {
return false;
}
void NoOpLoggingService::AddFoundUwS(const std::string& /*found_uws_name*/) {}
void NoOpLoggingService::AddDetectedUwS(const PUPData::PUP* /*found_uws*/,
UwSDetectedFlags flags) {}
void NoOpLoggingService::AddDetectedUwS(const UwS& uws) {}
void NoOpLoggingService::SetExitCode(ResultCode /*exit_code*/) {}
void NoOpLoggingService::AddLoadedModule(
const base::string16& /*name*/,
ModuleHost /*host*/,
const internal::FileInformation& /*file_information*/) {}
void NoOpLoggingService::AddService(
const base::string16& /*display_name*/,
const base::string16& /*service_name*/,
const internal::FileInformation& /*file_information*/) {}
void NoOpLoggingService::AddInstalledProgram(
const base::FilePath& /*folder_path*/) {}
void NoOpLoggingService::AddProcess(
const base::string16& /*name*/,
const internal::FileInformation& /*file_information*/) {}
void NoOpLoggingService::AddRegistryValue(
const internal::RegistryValue& /*registry_value*/,
const std::vector<internal::FileInformation>& /*file_informations*/) {}
void NoOpLoggingService::AddLayeredServiceProvider(
const std::vector<base::string16>& /*guids*/,
const internal::FileInformation& /*file_information*/) {}
void NoOpLoggingService::SetWinInetProxySettings(
const base::string16& /*config*/,
const base::string16& /*bypass*/,
const base::string16& /*auto_config_url*/,
bool /*autodetect*/) {}
void NoOpLoggingService::SetWinHttpProxySettings(
const base::string16& /*config*/,
const base::string16& /*bypass*/) {}
void NoOpLoggingService::AddInstalledExtension(
const base::string16& extension_id,
ExtensionInstallMethod install_method) {}
void NoOpLoggingService::AddScheduledTask(
const base::string16& /*name*/,
const base::string16& /*description*/,
const std::vector<internal::FileInformation>& /*actions*/) {}
void NoOpLoggingService::LogProcessInformation(
SandboxType /*process_type*/,
const SystemResourceUsage& /*usage*/) {}
bool NoOpLoggingService::AllExpectedRemovalsConfirmed() const {
// This function should never be called on no-op logging service as it's used
// only in the reporter. Return |false| as the default value to indicate error
// if it ever happens.
NOTREACHED();
return false;
}
std::string NoOpLoggingService::RawReportContent() {
return std::string();
}
bool NoOpLoggingService::ReadContentFromFile(const base::FilePath& log_file) {
return true;
}
void NoOpLoggingService::ScheduleFallbackLogsUpload(
RegistryLogger* registry_logger,
ResultCode result_code) {}
} // namespace chrome_cleaner
// Copyright 2018 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 CHROME_CHROME_CLEANER_LOGGING_NOOP_LOGGING_SERVICE_H_
#define CHROME_CHROME_CLEANER_LOGGING_NOOP_LOGGING_SERVICE_H_
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/values.h"
#include "chrome/chrome_cleaner/logging/logging_service_api.h"
#include "chrome/chrome_cleaner/logging/proto/shared_data.pb.h"
#include "chrome/chrome_cleaner/pup_data/pup_data.h"
#include "components/chrome_cleaner/public/constants/result_codes.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
} // namespace base
namespace chrome_cleaner {
// Manage where the logs are sent, and expose an API for more specific logging.
class NoOpLoggingService : public LoggingServiceAPI {
public:
// Return the singleton instance which will get destroyed by the AtExitMgr.
static NoOpLoggingService* GetInstance();
// LoggingServiceAPI.
void Initialize(RegistryLogger* registry_logger) override;
void Terminate() override;
void SendLogsToSafeBrowsing(const UploadResultCallback& done_callback,
RegistryLogger* registry_logger) override;
void CancelWaitForShutdown() override;
void EnableUploads(bool enabled, RegistryLogger* registry_logger) override;
bool uploads_enabled() const override;
void SetDetailedSystemReport(bool detailed_system_report) override;
bool detailed_system_report_enabled() const override;
void AddFoundUwS(const std::string& found_uws_name) override;
void AddDetectedUwS(const PUPData::PUP* found_uws,
UwSDetectedFlags flags) override;
void AddDetectedUwS(const UwS& uws) override;
void SetExitCode(ResultCode exit_code) override;
void AddLoadedModule(
const base::string16& name,
ModuleHost host,
const internal::FileInformation& file_information) override;
void AddInstalledProgram(const base::FilePath& folder_path) override;
void AddService(const base::string16& display_name,
const base::string16& service_name,
const internal::FileInformation& file_information) override;
void AddProcess(const base::string16& name,
const internal::FileInformation& file_information) override;
void AddRegistryValue(
const internal::RegistryValue& registry_value,
const std::vector<internal::FileInformation>& file_informations) override;
void AddLayeredServiceProvider(
const std::vector<base::string16>& guids,
const internal::FileInformation& file_information) override;
void SetWinInetProxySettings(const base::string16& config,
const base::string16& bypass,
const base::string16& auto_config_url,
bool autodetect) override;
void SetWinHttpProxySettings(const base::string16& config,
const base::string16& bypass) override;
void AddInstalledExtension(const base::string16& extension_id,
ExtensionInstallMethod install_method) override;
void AddScheduledTask(
const base::string16& name,
const base::string16& description,
const std::vector<internal::FileInformation>& actions) override;
void LogProcessInformation(SandboxType process_type,
const SystemResourceUsage& usage) override;
bool AllExpectedRemovalsConfirmed() const override;
std::string RawReportContent() override;
bool ReadContentFromFile(const base::FilePath& log_file) override;
void ScheduleFallbackLogsUpload(RegistryLogger* registry_logger,
ResultCode result_code) override;
private:
friend struct base::DefaultSingletonTraits<NoOpLoggingService>;
NoOpLoggingService();
DISALLOW_COPY_AND_ASSIGN(NoOpLoggingService);
};
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_LOGGING_NOOP_LOGGING_SERVICE_H_
// Copyright 2018 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.
// Provides the logging service instance to be used by executables other than
// the reporter and cleaner.
#include "chrome/chrome_cleaner/logging/logging_definitions.h"
#include "chrome/chrome_cleaner/logging/noop_logging_service.h"
namespace chrome_cleaner {
// Returns an instance of ReporterLoggingService if logs collection is enabled,
// or NoOpLoggingService otherwise.
LoggingServiceAPI* GetLoggingServiceForCurrentBuild() {
return NoOpLoggingService::GetInstance();
}
} // namespace chrome_cleaner
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -136,6 +136,9 @@ message ChromeCleanerReport {
reserved 10;
// Deprecated AntiVirusProduct field that stopped being sent after 29.157.
reserved 11;
// Deprecated incomplete_uws_matches that stopped being sent after
// 31.164.200
reserved 15;
// Information about modules loaded into selected processes.
// Next tag: 4.
......@@ -221,10 +224,6 @@ message ChromeCleanerReport {
}
optional SystemReport system_report = 14;
// Information found by Chrome Cleaner while running custom UwS matchers
// with incomplete matching results.
repeated IncompleteUwSMatch incomplete_uws_matches = 15;
// Information about Chrome Cleaner processes and their resource usage.
repeated ProcessInformation process_information = 19;
}
......@@ -14,7 +14,7 @@ package chrome_cleaner;
message APICall {
string file_name = 1;
string function_name = 2;
int64 time_called_ticks = 3;
int64 microseconds_since_start = 3;
map<string, string> parameters = 4;
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Copyright 2018 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.
// Provides the logging service instance to be used by the reporter executable.
#include "chrome/chrome_cleaner/logging/logging_definitions.h"
#include "chrome/chrome_cleaner/logging/noop_logging_service.h"
#include "chrome/chrome_cleaner/logging/reporter_logging_service.h"
#include "chrome/chrome_cleaner/settings/settings.h"
namespace chrome_cleaner {
// Returns an instance of ReporterLoggingService if logs collection is enabled,
// or NoOpLoggingService otherwise.
LoggingServiceAPI* GetLoggingServiceForCurrentBuild() {
if (Settings::GetInstance()->logs_collection_enabled())
return ReporterLoggingService::GetInstance();
return NoOpLoggingService::GetInstance();
}
} // namespace chrome_cleaner
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -273,4 +273,6 @@ Refer to README.md for content description and update process.
<item id="webstore_installer" hash_code="18764319" type="0" content_hash_code="11030110" os_list="linux,windows" file_path="chrome/browser/extensions/webstore_installer.cc"/>
<item id="webui_content_scripts_download" hash_code="100545943" type="0" content_hash_code="119898059" os_list="linux,windows" file_path="extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.cc"/>
<item id="xmpp_signal_strategy" hash_code="88906454" type="0" content_hash_code="88958321" os_list="linux,windows" file_path="remoting/signaling/xmpp_signal_strategy.cc"/>
<item id="chrome_cleanup_report" hash_code="71102679" type="0" content_hash_code="26537237" os_list="windows" file_path="chrome/chrome_cleaner/logging/cleaner_logging_service.cc"/>
<item id="unwanted_software_report" hash_code="43759504" type="0" content_hash_code="111455033" os_list="windows" file_path="chrome/chrome_cleaner/logging/reporter_logging_service.cc"/>
</annotations>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment