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

Side by Side Diff: chrome/browser/extensions/external_registry_loader_win.cc

Issue 2796783002: [Ext Registry] Do not try to re-watch registry if we are already watching it. (Closed)
Patch Set: revert retrying + add assert Created 3 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/external_registry_loader_win.h" 5 #include "chrome/browser/extensions/external_registry_loader_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_file.h" 10 #include "base/files/scoped_file.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 std::string MakePrefName(const std::string& extension_id, 48 std::string MakePrefName(const std::string& extension_id,
49 const std::string& pref_name) { 49 const std::string& pref_name) {
50 return base::StringPrintf("%s.%s", extension_id.c_str(), pref_name.c_str()); 50 return base::StringPrintf("%s.%s", extension_id.c_str(), pref_name.c_str());
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 namespace extensions { 55 namespace extensions {
56 56
57 ExternalRegistryLoader::ExternalRegistryLoader()
58 : attempted_watching_registry_(false) {}
59
57 void ExternalRegistryLoader::StartLoading() { 60 void ExternalRegistryLoader::StartLoading() {
58 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 61 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 BrowserThread::PostTask( 62 BrowserThread::PostTask(
60 BrowserThread::FILE, FROM_HERE, 63 BrowserThread::FILE, FROM_HERE,
61 base::Bind(&ExternalRegistryLoader::LoadOnFileThread, this)); 64 base::Bind(&ExternalRegistryLoader::LoadOnFileThread, this));
62 } 65 }
63 66
64 std::unique_ptr<base::DictionaryValue> 67 std::unique_ptr<base::DictionaryValue>
65 ExternalRegistryLoader::LoadPrefsOnFileThread() { 68 ExternalRegistryLoader::LoadPrefsOnFileThread() {
66 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 69 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 BrowserThread::PostTask( 196 BrowserThread::PostTask(
194 BrowserThread::UI, FROM_HERE, 197 BrowserThread::UI, FROM_HERE,
195 base::Bind(&ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry, 198 base::Bind(&ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry,
196 this)); 199 this));
197 } 200 }
198 201
199 void ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry() { 202 void ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry() {
200 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 203 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
201 LoadFinished(); 204 LoadFinished();
202 205
203 // Start watching registry. 206 // Attempt to watch registry if we haven't already.
207 if (attempted_watching_registry_)
208 return;
209
204 LONG result = ERROR_SUCCESS; 210 LONG result = ERROR_SUCCESS;
205 if ((result = hklm_key_.Create(HKEY_LOCAL_MACHINE, kRegistryExtensions, 211 if ((result = hklm_key_.Create(HKEY_LOCAL_MACHINE, kRegistryExtensions,
206 KEY_NOTIFY | KEY_WOW64_32KEY)) == 212 KEY_NOTIFY | KEY_WOW64_32KEY)) ==
207 ERROR_SUCCESS) { 213 ERROR_SUCCESS) {
208 base::win::RegKey::ChangeCallback callback = 214 base::win::RegKey::ChangeCallback callback =
209 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, 215 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged,
210 base::Unretained(this), base::Unretained(&hklm_key_)); 216 base::Unretained(this), base::Unretained(&hklm_key_));
211 hklm_key_.StartWatching(callback); 217 hklm_key_.StartWatching(callback);
212 } else { 218 } else {
213 LOG(WARNING) << "Error observing HKLM: " << result; 219 LOG(WARNING) << "Error observing HKLM: " << result;
214 } 220 }
215 221
216 if ((result = hkcu_key_.Create(HKEY_CURRENT_USER, kRegistryExtensions, 222 if ((result = hkcu_key_.Create(HKEY_CURRENT_USER, kRegistryExtensions,
217 KEY_NOTIFY)) == ERROR_SUCCESS) { 223 KEY_NOTIFY)) == ERROR_SUCCESS) {
218 base::win::RegKey::ChangeCallback callback = 224 base::win::RegKey::ChangeCallback callback =
219 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, 225 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged,
220 base::Unretained(this), base::Unretained(&hkcu_key_)); 226 base::Unretained(this), base::Unretained(&hkcu_key_));
221 hkcu_key_.StartWatching(callback); 227 hkcu_key_.StartWatching(callback);
222 } else { 228 } else {
223 LOG(WARNING) << "Error observing HKCU: " << result; 229 LOG(WARNING) << "Error observing HKCU: " << result;
224 } 230 }
231
232 attempted_watching_registry_ = true;
225 } 233 }
226 234
227 void ExternalRegistryLoader::OnRegistryKeyChanged(base::win::RegKey* key) { 235 void ExternalRegistryLoader::OnRegistryKeyChanged(base::win::RegKey* key) {
228 // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is 236 // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is
229 // called, so we need to re-register. 237 // called, so we need to re-register.
230 key->StartWatching(base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, 238 key->StartWatching(base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged,
231 base::Unretained(this), base::Unretained(key))); 239 base::Unretained(this), base::Unretained(key)));
232 240
233 BrowserThread::PostTask( 241 BrowserThread::PostTask(
234 BrowserThread::FILE, FROM_HERE, 242 BrowserThread::FILE, FROM_HERE,
235 base::Bind(&ExternalRegistryLoader::UpdatePrefsOnFileThread, this)); 243 base::Bind(&ExternalRegistryLoader::UpdatePrefsOnFileThread, this));
236 } 244 }
237 245
238 void ExternalRegistryLoader::UpdatePrefsOnFileThread() { 246 void ExternalRegistryLoader::UpdatePrefsOnFileThread() {
239 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 247 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
240 base::TimeTicks start_time = base::TimeTicks::Now(); 248 base::TimeTicks start_time = base::TimeTicks::Now();
241 std::unique_ptr<base::DictionaryValue> prefs = LoadPrefsOnFileThread(); 249 std::unique_ptr<base::DictionaryValue> prefs = LoadPrefsOnFileThread();
242 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWinUpdate", 250 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWinUpdate",
243 base::TimeTicks::Now() - start_time); 251 base::TimeTicks::Now() - start_time);
244 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 252 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
245 base::Bind(&ExternalRegistryLoader::OnUpdated, this, 253 base::Bind(&ExternalRegistryLoader::OnUpdated, this,
246 base::Passed(&prefs))); 254 base::Passed(&prefs)));
247 } 255 }
248 256
249 } // namespace extensions 257 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698