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

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: Handle background case by clearing flag in startup browser creator. 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
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() {
23 activate_called_ = true;
24
25 // System profiles don't contain user settings.
26 if (!profile_ || profile_->IsSystemProfile()) {
27 UMA_HISTOGRAM_BOOLEAN("Profile.TriggeredReset", false);
28 return;
29 }
30
31 int64 timestamp = 0;
32 base::win::RegKey reset_reg_key(HKEY_CURRENT_USER,
33 kTriggeredResetRegistryPath, KEY_QUERY_VALUE);
34
35 if (!reset_reg_key.Valid() ||
36 reset_reg_key.ReadInt64(kTriggeredResetTimestamp, &timestamp) !=
37 ERROR_SUCCESS) {
38 UMA_HISTOGRAM_BOOLEAN("Profile.TriggeredReset", false);
39 return;
40 }
41
42 // A reset trigger time was found. Compare it to the trigger time stored
43 // in this profile. If different, reset the profile and persist the new
44 // time.
45 PrefService* pref_service = profile_->GetPrefs();
46 const int64 preference_timestamp =
47 pref_service->GetInt64(prefs::kLastProfileResetTimestamp);
48
49 if (profile_->IsNewProfile()) {
50 // New profiles should never be reset. Instead, persist the time stamp
51 // directly.
52 pref_service->SetInt64(prefs::kLastProfileResetTimestamp, timestamp);
53 } else if (timestamp != preference_timestamp) {
54 DVLOG(1) << "Profile reset detected.";
55
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
68 UMA_HISTOGRAM_BOOLEAN("Profile.TriggeredReset", has_reset_trigger_);
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698