| 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_extension_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/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_handle.h" | 10 #include "base/memory/scoped_handle.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "base/version.h" | 16 #include "base/version.h" |
| 17 #include "base/win/registry.h" | 17 #include "base/win/registry.h" |
| 18 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 18 #include "chrome/browser/extensions/external_provider_impl.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 | 20 |
| 21 using content::BrowserThread; | 21 using content::BrowserThread; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // The Registry subkey that contains information about external extensions. | 25 // The Registry subkey that contains information about external extensions. |
| 26 const char kRegistryExtensions[] = "Software\\Google\\Chrome\\Extensions"; | 26 const char kRegistryExtensions[] = "Software\\Google\\Chrome\\Extensions"; |
| 27 | 27 |
| 28 // Registry value of of that key that defines the path to the .crx file. | 28 // Registry value of of that key that defines the path to the .crx file. |
| 29 const wchar_t kRegistryExtensionPath[] = L"path"; | 29 const wchar_t kRegistryExtensionPath[] = L"path"; |
| 30 | 30 |
| 31 // Registry value of that key that defines the current version of the .crx file. | 31 // Registry value of that key that defines the current version of the .crx file. |
| 32 const wchar_t kRegistryExtensionVersion[] = L"version"; | 32 const wchar_t kRegistryExtensionVersion[] = L"version"; |
| 33 | 33 |
| 34 bool CanOpenFileForReading(const FilePath& path) { | 34 bool CanOpenFileForReading(const FilePath& path) { |
| 35 ScopedStdioHandle file_handle(file_util::OpenFile(path, "rb")); | 35 ScopedStdioHandle file_handle(file_util::OpenFile(path, "rb")); |
| 36 return file_handle.get() != NULL; | 36 return file_handle.get() != NULL; |
| 37 } | 37 } |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 void ExternalRegistryExtensionLoader::StartLoading() { | 41 namespace extensions { |
| 42 |
| 43 void ExternalRegistryLoader::StartLoading() { |
| 42 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 43 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 44 BrowserThread::FILE, FROM_HERE, | 46 BrowserThread::FILE, FROM_HERE, |
| 45 base::Bind(&ExternalRegistryExtensionLoader::LoadOnFileThread, this)); | 47 base::Bind(&ExternalRegistryLoader::LoadOnFileThread, this)); |
| 46 } | 48 } |
| 47 | 49 |
| 48 void ExternalRegistryExtensionLoader::LoadOnFileThread() { | 50 void ExternalRegistryLoader::LoadOnFileThread() { |
| 49 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 51 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 50 base::TimeTicks start_time = base::TimeTicks::Now(); | 52 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 51 scoped_ptr<DictionaryValue> prefs(new DictionaryValue); | 53 scoped_ptr<DictionaryValue> prefs(new DictionaryValue); |
| 52 | 54 |
| 53 // A map of IDs, to weed out duplicates between HKCU and HKLM. | 55 // A map of IDs, to weed out duplicates between HKCU and HKLM. |
| 54 std::set<string16> keys; | 56 std::set<string16> keys; |
| 55 base::win::RegistryKeyIterator iterator_machine_key( | 57 base::win::RegistryKeyIterator iterator_machine_key( |
| 56 HKEY_LOCAL_MACHINE, ASCIIToWide(kRegistryExtensions).c_str()); | 58 HKEY_LOCAL_MACHINE, ASCIIToWide(kRegistryExtensions).c_str()); |
| 57 for (; iterator_machine_key.Valid(); ++iterator_machine_key) | 59 for (; iterator_machine_key.Valid(); ++iterator_machine_key) |
| 58 keys.insert(iterator_machine_key.Name()); | 60 keys.insert(iterator_machine_key.Name()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (key.ReadValue(kRegistryExtensionVersion, &extension_version) | 118 if (key.ReadValue(kRegistryExtensionVersion, &extension_version) |
| 117 != ERROR_SUCCESS) { | 119 != ERROR_SUCCESS) { |
| 118 // TODO(erikkay): find a way to get this into about:extensions | 120 // TODO(erikkay): find a way to get this into about:extensions |
| 119 LOG(ERROR) << "Missing value " << kRegistryExtensionVersion | 121 LOG(ERROR) << "Missing value " << kRegistryExtensionVersion |
| 120 << " for key " << key_path << "."; | 122 << " for key " << key_path << "."; |
| 121 continue; | 123 continue; |
| 122 } | 124 } |
| 123 | 125 |
| 124 std::string id = WideToASCII(*it); | 126 std::string id = WideToASCII(*it); |
| 125 StringToLowerASCII(&id); | 127 StringToLowerASCII(&id); |
| 126 if (!extensions::Extension::IdIsValid(id)) { | 128 if (!Extension::IdIsValid(id)) { |
| 127 LOG(ERROR) << "Invalid id value " << id | 129 LOG(ERROR) << "Invalid id value " << id |
| 128 << " for key " << key_path << "."; | 130 << " for key " << key_path << "."; |
| 129 continue; | 131 continue; |
| 130 } | 132 } |
| 131 | 133 |
| 132 Version version(WideToASCII(extension_version)); | 134 Version version(WideToASCII(extension_version)); |
| 133 if (!version.IsValid()) { | 135 if (!version.IsValid()) { |
| 134 LOG(ERROR) << "Invalid version value " << extension_version | 136 LOG(ERROR) << "Invalid version value " << extension_version |
| 135 << " for key " << key_path << "."; | 137 << " for key " << key_path << "."; |
| 136 continue; | 138 continue; |
| 137 } | 139 } |
| 138 | 140 |
| 139 prefs->SetString( | 141 prefs->SetString( |
| 140 id + "." + ExternalExtensionProviderImpl::kExternalVersion, | 142 id + "." + ExternalProviderImpl::kExternalVersion, |
| 141 WideToASCII(extension_version)); | 143 WideToASCII(extension_version)); |
| 142 prefs->SetString( | 144 prefs->SetString( |
| 143 id + "." + ExternalExtensionProviderImpl::kExternalCrx, | 145 id + "." + ExternalProviderImpl::kExternalCrx, |
| 144 extension_path_str); | 146 extension_path_str); |
| 145 } | 147 } |
| 146 | 148 |
| 147 prefs_.reset(prefs.release()); | 149 prefs_.reset(prefs.release()); |
| 148 HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin", | 150 HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin", |
| 149 base::TimeTicks::Now() - start_time); | 151 base::TimeTicks::Now() - start_time); |
| 150 BrowserThread::PostTask( | 152 BrowserThread::PostTask( |
| 151 BrowserThread::UI, FROM_HERE, | 153 BrowserThread::UI, FROM_HERE, |
| 152 base::Bind(&ExternalRegistryExtensionLoader::LoadFinished, this)); | 154 base::Bind(&ExternalRegistryLoader::LoadFinished, this)); |
| 153 } | 155 } |
| 156 |
| 157 } // namespace extensions |
| OLD | NEW |