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

Side by Side Diff: chrome/browser/safe_browsing/chrome_cleaner/settings_resetter_win.cc

Issue 2952883002: Chrome Cleaner: Fix issue where a tagged profile could be reset multiple times (Closed)
Patch Set: Add sequence DCHECKs. Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/sequence_checker.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "base/win/registry.h" 20 #include "base/win/registry.h"
20 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/profile_resetter/profile_resetter.h" 22 #include "chrome/browser/profile_resetter/profile_resetter.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h" 25 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_field_trial_win.h"
25 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_finder.h" 27 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 Profile* profile, 90 Profile* profile,
90 std::unique_ptr<BrandcodedDefaultSettings> master_settings); 91 std::unique_ptr<BrandcodedDefaultSettings> master_settings);
91 92
92 // Removes the settings reset tag for |profile|. If there are no more 93 // Removes the settings reset tag for |profile|. If there are no more
93 // profiles to reset, invokes |done_callback_| and deletes this object. 94 // profiles to reset, invokes |done_callback_| and deletes this object.
94 void OnResetCompleted(Profile* profile); 95 void OnResetCompleted(Profile* profile);
95 96
96 // The profiles to be reset. 97 // The profiles to be reset.
97 std::vector<Profile*> profiles_to_reset_; 98 std::vector<Profile*> profiles_to_reset_;
98 99
100 // The ProfileResetter objects that are used to reset each profile. We need to
101 // hold on to these until each reset operation has been completed.
102 std::vector<std::unique_ptr<ProfileResetter>> profile_resetters_;
103
104 // Used to check that modifications to |profile_resetters_| are sequenced
105 // correctly.
106 SEQUENCE_CHECKER(sequence_checker_);
107
99 // The number of profiles that need to be reset. 108 // The number of profiles that need to be reset.
100 int num_pending_resets_; 109 int num_pending_resets_;
101 110
102 // The callback to be invoked once settings reset completes. 111 // The callback to be invoked once settings reset completes.
103 base::OnceClosure done_callback_; 112 base::OnceClosure done_callback_;
104 113
105 std::unique_ptr<PostCleanupSettingsResetter::Delegate> delegate_; 114 std::unique_ptr<PostCleanupSettingsResetter::Delegate> delegate_;
106 115
107 DISALLOW_COPY_AND_ASSIGN(SettingsResetter); 116 DISALLOW_COPY_AND_ASSIGN(SettingsResetter);
108 }; 117 };
109 118
110 SettingsResetter::SettingsResetter( 119 SettingsResetter::SettingsResetter(
111 std::vector<Profile*> profiles_to_reset, 120 std::vector<Profile*> profiles_to_reset,
112 std::unique_ptr<PostCleanupSettingsResetter::Delegate> delegate, 121 std::unique_ptr<PostCleanupSettingsResetter::Delegate> delegate,
113 base::OnceClosure done_callback) 122 base::OnceClosure done_callback)
114 : profiles_to_reset_(std::move(profiles_to_reset)), 123 : profiles_to_reset_(std::move(profiles_to_reset)),
115 num_pending_resets_(profiles_to_reset_.size()), 124 num_pending_resets_(profiles_to_reset_.size()),
116 done_callback_(std::move(done_callback)), 125 done_callback_(std::move(done_callback)),
117 delegate_(std::move(delegate)) { 126 delegate_(std::move(delegate)) {
118 DCHECK_LT(0, num_pending_resets_); 127 DCHECK_LT(0, num_pending_resets_);
119 DCHECK(done_callback_); 128 DCHECK(done_callback_);
120 DCHECK(delegate_); 129 DCHECK(delegate_);
130
131 DETACH_FROM_SEQUENCE(sequence_checker_);
121 } 132 }
122 133
123 SettingsResetter::~SettingsResetter() { 134 SettingsResetter::~SettingsResetter() {
124 DCHECK(!done_callback_); 135 DCHECK(!done_callback_);
125 DCHECK(!num_pending_resets_); 136 DCHECK(!num_pending_resets_);
126 } 137 }
127 138
128 void SettingsResetter::Run() { 139 void SettingsResetter::Run() {
129 for (Profile* profile : profiles_to_reset_) { 140 for (Profile* profile : profiles_to_reset_) {
130 delegate_->FetchDefaultSettings( 141 delegate_->FetchDefaultSettings(
131 base::Bind(&SettingsResetter::OnFetchCompleted, this, profile)); 142 base::Bind(&SettingsResetter::OnFetchCompleted, this, profile));
132 } 143 }
133 } 144 }
134 145
135 void SettingsResetter::OnFetchCompleted( 146 void SettingsResetter::OnFetchCompleted(
136 Profile* profile, 147 Profile* profile,
137 std::unique_ptr<BrandcodedDefaultSettings> master_settings) { 148 std::unique_ptr<BrandcodedDefaultSettings> master_settings) {
149 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
150
138 static const ProfileResetter::ResettableFlags kSettingsToReset = 151 static const ProfileResetter::ResettableFlags kSettingsToReset =
139 ProfileResetter::DEFAULT_SEARCH_ENGINE | ProfileResetter::HOMEPAGE | 152 ProfileResetter::DEFAULT_SEARCH_ENGINE | ProfileResetter::HOMEPAGE |
140 ProfileResetter::EXTENSIONS | ProfileResetter::STARTUP_PAGES | 153 ProfileResetter::EXTENSIONS | ProfileResetter::STARTUP_PAGES |
141 ProfileResetter::SHORTCUTS; 154 ProfileResetter::SHORTCUTS;
142 155
143 delegate_->GetProfileResetter(profile)->Reset( 156 profile_resetters_.push_back(delegate_->GetProfileResetter(profile));
157 profile_resetters_.back()->Reset(
144 kSettingsToReset, std::move(master_settings), 158 kSettingsToReset, std::move(master_settings),
145 base::Bind(&SettingsResetter::OnResetCompleted, this, profile)); 159 base::Bind(&SettingsResetter::OnResetCompleted, this, profile));
146 } 160 }
147 161
148 void SettingsResetter::OnResetCompleted(Profile* profile) { 162 void SettingsResetter::OnResetCompleted(Profile* profile) {
149 DCHECK_LT(0, num_pending_resets_); 163 DCHECK_LT(0, num_pending_resets_);
150 164
151 RecordResetPending(false, profile); 165 RecordResetPending(false, profile);
152 166
153 --num_pending_resets_; 167 --num_pending_resets_;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 246 }
233 247
234 // static 248 // static
235 void PostCleanupSettingsResetter::RegisterProfilePrefs( 249 void PostCleanupSettingsResetter::RegisterProfilePrefs(
236 user_prefs::PrefRegistrySyncable* registry) { 250 user_prefs::PrefRegistrySyncable* registry) {
237 DCHECK(registry); 251 DCHECK(registry);
238 registry->RegisterBooleanPref(prefs::kChromeCleanerResetPending, false); 252 registry->RegisterBooleanPref(prefs::kChromeCleanerResetPending, false);
239 } 253 }
240 254
241 } // namespace safe_browsing 255 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698