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(&ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry, |
195 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, kRegistryExtensions, | |
205 KEY_NOTIFY | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
206 base::win::RegKey::ChangeCallback callback = | |
207 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | |
208 base::Unretained(this), base::Unretained(&hklm_key_)); | |
209 hklm_key_.StartWatching(callback); | |
210 } else { | |
211 // TODO(lazyboy): Error handling. | |
asargent_no_longer_on_chrome
2016/01/25 18:50:52
Did you have any particular ideas in mind? I don't
lazyboy
2016/01/26 05:20:04
No I don't, maybe a LOG(WARNING) is enough?
Perhap
| |
212 LOG(ERROR) << "Error observing HKLM."; | |
213 } | |
214 | |
215 if (hkcu_key_.Create(HKEY_CURRENT_USER, kRegistryExtensions, KEY_NOTIFY) == | |
216 ERROR_SUCCESS) { | |
217 base::win::RegKey::ChangeCallback callback = | |
218 base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | |
219 base::Unretained(this), base::Unretained(&hkcu_key_)); | |
220 hkcu_key_.StartWatching(callback); | |
221 } else { | |
222 // TODO(lazyboy): Error handling. | |
223 LOG(ERROR) << "Error observing HKCU."; | |
224 } | |
225 } | |
226 | |
227 void ExternalRegistryLoader::OnRegistryKeyChanged(base::win::RegKey* key) { | |
228 // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is | |
229 // called, so we need to re-register. | |
230 key->StartWatching(base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, | |
231 base::Unretained(this), base::Unretained(key))); | |
232 | |
233 BrowserThread::PostTask( | |
234 BrowserThread::FILE, FROM_HERE, | |
235 base::Bind(&ExternalRegistryLoader::UpdatePrefsOnFileThread, this)); | |
236 } | |
237 | |
238 void ExternalRegistryLoader::UpdatePrefsOnFileThread() { | |
239 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
240 base::TimeTicks start_time = base::TimeTicks::Now(); | |
241 LoadPrefsOnFileThread(); | |
242 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWinUpdate", | |
243 base::TimeTicks::Now() - start_time); | |
244 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
245 base::Bind(&ExternalRegistryLoader::OnUpdated, this)); | |
191 } | 246 } |
192 | 247 |
193 } // namespace extensions | 248 } // namespace extensions |
OLD | NEW |