Chromium Code Reviews| 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..b1c6e0b30f4340f2675e4df709094a9f1ae9b260 |
| --- /dev/null |
| +++ b/chrome/browser/profile_resetter/triggered_profile_resetter_win.cc |
| @@ -0,0 +1,59 @@ |
| +// 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; |
| + |
| +const wchar_t kTriggeredResetRegistryPath[] = |
|
grt (UTC plus 2)
2015/09/04 18:35:48
please add a comment explaining that this location
robertshield
2015/09/04 20:27:18
Done.
|
| + L"Software\\" PRODUCT_STRING_PATH L"\\TriggeredReset"; |
| +const wchar_t kTriggeredResetToolName[] = L"ToolName"; |
| +const wchar_t kTriggeredResetTimestamp[] = L"Timestamp"; |
| + |
| +void TriggeredProfileResetter::Activate() { |
| + activate_called_ = true; |
|
grt (UTC plus 2)
2015/09/04 18:35:48
#if DCHECK_IS_ON() around this?
robertshield
2015/09/04 20:27:18
Done.
|
| + |
| + // 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()) { |
|
grt (UTC plus 2)
2015/09/04 18:35:48
nit: reduce indentation with
if (!Valid())
r
robertshield
2015/09/04 20:27:18
Done.
|
| + int64 timestamp = 0; |
| + if (reset_reg_key.ReadInt64(kTriggeredResetTimestamp, ×tamp) == |
|
grt (UTC plus 2)
2015/09/04 18:35:48
similar nit to early-exit and reduce indentation
robertshield
2015/09/04 20:27:18
Must be channeling my secret inner lisp programmer
|
| + ERROR_SUCCESS) { |
| + // 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) { |
| + VLOG(1) << "Profile reset detected."; |
|
grt (UTC plus 2)
2015/09/04 18:35:48
DVLOG or remove
robertshield
2015/09/04 20:27:18
Done.
|
| + has_reset_trigger_ = true; |
| + |
| + if (reset_reg_key.ReadValue(kTriggeredResetToolName, &tool_name_) != |
| + ERROR_SUCCESS) { |
| + VLOG(1) << "Failed to read triggered profile reset tool name."; |
| + } |
|
grt (UTC plus 2)
2015/09/04 18:35:48
} else if (tool_name_.length() > kMaxToolNameLengt
robertshield
2015/09/04 20:27:18
Done.
|
| + if (tool_name_.length() > kMaxToolNameLength) |
| + tool_name_.resize(kMaxToolNameLength); |
| + |
| + pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp); |
| + } |
| + } |
| + } |
| +} |