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

Side by Side 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 nits 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 unified diff | Download patch
OLDNEW
(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/metrics/histogram_macros.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/win/registry.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/pref_names.h"
13
14 // The registry path where the TriggeredReset values get set. Note that this
grt (UTC plus 2) 2015/09/14 14:35:34 wrap these constants in the unnamed namespace
robertshield 2015/09/21 04:16:23 Done.
15 // uses the same path for both SxS (Canary) and non-SxS Chrome.
16 const wchar_t kTriggeredResetRegistryPath[] =
17 L"Software\\" PRODUCT_STRING_PATH L"\\TriggeredReset";
18
19 const wchar_t kTriggeredResetToolName[] = L"ToolName";
20 const wchar_t kTriggeredResetTimestamp[] = L"Timestamp";
21
22 void TriggeredProfileResetter::Activate() {
engedy 2015/09/14 23:28:56 I'm sad that this code is not tested at all. Could
robertshield 2015/09/21 04:16:23 Done.
23 #if DCHECK_IS_ON()
24 activate_called_ = true;
25 #endif
26
27 // System profiles don't contain user settings.
28 if (!profile_ || profile_->IsSystemProfile())
engedy 2015/09/14 23:28:56 I am not sure about the default behavior of BCKS c
robertshield 2015/09/21 04:16:23 Yep, incognito mode does work correctly.
engedy 2015/09/21 12:56:10 Acknowledged.
29 return;
30
31 base::win::RegKey reset_reg_key(HKEY_CURRENT_USER,
32 kTriggeredResetRegistryPath,
33 KEY_QUERY_VALUE | KEY_SET_VALUE);
engedy 2015/09/14 16:08:29 nit: I think KEY_SET_VALUE is not needed.
robertshield 2015/09/21 04:16:23 Done.
34 if (!reset_reg_key.Valid())
35 return;
36
37 int64 timestamp = 0;
38 if (reset_reg_key.ReadInt64(kTriggeredResetTimestamp, &timestamp) !=
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) {
engedy 2015/09/14 16:08:29 Trying to think of any edge cases here. Any reason
robertshield 2015/09/21 04:16:23 I didn't do that since the machine clock could wel
engedy 2015/09/21 12:56:10 Fair enough, I just wanted to make sure this has b
robertshield 2015/09/21 22:04:30 Thanks!
55 DVLOG(1) << "Profile reset detected.";
56
57 has_reset_trigger_ = true;
58 UMA_HISTOGRAM_BOOLEAN("Profile.TriggeredReset", true);
engedy 2015/09/14 16:08:29 I think it could be more useful to record a histog
Alexei Svitkine (slow) 2015/09/14 17:05:43 Agree.
robertshield 2015/09/21 04:16:23 Ok, figured we'd have this reference value implici
robertshield 2015/09/21 04:16:23 Acknowledged.
59
60 if (reset_reg_key.ReadValue(kTriggeredResetToolName, &tool_name_) !=
61 ERROR_SUCCESS) {
62 DVLOG(1) << "Failed to read triggered profile reset tool name.";
engedy 2015/09/14 16:08:29 I know this is a edge case, but wouldn't it be bet
robertshield 2015/09/21 04:16:23 I had planned to have a default placeholder of "A
engedy 2015/09/21 12:56:10 Sounds good to me.
robertshield 2015/09/21 22:04:30 Acknowledged.
63 } else if (tool_name_.length() > kMaxToolNameLength) {
64 tool_name_.resize(kMaxToolNameLength);
65 }
66
67 pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp);
68 }
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698