Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/safe_browsing/chrome_cleaner/settings_resetter_win.h" | 5 #include "chrome/browser/safe_browsing/chrome_cleaner/settings_resetter_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/barrier_closure.h" | 13 #include "base/barrier_closure.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/callback_helpers.h" | 15 #include "base/callback_helpers.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/metrics/histogram_macros.h" | |
| 18 #include "base/sequence_checker.h" | 19 #include "base/sequence_checker.h" |
| 19 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 20 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/profile_resetter/profile_resetter.h" | 23 #include "chrome/browser/profile_resetter/profile_resetter.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" | 26 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" |
| 26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 29 #include "components/chrome_cleaner/public/constants/constants.h" | 30 #include "components/chrome_cleaner/public/constants/constants.h" |
| 30 #include "components/pref_registry/pref_registry_syncable.h" | 31 #include "components/pref_registry/pref_registry_syncable.h" |
| 31 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 33 | 34 |
| 34 namespace safe_browsing { | 35 namespace safe_browsing { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 39 enum TaggedProfileForResetting { | |
|
csharp
2017/07/07 20:53:33
nit: Add a comment about matching uma
ftirelo
2017/07/07 21:22:08
Done.
| |
| 40 TAGGED_PROFILE_FOR_RESETTING_TAGGED = 0, | |
| 41 | |
| 42 TAGGED_PROFILE_FOR_RESETTING_MAX, | |
| 43 }; | |
| 44 | |
| 38 // Returns the post-cleanup reset pending prefs for |profile|. | 45 // Returns the post-cleanup reset pending prefs for |profile|. |
| 39 bool ResetPending(Profile* profile) { | 46 bool ResetPending(Profile* profile) { |
| 40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 41 DCHECK(PostCleanupSettingsResetter::IsEnabled()); | 48 DCHECK(PostCleanupSettingsResetter::IsEnabled()); |
| 42 DCHECK(profile); | 49 DCHECK(profile); |
| 43 | 50 |
| 44 PrefService* prefs = profile->GetPrefs(); | 51 PrefService* prefs = profile->GetPrefs(); |
| 45 return prefs->GetBoolean(prefs::kChromeCleanerResetPending); | 52 return prefs->GetBoolean(prefs::kChromeCleanerResetPending); |
| 46 } | 53 } |
| 47 | 54 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 PostCleanupSettingsResetter::Delegate::GetProfileResetter(Profile* profile) { | 220 PostCleanupSettingsResetter::Delegate::GetProfileResetter(Profile* profile) { |
| 214 return base::MakeUnique<ProfileResetter>(profile); | 221 return base::MakeUnique<ProfileResetter>(profile); |
| 215 } | 222 } |
| 216 | 223 |
| 217 void PostCleanupSettingsResetter::TagForResetting(Profile* profile) { | 224 void PostCleanupSettingsResetter::TagForResetting(Profile* profile) { |
| 218 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 225 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 219 DCHECK(IsEnabled()); | 226 DCHECK(IsEnabled()); |
| 220 DCHECK(profile); | 227 DCHECK(profile); |
| 221 | 228 |
| 222 RecordResetPending(true, profile); | 229 RecordResetPending(true, profile); |
| 230 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.TaggedProfileForResetting", | |
| 231 TAGGED_PROFILE_FOR_RESETTING_TAGGED, | |
| 232 TAGGED_PROFILE_FOR_RESETTING_MAX); | |
| 223 } | 233 } |
| 224 | 234 |
| 225 void PostCleanupSettingsResetter::ResetTaggedProfiles( | 235 void PostCleanupSettingsResetter::ResetTaggedProfiles( |
| 226 std::vector<Profile*> profiles, | 236 std::vector<Profile*> profiles, |
| 227 base::OnceClosure done_callback, | 237 base::OnceClosure done_callback, |
| 228 std::unique_ptr<PostCleanupSettingsResetter::Delegate> delegate) { | 238 std::unique_ptr<PostCleanupSettingsResetter::Delegate> delegate) { |
| 229 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 230 DCHECK(IsEnabled()); | 240 DCHECK(IsEnabled()); |
| 231 DCHECK(delegate); | 241 DCHECK(delegate); |
| 232 | 242 |
| 233 std::vector<Profile*> profiles_to_reset; | 243 std::vector<Profile*> profiles_to_reset; |
| 234 if (!CopyProfilesToReset(profiles, &profiles_to_reset) || | 244 if (!CopyProfilesToReset(profiles, &profiles_to_reset) || |
| 235 !CleanupCompletedFromRegistry()) { | 245 !CleanupCompletedFromRegistry()) { |
| 236 std::move(done_callback).Run(); | 246 std::move(done_callback).Run(); |
| 237 return; | 247 return; |
| 238 } | 248 } |
| 239 | 249 |
| 250 UMA_HISTOGRAM_EXACT_LINEAR("SoftwareReporter.PostCleanupSettingsReset", | |
| 251 profiles_to_reset.size(), 10); | |
| 252 | |
| 240 // The SettingsResetter object will self-delete once |done_callback| is | 253 // The SettingsResetter object will self-delete once |done_callback| is |
| 241 // invoked. | 254 // invoked. |
| 242 make_scoped_refptr(new SettingsResetter(std::move(profiles_to_reset), | 255 make_scoped_refptr(new SettingsResetter(std::move(profiles_to_reset), |
| 243 std::move(delegate), | 256 std::move(delegate), |
| 244 std::move(done_callback))) | 257 std::move(done_callback))) |
| 245 ->Run(); | 258 ->Run(); |
| 246 } | 259 } |
| 247 | 260 |
| 248 // static | 261 // static |
| 249 void PostCleanupSettingsResetter::RegisterProfilePrefs( | 262 void PostCleanupSettingsResetter::RegisterProfilePrefs( |
| 250 user_prefs::PrefRegistrySyncable* registry) { | 263 user_prefs::PrefRegistrySyncable* registry) { |
| 251 DCHECK(registry); | 264 DCHECK(registry); |
| 252 registry->RegisterBooleanPref(prefs::kChromeCleanerResetPending, false); | 265 registry->RegisterBooleanPref(prefs::kChromeCleanerResetPending, false); |
| 253 } | 266 } |
| 254 | 267 |
| 255 } // namespace safe_browsing | 268 } // namespace safe_browsing |
| OLD | NEW |