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

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: msw feedback Created 5 years, 2 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 <stdint.h>
8
9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/win/registry.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/pref_names.h"
16
17 // The registry path where the TriggeredReset values get set. Note that this
18 // uses the same path for both SxS (Canary) and non-SxS Chrome.
19 const wchar_t kTriggeredResetRegistryPath[] =
20 L"Software\\" PRODUCT_STRING_PATH L"\\TriggeredReset";
21
22 const wchar_t kTriggeredResetToolName[] = L"ToolName";
23 const wchar_t kTriggeredResetTimestamp[] = L"Timestamp";
24
25 namespace {
26
27 const char kTriggeredResetFieldTrialName[] = "TriggeredResetFieldTrial";
28 const char kTriggeredResetOnGroup[] = "On";
29
30 bool IsInTriggeredResetFieldTrial() {
31 return base::FieldTrialList::FindFullName(kTriggeredResetFieldTrialName) ==
32 kTriggeredResetOnGroup;
33 }
34
35 } // namespace
36
37 void TriggeredProfileResetter::Activate() {
38 activate_called_ = true;
39
40 // System profiles don't contain user settings and bail out if we're not in
41 // the field trial.
42 if (!profile_ || profile_->IsSystemProfile() ||
43 !IsInTriggeredResetFieldTrial()) {
44 UMA_HISTOGRAM_BOOLEAN("Profile.TriggeredReset", false);
45 return;
46 }
47
48 int64_t timestamp = 0;
49 base::win::RegKey reset_reg_key(HKEY_CURRENT_USER,
50 kTriggeredResetRegistryPath, KEY_QUERY_VALUE);
51
52 if (!reset_reg_key.Valid() ||
53 reset_reg_key.ReadInt64(kTriggeredResetTimestamp, &timestamp) !=
54 ERROR_SUCCESS) {
55 UMA_HISTOGRAM_BOOLEAN("Profile.TriggeredReset", false);
56 return;
57 }
58
59 // A reset trigger time was found. Compare it to the trigger time stored
60 // in this profile. If different, reset the profile and persist the new
61 // time.
62 PrefService* pref_service = profile_->GetPrefs();
63 const int64 preference_timestamp =
64 pref_service->GetInt64(prefs::kLastProfileResetTimestamp);
65
66 if (profile_->IsNewProfile()) {
67 // New profiles should never be reset. Instead, persist the time stamp
68 // directly.
69 pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp);
70 } else if (timestamp != preference_timestamp) {
71 DVLOG(1) << "Profile reset detected.";
72
73 has_reset_trigger_ = true;
74
75 if (reset_reg_key.ReadValue(kTriggeredResetToolName, &tool_name_) !=
76 ERROR_SUCCESS) {
77 DVLOG(1) << "Failed to read triggered profile reset tool name.";
78 } else if (tool_name_.length() > kMaxToolNameLength) {
79 tool_name_.resize(kMaxToolNameLength);
80 }
81
82 pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp);
83 }
84
85 UMA_HISTOGRAM_BOOLEAN("Profile.TriggeredReset", has_reset_trigger_);
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698