Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/extensions/external_registry_loader_win.cc

Issue 10692168: Moved ExternalExtensionLoaders/Providers into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 scoped_ptr<Version> version; 134 scoped_ptr<Version> version;
133 version.reset(Version::GetVersionFromString( 135 version.reset(Version::GetVersionFromString(
134 WideToASCII(extension_version))); 136 WideToASCII(extension_version)));
135 if (!version.get()) { 137 if (!version.get()) {
136 LOG(ERROR) << "Invalid version value " << extension_version 138 LOG(ERROR) << "Invalid version value " << extension_version
137 << " for key " << key_path << "."; 139 << " for key " << key_path << ".";
138 continue; 140 continue;
139 } 141 }
140 142
141 prefs->SetString( 143 prefs->SetString(
142 id + "." + ExternalExtensionProviderImpl::kExternalVersion, 144 id + "." + ExternalProviderImpl::kExternalVersion,
143 WideToASCII(extension_version)); 145 WideToASCII(extension_version));
144 prefs->SetString( 146 prefs->SetString(
145 id + "." + ExternalExtensionProviderImpl::kExternalCrx, 147 id + "." + ExternalProviderImpl::kExternalCrx,
146 extension_path_str); 148 extension_path_str);
147 } 149 }
148 150
149 prefs_.reset(prefs.release()); 151 prefs_.reset(prefs.release());
150 HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin", 152 HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin",
151 base::TimeTicks::Now() - start_time); 153 base::TimeTicks::Now() - start_time);
152 BrowserThread::PostTask( 154 BrowserThread::PostTask(
153 BrowserThread::UI, FROM_HERE, 155 BrowserThread::UI, FROM_HERE,
154 base::Bind(&ExternalRegistryExtensionLoader::LoadFinished, this)); 156 base::Bind(&ExternalRegistryLoader::LoadFinished, this));
155 } 157 }
158
159 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698