Commit 4d621caa authored by Rainhard Findling's avatar Rainhard Findling Committed by Commit Bot

Safety check Chrome cleaner: write CCT completion time to prefs

* Workaround for crbug.com/1139806.
* Writes the CCT scan completion time into a Chrome pref in case
  Chrome is open when the scan completes.
* Uses this timestamp alongside the one from the registry in the
  Chrome cleaner child of safety check.

Bug: 1087263,1139806
Change-Id: Ia3fda6e87058ba76089ce22e8367f41d8e0b8512
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2484700Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Commit-Queue: Rainhard Findling <rainhard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820895}
parent 7dfe96c7
......@@ -373,6 +373,7 @@
#include "chrome/browser/win/conflicts/module_database.h"
#include "chrome/browser/win/conflicts/third_party_conflicts_manager.h"
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
#include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_controller_win.h"
#include "chrome/browser/safe_browsing/chrome_cleaner/settings_resetter_win.h"
#include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_prefs_manager.h"
#endif
......@@ -722,6 +723,7 @@ void RegisterLocalState(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(
policy::policy_prefs::kNativeWindowOcclusionEnabled, true);
component_updater::RegisterPrefsForSwReporter(registry);
safe_browsing::RegisterChromeCleanerScanCompletionTimePref(registry);
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
IncompatibleApplicationsUpdater::RegisterLocalStatePrefs(registry);
ModuleDatabase::RegisterLocalStatePrefs(registry);
......
......@@ -20,7 +20,9 @@ source_set("public") {
deps = [
"//base",
"//chrome/common:constants",
"//components/chrome_cleaner/public/constants",
"//components/prefs:prefs",
"//components/variations",
"//url",
]
......
......@@ -36,6 +36,7 @@
#include "chrome/browser/safe_browsing/chrome_cleaner/srt_client_info_win.h"
#include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "chrome/installer/util/scoped_token_privilege.h"
#include "components/chrome_cleaner/public/constants/constants.h"
#include "components/chrome_cleaner/public/proto/chrome_prompt.pb.h"
......@@ -340,12 +341,20 @@ void ChromeCleanerControllerImpl::OnReporterSequenceDone(
break;
case SwReporterInvocationResult::kNothingFound:
case SwReporterInvocationResult::kCleanupNotOffered: {
// TODO(crbug.com/1139806): The scan completion timestamp is not always
// written to the registry. As a workaround, write the completion
// timestamp also to a pref. This ensures that the timestamp is preserved
// in case Chrome is still opened when the scan completes. Remove this
// workaround once the timestamp is written to the registry in all cases.
PrefService* pref_service = g_browser_process->local_state();
if (pref_service) {
pref_service->SetTime(prefs::kChromeCleanerScanCompletionTime,
base::Time::Now());
}
idle_reason_ = IdleReason::kReporterFoundNothing;
break;
case SwReporterInvocationResult::kCleanupNotOffered:
idle_reason_ = IdleReason::kReporterFoundNothing;
break;
}
case SwReporterInvocationResult::kCleanupToBeOffered:
// A request to scan will immediately follow this message, so no state
......@@ -652,6 +661,15 @@ void ChromeCleanerControllerImpl::OnPromptUser(
idle_reason_ = IdleReason::kScanningFoundNothing;
SetStateAndNotifyObservers(State::kIdle);
RecordPromptNotShownWithReasonHistogram(NO_PROMPT_REASON_NOTHING_FOUND);
// TODO(crbug.com/1139806): The scan completion timestamp is not always
// written to the registry. As a workaround, write the completion
// timestamp also to a pref. This ensures that the timestamp is preserved
// in case Chrome is still opened when the scan completes. Remove this
// workaround once the timestamp is written to the registry in all cases.
g_browser_process->local_state()->SetTime(
prefs::kChromeCleanerScanCompletionTime, base::Time::Now());
return;
}
......
......@@ -7,6 +7,7 @@
#include <ostream>
#include "base/metrics/histogram_macros.h"
#include "chrome/common/pref_names.h"
namespace safe_browsing {
......@@ -33,4 +34,11 @@ ChromeCleanerController::ChromeCleanerController() = default;
ChromeCleanerController::~ChromeCleanerController() = default;
// static
void RegisterChromeCleanerScanCompletionTimePref(PrefRegistrySimple* registry) {
DCHECK(registry);
registry->RegisterTimePref(prefs::kChromeCleanerScanCompletionTime,
base::Time());
}
} // namespace safe_browsing
......@@ -14,6 +14,7 @@
#include "base/observer_list.h"
#include "chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_scanner_results_win.h"
#include "chrome/browser/safe_browsing/chrome_cleaner/sw_reporter_invocation_win.h"
#include "components/prefs/pref_registry_simple.h"
class Profile;
......@@ -220,6 +221,9 @@ class ChromeCleanerController {
DISALLOW_COPY_AND_ASSIGN(ChromeCleanerController);
};
// Registers the reporter scan completion time preference.
void RegisterChromeCleanerScanCompletionTimePref(PrefRegistrySimple* registry);
// These are used for debug output in tests.
std::ostream& operator<<(std::ostream& out,
ChromeCleanerController::State state);
......
......@@ -12,11 +12,13 @@
#include "base/metrics/user_metrics_action.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate_factory.h"
#include "chrome/browser/password_manager/bulk_leak_check_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/version_ui.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
......@@ -165,7 +167,16 @@ base::Time TimestampDelegate::GetSystemTime() {
#if defined(OS_WIN) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
base::Time TimestampDelegate::FetchChromeCleanerScanCompletionTimestamp() {
// Read scan completion timestamp from registry.
// TODO(crbug.com/1139806): The cleaner scan completion timestamp is not
// always written to the registry. As a workaround, it is also written to a
// pref. This ensures that the timestamp is preserved in case Chrome is still
// opened when the scan completes. Remove this workaround once the timestamp
// is written to the registry in all cases.
const base::Time end_time_from_prefs =
g_browser_process->local_state()->GetTime(
prefs::kChromeCleanerScanCompletionTime);
// Read the scan completion timestamp from the registry, if it exists there.
base::win::RegKey reporter_key;
int64_t end_time = 0;
if (reporter_key.Open(HKEY_CURRENT_USER,
......@@ -173,11 +184,27 @@ base::Time TimestampDelegate::FetchChromeCleanerScanCompletionTimestamp() {
KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS ||
reporter_key.ReadInt64(chrome_cleaner::kEndTimeValueName, &end_time) !=
ERROR_SUCCESS) {
// TODO(crbug.com/1139806): Part of the above workaround. If the registry
// does not contain the timestamp but the pref does, then return the one
// from the pref.
if (!end_time_from_prefs.is_null()) {
return end_time_from_prefs;
}
// Reading failed. Return 'null' time.
return base::Time();
}
return base::Time::FromDeltaSinceWindowsEpoch(
// TODO(crbug.com/1139806): Part of the above workaround. If the timestamp in
// prefs is null or older than the one from the registry, then return the one
// from the registry. Otherwise return the one from prefs.
base::Time end_time_from_registry = base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds(end_time));
if (end_time_from_prefs.is_null() ||
end_time_from_prefs < end_time_from_registry) {
return end_time_from_registry;
} else {
return end_time_from_prefs;
}
}
#endif
......
......@@ -73,6 +73,11 @@ const char kLastProfileResetTimestamp[] = "profile.last_reset_timestamp";
// A boolean indicating if settings should be reset for this profile once a
// run of the Chrome Cleanup Tool has completed.
const char kChromeCleanerResetPending[] = "chrome_cleaner.reset_pending";
// The last time the Chrome cleaner scan completed without finding anything,
// while Chrome was opened.
const char kChromeCleanerScanCompletionTime[] =
"chrome_cleaner.scan_completion_time";
#endif
// The URL to open the new tab page to. Only set by Group Policy.
......
......@@ -36,6 +36,7 @@ extern const char kProfileCreationTime[];
#if defined(OS_WIN)
extern const char kLastProfileResetTimestamp[];
extern const char kChromeCleanerResetPending[];
extern const char kChromeCleanerScanCompletionTime[];
#endif
extern const char kNewTabPageLocationOverride[];
extern const char kProfileIconVersion[];
......
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