Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 : is_watching_hklm_(false), is_watching_hkcu_(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 Loading... | |
| 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 // Start watching registry if we are not already. |
| 204 LONG result = ERROR_SUCCESS; | 207 LONG result = ERROR_SUCCESS; |
| 205 if ((result = hklm_key_.Create(HKEY_LOCAL_MACHINE, kRegistryExtensions, | 208 if (!is_watching_hklm_) { |
|
Devlin
2017/04/04 01:44:07
Do we want these (this and is_watching_hkcu_) as s
lazyboy
2017/04/04 18:45:10
These can independently fail. Or at least HKLM can
Devlin
2017/04/04 20:48:35
So, my question here is more around whether or not
lazyboy
2017/04/04 21:47:23
Note that a watcher that previously failed would a
| |
| 206 KEY_NOTIFY | KEY_WOW64_32KEY)) == | 209 if ((result = hklm_key_.Create(HKEY_LOCAL_MACHINE, kRegistryExtensions, |
| 207 ERROR_SUCCESS) { | 210 KEY_NOTIFY | KEY_WOW64_32KEY)) == |
| 208 base::win::RegKey::ChangeCallback callback = | 211 ERROR_SUCCESS) { |
| 209 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | 212 base::win::RegKey::ChangeCallback callback = |
| 210 base::Unretained(this), base::Unretained(&hklm_key_)); | 213 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, |
| 211 hklm_key_.StartWatching(callback); | 214 base::Unretained(this), base::Unretained(&hklm_key_)); |
| 212 } else { | 215 hklm_key_.StartWatching(callback); |
| 213 LOG(WARNING) << "Error observing HKLM: " << result; | 216 is_watching_hklm_ = true; |
| 217 } else { | |
| 218 LOG(WARNING) << "Error observing HKLM: " << result; | |
| 219 } | |
| 214 } | 220 } |
| 215 | 221 |
| 216 if ((result = hkcu_key_.Create(HKEY_CURRENT_USER, kRegistryExtensions, | 222 if (!is_watching_hkcu_) { |
| 217 KEY_NOTIFY)) == ERROR_SUCCESS) { | 223 if ((result = hkcu_key_.Create(HKEY_CURRENT_USER, kRegistryExtensions, |
| 218 base::win::RegKey::ChangeCallback callback = | 224 KEY_NOTIFY)) == ERROR_SUCCESS) { |
| 219 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | 225 base::win::RegKey::ChangeCallback callback = |
| 220 base::Unretained(this), base::Unretained(&hkcu_key_)); | 226 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, |
| 221 hkcu_key_.StartWatching(callback); | 227 base::Unretained(this), base::Unretained(&hkcu_key_)); |
| 222 } else { | 228 hkcu_key_.StartWatching(callback); |
| 223 LOG(WARNING) << "Error observing HKCU: " << result; | 229 is_watching_hkcu_ = true; |
| 230 } else { | |
| 231 LOG(WARNING) << "Error observing HKCU: " << result; | |
| 232 } | |
| 224 } | 233 } |
| 225 } | 234 } |
| 226 | 235 |
| 227 void ExternalRegistryLoader::OnRegistryKeyChanged(base::win::RegKey* key) { | 236 void ExternalRegistryLoader::OnRegistryKeyChanged(base::win::RegKey* key) { |
| 228 // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is | 237 // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is |
| 229 // called, so we need to re-register. | 238 // called, so we need to re-register. |
| 230 key->StartWatching(base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | 239 key->StartWatching(base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, |
| 231 base::Unretained(this), base::Unretained(key))); | 240 base::Unretained(this), base::Unretained(key))); |
| 232 | 241 |
| 233 BrowserThread::PostTask( | 242 BrowserThread::PostTask( |
| 234 BrowserThread::FILE, FROM_HERE, | 243 BrowserThread::FILE, FROM_HERE, |
| 235 base::Bind(&ExternalRegistryLoader::UpdatePrefsOnFileThread, this)); | 244 base::Bind(&ExternalRegistryLoader::UpdatePrefsOnFileThread, this)); |
| 236 } | 245 } |
| 237 | 246 |
| 238 void ExternalRegistryLoader::UpdatePrefsOnFileThread() { | 247 void ExternalRegistryLoader::UpdatePrefsOnFileThread() { |
| 239 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 248 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 240 base::TimeTicks start_time = base::TimeTicks::Now(); | 249 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 241 std::unique_ptr<base::DictionaryValue> prefs = LoadPrefsOnFileThread(); | 250 std::unique_ptr<base::DictionaryValue> prefs = LoadPrefsOnFileThread(); |
| 242 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWinUpdate", | 251 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWinUpdate", |
| 243 base::TimeTicks::Now() - start_time); | 252 base::TimeTicks::Now() - start_time); |
| 244 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 253 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 245 base::Bind(&ExternalRegistryLoader::OnUpdated, this, | 254 base::Bind(&ExternalRegistryLoader::OnUpdated, this, |
| 246 base::Passed(&prefs))); | 255 base::Passed(&prefs))); |
| 247 } | 256 } |
| 248 | 257 |
| 249 } // namespace extensions | 258 } // namespace extensions |
| OLD | NEW |