| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ExternalRegistryLoader::LoadOnFileThread() { | 63 void ExternalRegistryLoader::LoadOnFileThread() { |
| 64 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 64 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 65 base::TimeTicks start_time = base::TimeTicks::Now(); | 65 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 66 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 66 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 67 | 67 |
| 68 // 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. |
| 69 std::set<base::string16> keys; | 69 std::set<base::string16> keys; |
| 70 base::win::RegistryKeyIterator iterator_machine_key( | 70 base::win::RegistryKeyIterator iterator_machine_key( |
| 71 HKEY_LOCAL_MACHINE, base::ASCIIToWide(kRegistryExtensions).c_str()); | 71 HKEY_LOCAL_MACHINE, |
| 72 base::ASCIIToWide(kRegistryExtensions).c_str(), |
| 73 KEY_WOW64_32KEY); |
| 72 for (; iterator_machine_key.Valid(); ++iterator_machine_key) | 74 for (; iterator_machine_key.Valid(); ++iterator_machine_key) |
| 73 keys.insert(iterator_machine_key.Name()); | 75 keys.insert(iterator_machine_key.Name()); |
| 74 base::win::RegistryKeyIterator iterator_user_key( | 76 base::win::RegistryKeyIterator iterator_user_key( |
| 75 HKEY_CURRENT_USER, base::ASCIIToWide(kRegistryExtensions).c_str()); | 77 HKEY_CURRENT_USER, |
| 78 base::ASCIIToWide(kRegistryExtensions).c_str(), |
| 79 0); |
| 76 for (; iterator_user_key.Valid(); ++iterator_user_key) | 80 for (; iterator_user_key.Valid(); ++iterator_user_key) |
| 77 keys.insert(iterator_user_key.Name()); | 81 keys.insert(iterator_user_key.Name()); |
| 78 | 82 |
| 79 // Iterate over the keys found, first trying HKLM, then HKCU, as per Windows | 83 // Iterate over the keys found, first trying HKLM, then HKCU, as per Windows |
| 80 // policy conventions. We only fall back to HKCU if the HKLM key cannot be | 84 // policy conventions. We only fall back to HKCU if the HKLM key cannot be |
| 81 // opened, not if the data within the key is invalid, for example. | 85 // opened, not if the data within the key is invalid, for example. |
| 82 for (std::set<base::string16>::const_iterator it = keys.begin(); | 86 for (std::set<base::string16>::const_iterator it = keys.begin(); |
| 83 it != keys.end(); ++it) { | 87 it != keys.end(); ++it) { |
| 84 base::win::RegKey key; | 88 base::win::RegKey key; |
| 85 base::string16 key_path = base::ASCIIToWide(kRegistryExtensions); | 89 base::string16 key_path = base::ASCIIToWide(kRegistryExtensions); |
| 86 key_path.append(L"\\"); | 90 key_path.append(L"\\"); |
| 87 key_path.append(*it); | 91 key_path.append(*it); |
| 88 if (key.Open(HKEY_LOCAL_MACHINE, | 92 if (key.Open(HKEY_LOCAL_MACHINE, |
| 89 key_path.c_str(), KEY_READ) != ERROR_SUCCESS) { | 93 key_path.c_str(), |
| 94 KEY_READ | KEY_WOW64_32KEY) != ERROR_SUCCESS) { |
| 90 if (key.Open(HKEY_CURRENT_USER, | 95 if (key.Open(HKEY_CURRENT_USER, |
| 91 key_path.c_str(), KEY_READ) != ERROR_SUCCESS) { | 96 key_path.c_str(), KEY_READ) != ERROR_SUCCESS) { |
| 92 LOG(ERROR) << "Unable to read registry key at path (HKLM & HKCU): " | 97 LOG(ERROR) << "Unable to read registry key at path (HKLM & HKCU): " |
| 93 << key_path << "."; | 98 << key_path << "."; |
| 94 continue; | 99 continue; |
| 95 } | 100 } |
| 96 } | 101 } |
| 97 | 102 |
| 98 std::string id = base::UTF16ToASCII(*it); | 103 std::string id = base::UTF16ToASCII(*it); |
| 99 base::StringToLowerASCII(&id); | 104 base::StringToLowerASCII(&id); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 187 |
| 183 prefs_.reset(prefs.release()); | 188 prefs_.reset(prefs.release()); |
| 184 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin", | 189 LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin", |
| 185 base::TimeTicks::Now() - start_time); | 190 base::TimeTicks::Now() - start_time); |
| 186 BrowserThread::PostTask( | 191 BrowserThread::PostTask( |
| 187 BrowserThread::UI, FROM_HERE, | 192 BrowserThread::UI, FROM_HERE, |
| 188 base::Bind(&ExternalRegistryLoader::LoadFinished, this)); | 193 base::Bind(&ExternalRegistryLoader::LoadFinished, this)); |
| 189 } | 194 } |
| 190 | 195 |
| 191 } // namespace extensions | 196 } // namespace extensions |
| OLD | NEW |