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; | |
|
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.
| |
| 14 | |
| 15 // The registry path where the TriggeredReset values get set. Note that this | |
| 16 // uses the same path for both SxS (Canary) and non-SxS Chrome. | |
| 17 const wchar_t kTriggeredResetRegistryPath[] = | |
| 18 L"Software\\" PRODUCT_STRING_PATH L"\\TriggeredReset"; | |
| 19 | |
| 20 const wchar_t kTriggeredResetToolName[] = L"ToolName"; | |
| 21 const wchar_t kTriggeredResetTimestamp[] = L"Timestamp"; | |
| 22 | |
| 23 void TriggeredProfileResetter::Activate() { | |
| 24 #if DCHECK_IS_ON() | |
| 25 activate_called_ = true; | |
| 26 #endif | |
| 27 | |
| 28 // System profiles don't contain user settings. | |
| 29 if (!profile_ || profile_->IsSystemProfile()) | |
| 30 return; | |
| 31 | |
| 32 RegKey reset_reg_key(HKEY_CURRENT_USER, kTriggeredResetRegistryPath, | |
| 33 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
| 34 if (!reset_reg_key.Valid()) | |
| 35 return; | |
| 36 | |
| 37 int64 timestamp = 0; | |
| 38 if (reset_reg_key.ReadInt64(kTriggeredResetTimestamp, ×tamp) != | |
| 39 ERROR_SUCCESS) { | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 // A reset trigger time was found. Compare it to the trigger time stored | |
| 44 // in this profile. If different, reset the profile and persist the new | |
| 45 // time. | |
| 46 PrefService* pref_service = profile_->GetPrefs(); | |
| 47 const int64 preference_timestamp = | |
| 48 pref_service->GetInt64(prefs::kLastProfileResetTimestamp); | |
| 49 | |
| 50 if (profile_->IsNewProfile()) { | |
| 51 // New profiles should never be reset. Instead, persist the time stamp | |
| 52 // directly. | |
| 53 pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp); | |
| 54 } else if (timestamp != preference_timestamp) { | |
| 55 DVLOG(1) << "Profile reset detected."; | |
| 56 has_reset_trigger_ = true; | |
| 57 | |
| 58 if (reset_reg_key.ReadValue(kTriggeredResetToolName, &tool_name_) != | |
| 59 ERROR_SUCCESS) { | |
| 60 DVLOG(1) << "Failed to read triggered profile reset tool name."; | |
| 61 } else if (tool_name_.length() > kMaxToolNameLength) { | |
| 62 tool_name_.resize(kMaxToolNameLength); | |
| 63 } | |
| 64 | |
| 65 pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp); | |
| 66 } | |
| 67 } | |
| OLD | NEW |