diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-12 02:51:34 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-12 02:51:34 +0000 |
commit | a1257b12bd288161e1eadeff9f2378de9b6e029a (patch) | |
tree | 36352e0325d128786131a059a501bae9c1f46967 /chrome/browser/extensions/external_pref_extension_provider.cc | |
parent | b5110bcd688f2d19b48af67e255273be2b94e68b (diff) | |
download | chromium_src-a1257b12bd288161e1eadeff9f2378de9b6e029a.zip chromium_src-a1257b12bd288161e1eadeff9f2378de9b6e029a.tar.gz chromium_src-a1257b12bd288161e1eadeff9f2378de9b6e029a.tar.bz2 |
Factor out the code that deals with installing external extensions through Registry and Preferences into separate classes. While I was at it, I removed the EXTERNAL_INSTALL file, since we now keep track of this in the Preferences.
This also takes care of the virtualization problem in the unit tests for vista (see bug).
BUG=13063
TEST=None, covered by automated tests.
Review URL: http://codereview.chromium.org/122004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/external_pref_extension_provider.cc')
-rw-r--r-- | chrome/browser/extensions/external_pref_extension_provider.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/chrome/browser/extensions/external_pref_extension_provider.cc b/chrome/browser/extensions/external_pref_extension_provider.cc new file mode 100644 index 0000000..6db3355 --- /dev/null +++ b/chrome/browser/extensions/external_pref_extension_provider.cc @@ -0,0 +1,84 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/extensions/external_pref_extension_provider.h" + +#include "base/file_path.h" +#include "base/string_util.h" +#include "base/version.h" + +// Constants for keeping track of extension preferences. +const wchar_t kLocation[] = L"location"; +const wchar_t kState[] = L"state"; +const wchar_t kExternalCrx[] = L"external_crx"; +const wchar_t kExternalVersion[] = L"external_version"; + +ExternalPrefExtensionProvider::ExternalPrefExtensionProvider( + DictionaryValue* prefs) { + DCHECK(prefs); + prefs_.reset(prefs); +} + +ExternalPrefExtensionProvider::~ExternalPrefExtensionProvider() { +} + +void ExternalPrefExtensionProvider::VisitRegisteredExtension( + Visitor* visitor, const std::set<std::string>& ids_to_ignore) const { + for (DictionaryValue::key_iterator i = prefs_->begin_keys(); + i != prefs_->end_keys(); ++i) { + const std::wstring& extension_id = *i; + if (ids_to_ignore.find(WideToASCII(extension_id)) != ids_to_ignore.end()) + continue; + + DictionaryValue* extension = NULL; + if (!prefs_->GetDictionary(extension_id, &extension)) { + NOTREACHED() << "Cannot read extension " << extension_id.c_str() + << " from dictionary."; + continue; + } + + int location; + if (extension->GetInteger(kLocation, &location) && + location != Extension::EXTERNAL_PREF) { + continue; + } + int state; + if (extension->GetInteger(kState, &state) && + state == Extension::KILLBIT) { + continue; + } + + FilePath::StringType external_crx; + std::string external_version; + if (!extension->GetString(kExternalCrx, &external_crx) || + !extension->GetString(kExternalVersion, &external_version)) { + LOG(WARNING) << "Malformed extension dictionary for extension: " + << extension_id.c_str(); + continue; + } + + scoped_ptr<Version> version; + version.reset(Version::GetVersionFromString(external_version)); + visitor->OnExternalExtensionFound( + WideToASCII(extension_id), version.get(), FilePath(external_crx)); + } +} + +Version* ExternalPrefExtensionProvider::RegisteredVersion( + std::string id, Extension::Location* location) const { + DictionaryValue* extension = NULL; + if (!prefs_->GetDictionary(ASCIIToWide(id), &extension)) { + NOTREACHED() << "Cannot read extension " << id.c_str() + << " from dictionary."; + return NULL; + } + + std::string external_version; + if (!extension->GetString(kExternalVersion, &external_version)) + return NULL; + + if (location) + *location = Extension::EXTERNAL_PREF; + return Version::GetVersionFromString(external_version); +} |