Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | |
| 6 | |
| 7 #include "base/prefs/pref_service.h" | |
| 8 #include "base/win/registry.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/common/chrome_constants.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 | |
| 13 using base::win::RegKey; | |
| 14 | |
| 15 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.
| |
| 16 L"Software\\" PRODUCT_STRING_PATH L"\\TriggeredReset"; | |
| 17 const wchar_t kTriggeredResetToolName[] = L"ToolName"; | |
| 18 const wchar_t kTriggeredResetTimestamp[] = L"Timestamp"; | |
| 19 | |
| 20 void TriggeredProfileResetter::Activate() { | |
| 21 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.
| |
| 22 | |
| 23 // System profiles don't contain user settings. | |
| 24 if (!profile_ || profile_->IsSystemProfile()) | |
| 25 return; | |
| 26 | |
| 27 RegKey reset_reg_key(HKEY_CURRENT_USER, kTriggeredResetRegistryPath, | |
| 28 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
| 29 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.
| |
| 30 int64 timestamp = 0; | |
| 31 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
| |
| 32 ERROR_SUCCESS) { | |
| 33 // A reset trigger time was found. Compare it to the trigger time stored | |
| 34 // in this profile. If different, reset the profile and persist the new | |
| 35 // time. | |
| 36 PrefService* pref_service = profile_->GetPrefs(); | |
| 37 const int64 preference_timestamp = | |
| 38 pref_service->GetInt64(prefs::kLastProfileResetTimestamp); | |
| 39 | |
| 40 if (profile_->IsNewProfile()) { | |
| 41 // New profiles should never be reset. Instead, persist the time stamp | |
| 42 // directly. | |
| 43 pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp); | |
| 44 } else if (timestamp != preference_timestamp) { | |
| 45 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.
| |
| 46 has_reset_trigger_ = true; | |
| 47 | |
| 48 if (reset_reg_key.ReadValue(kTriggeredResetToolName, &tool_name_) != | |
| 49 ERROR_SUCCESS) { | |
| 50 VLOG(1) << "Failed to read triggered profile reset tool name."; | |
| 51 } | |
|
grt (UTC plus 2)
2015/09/04 18:35:48
} else if (tool_name_.length() > kMaxToolNameLengt
robertshield
2015/09/04 20:27:18
Done.
| |
| 52 if (tool_name_.length() > kMaxToolNameLength) | |
| 53 tool_name_.resize(kMaxToolNameLength); | |
| 54 | |
| 55 pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp); | |
| 56 } | |
| 57 } | |
| 58 } | |
| 59 } | |
| OLD | NEW |