Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7516)

Unified Diff: chrome/browser/profile_resetter/triggered_profile_resetter_win.cc

Issue 1294923003: Add a triggered profile reset mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Grt feedback Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profile_resetter/triggered_profile_resetter_win.cc
diff --git a/chrome/browser/profile_resetter/triggered_profile_resetter_win.cc b/chrome/browser/profile_resetter/triggered_profile_resetter_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..95b64586456fbc95603ce1b45bf90e7f861e914d
--- /dev/null
+++ b/chrome/browser/profile_resetter/triggered_profile_resetter_win.cc
@@ -0,0 +1,67 @@
+// Copyright 2015 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/browser/profile_resetter/triggered_profile_resetter.h"
+
+#include "base/prefs/pref_service.h"
+#include "base/win/registry.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/pref_names.h"
+
+using base::win::RegKey;
grt (UTC plus 2) 2015/09/05 12:44:14 is this worth it for only one location? if you pre
robertshield 2015/09/13 06:04:02 Done.
+
+// The registry path where the TriggeredReset values get set. Note that this
+// uses the same path for both SxS (Canary) and non-SxS Chrome.
+const wchar_t kTriggeredResetRegistryPath[] =
+ L"Software\\" PRODUCT_STRING_PATH L"\\TriggeredReset";
+
+const wchar_t kTriggeredResetToolName[] = L"ToolName";
+const wchar_t kTriggeredResetTimestamp[] = L"Timestamp";
+
+void TriggeredProfileResetter::Activate() {
+#if DCHECK_IS_ON()
+ activate_called_ = true;
+#endif
+
+ // System profiles don't contain user settings.
+ if (!profile_ || profile_->IsSystemProfile())
+ return;
+
+ RegKey reset_reg_key(HKEY_CURRENT_USER, kTriggeredResetRegistryPath,
+ KEY_QUERY_VALUE | KEY_SET_VALUE);
+ if (!reset_reg_key.Valid())
+ return;
+
+ int64 timestamp = 0;
+ if (reset_reg_key.ReadInt64(kTriggeredResetTimestamp, &timestamp) !=
+ ERROR_SUCCESS) {
+ return;
+ }
+
+ // A reset trigger time was found. Compare it to the trigger time stored
+ // in this profile. If different, reset the profile and persist the new
+ // time.
+ PrefService* pref_service = profile_->GetPrefs();
+ const int64 preference_timestamp =
+ pref_service->GetInt64(prefs::kLastProfileResetTimestamp);
+
+ if (profile_->IsNewProfile()) {
+ // New profiles should never be reset. Instead, persist the time stamp
+ // directly.
+ pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp);
+ } else if (timestamp != preference_timestamp) {
+ DVLOG(1) << "Profile reset detected.";
+ has_reset_trigger_ = true;
+
+ if (reset_reg_key.ReadValue(kTriggeredResetToolName, &tool_name_) !=
+ ERROR_SUCCESS) {
+ DVLOG(1) << "Failed to read triggered profile reset tool name.";
+ } else if (tool_name_.length() > kMaxToolNameLength) {
+ tool_name_.resize(kMaxToolNameLength);
+ }
+
+ pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698