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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 | 54 |
55 namespace extensions { | 55 namespace extensions { |
56 | 56 |
57 void ExternalRegistryLoader::StartLoading() { | 57 void ExternalRegistryLoader::StartLoading() { |
58 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
59 BrowserThread::PostTask( | 59 BrowserThread::PostTask( |
60 BrowserThread::FILE, FROM_HERE, | 60 BrowserThread::FILE, FROM_HERE, |
61 base::Bind(&ExternalRegistryLoader::LoadOnFileThread, this)); | 61 base::Bind(&ExternalRegistryLoader::LoadOnFileThread, this)); |
62 } | 62 } |
63 | 63 |
64 void ExternalRegistryLoader::LoadOnFileThread() { | 64 void ExternalRegistryLoader::LoadPrefsOnFileThread() { |
65 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 65 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
66 base::TimeTicks start_time = base::TimeTicks::Now(); | |
67 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 66 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
68 | 67 |
69 // A map of IDs, to weed out duplicates between HKCU and HKLM. | 68 // A map of IDs, to weed out duplicates between HKCU and HKLM. |
70 std::set<base::string16> keys; | 69 std::set<base::string16> keys; |
71 base::win::RegistryKeyIterator iterator_machine_key( | 70 base::win::RegistryKeyIterator iterator_machine_key( |
72 HKEY_LOCAL_MACHINE, | 71 HKEY_LOCAL_MACHINE, |
73 kRegistryExtensions, | 72 kRegistryExtensions, |
74 KEY_WOW64_32KEY); | 73 KEY_WOW64_32KEY); |
75 for (; iterator_machine_key.Valid(); ++iterator_machine_key) | 74 for (; iterator_machine_key.Valid(); ++iterator_machine_key) |
76 keys.insert(iterator_machine_key.Name()); | 75 keys.insert(iterator_machine_key.Name()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 base::UTF16ToASCII(extension_version)); | 175 base::UTF16ToASCII(extension_version)); |
177 prefs->SetString( | 176 prefs->SetString( |
178 MakePrefName(id, ExternalProviderImpl::kExternalCrx), | 177 MakePrefName(id, ExternalProviderImpl::kExternalCrx), |
179 extension_path_str); | 178 extension_path_str); |
180 prefs->SetBoolean( | 179 prefs->SetBoolean( |
181 MakePrefName(id, ExternalProviderImpl::kMayBeUntrusted), | 180 MakePrefName(id, ExternalProviderImpl::kMayBeUntrusted), |
182 true); | 181 true); |
183 } | 182 } |
184 | 183 |
185 prefs_.reset(prefs.release()); | 184 prefs_.reset(prefs.release()); |
185 } | |
186 | |
187 void ExternalRegistryLoader::LoadOnFileThread() { | |
188 base::TimeTicks start_time = base::TimeTicks::Now(); | |
189 LoadPrefsOnFileThread(); | |
186 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin", | 190 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin", |
187 base::TimeTicks::Now() - start_time); | 191 base::TimeTicks::Now() - start_time); |
188 BrowserThread::PostTask( | 192 BrowserThread::PostTask( |
189 BrowserThread::UI, FROM_HERE, | 193 BrowserThread::UI, FROM_HERE, |
190 base::Bind(&ExternalRegistryLoader::LoadFinished, this)); | 194 base::Bind( |
195 &ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry, this)); | |
196 } | |
197 | |
198 void ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry() { | |
199 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
200 LoadFinished(); | |
201 | |
202 // Start watching registry. | |
203 // TODO(lazyboy): Is using KEY_WOW64_32KEY correct? | |
204 if (hklm_key_.Create(HKEY_LOCAL_MACHINE, | |
205 kRegistryExtensions, | |
206 KEY_NOTIFY | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
207 base::win::RegKey::ChangeCallback callback = | |
208 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | |
209 base::Unretained(this), | |
asargent_no_longer_on_chrome
2016/01/20 22:49:00
I know that reading from the registry must be done
lazyboy
2016/01/21 21:02:12
I've based my changes on plugin_service_impl.cc, w
| |
210 base::Unretained(&hklm_key_)); | |
211 hklm_key_.StartWatching(callback); | |
212 } else { | |
213 // TODO(lazyboy): Error handling. | |
214 LOG(ERROR) << "Error observing HKLM."; | |
215 } | |
216 | |
217 if (hkcu_key_.Create(HKEY_CURRENT_USER, | |
218 kRegistryExtensions, | |
219 KEY_NOTIFY) == ERROR_SUCCESS) { | |
220 base::win::RegKey::ChangeCallback callback = | |
221 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | |
222 base::Unretained(this), | |
223 base::Unretained(&hkcu_key_)); | |
224 hkcu_key_.StartWatching(callback); | |
225 } else { | |
226 // TODO(lazyboy): Error handling. | |
227 LOG(ERROR) << "Error observing HKCU."; | |
228 } | |
229 } | |
230 | |
231 void ExternalRegistryLoader::OnRegistryKeyChanged(base::win::RegKey* key) { | |
232 key->StartWatching( | |
Devlin
2016/01/21 00:14:26
Save the reader the lookup into win/registry.h wit
lazyboy
2016/01/21 21:02:12
Done.
| |
233 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | |
234 base::Unretained(this), | |
235 base::Unretained(key))); | |
236 | |
237 BrowserThread::PostTask( | |
238 BrowserThread::FILE, FROM_HERE, | |
239 base::Bind(&ExternalRegistryLoader::UpdatePrefsOnFileThread, this)); | |
240 } | |
241 | |
242 void ExternalRegistryLoader::UpdatePrefsOnFileThread() { | |
243 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
244 base::TimeTicks start_time = base::TimeTicks::Now(); | |
245 LoadPrefsOnFileThread(); | |
246 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWinUpdate", | |
247 base::TimeTicks::Now() - start_time); | |
248 BrowserThread::PostTask( | |
249 BrowserThread::UI, FROM_HERE, | |
250 base::Bind(&ExternalRegistryLoader::OnUpdated, this)); | |
191 } | 251 } |
192 | 252 |
193 } // namespace extensions | 253 } // namespace extensions |
OLD | NEW |