diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-31 01:33:28 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-31 01:33:28 +0000 |
commit | 18a12354e6c3e1edf2f85e11cd7359127d2d3ce2 (patch) | |
tree | 4da92adef2a8d63222485890179d61d7f6f1e61c /chrome/browser | |
parent | a92d2fd9d1fe0e74f6ca7d540858a4711b46367e (diff) | |
download | chromium_src-18a12354e6c3e1edf2f85e11cd7359127d2d3ce2.zip chromium_src-18a12354e6c3e1edf2f85e11cd7359127d2d3ce2.tar.gz chromium_src-18a12354e6c3e1edf2f85e11cd7359127d2d3ce2.tar.bz2 |
Add support for loading Current Version. (haven't removed the old style loading yet)
Review URL: http://codereview.chromium.org/19525
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 56 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 10 |
3 files changed, 53 insertions, 17 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 78758df..7440d6b 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -149,6 +149,15 @@ bool ExtensionsServiceBackend::LoadExtensionsFromDirectory( file_util::FileEnumerator::DIRECTORIES); for (FilePath child_path = enumerator.Next(); !child_path.value().empty(); child_path = enumerator.Next()) { + std::string version_str; + if (ReadCurrentVersion(child_path, &version_str)) { + child_path = child_path.AppendASCII(version_str); + } else { + // For now, continue to allow fallback to a non-versioned directory + // structure. This is so that we can use this same method to load + // from local directories that developers are just hacking in place. + // TODO(erikkay): perhaps we should use a different code path for this. + } FilePath manifest_path = child_path.AppendASCII(Extension::kManifestFilename); if (!file_util::PathExists(manifest_path)) { @@ -319,30 +328,45 @@ DictionaryValue* ExtensionsServiceBackend::ReadManifest( return manifest; } +bool ExtensionsServiceBackend::ReadCurrentVersion( + const FilePath& extension_path, + std::string* version_string) { + FilePath current_version = + extension_path.AppendASCII(ExtensionsService::kCurrentVersionFileName); + if (file_util::PathExists(current_version)) { + if (file_util::ReadFileToString(current_version, version_string)) { + TrimWhitespace(*version_string, TRIM_ALL, version_string); + return true; + } + } + return false; +} + bool ExtensionsServiceBackend::CheckCurrentVersion( const FilePath& extension_path, const std::string& version, const FilePath& dest_dir, scoped_refptr<ExtensionsServiceFrontendInterface> frontend) { - FilePath current_version = - dest_dir.AppendASCII(ExtensionsService::kCurrentVersionFileName); - if (file_util::PathExists(current_version)) { - std::string version_str; - if (file_util::ReadFileToString(current_version, &version_str)) { - if (version_str == version) { + std::string version_str; + if (ReadCurrentVersion(dest_dir, &version_str)) { + if (version_str == version) { + FilePath version_dir = dest_dir.AppendASCII(version_str); + if (file_util::PathExists(version_dir)) { ReportExtensionInstallError(frontend, extension_path, "Extension version already installed"); return false; - } else { - scoped_ptr<Version> cur_version( - Version::GetVersionFromString(version_str)); - scoped_ptr<Version> new_version( - Version::GetVersionFromString(version)); - if (cur_version->CompareTo(*new_version) >= 0) { - ReportExtensionInstallError(frontend, extension_path, - "More recent version of extension already installed"); - return false; - } + } + // If the existing version_dir doesn't exist, then we'll return true + // so that we attempt to repair the broken installation. + } else { + scoped_ptr<Version> cur_version( + Version::GetVersionFromString(version_str)); + scoped_ptr<Version> new_version( + Version::GetVersionFromString(version)); + if (cur_version->CompareTo(*new_version) >= 0) { + ReportExtensionInstallError(frontend, extension_path, + "More recent version of extension already installed"); + return false; } } } diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index b9cf4a6..48d9778 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -142,6 +142,10 @@ class ExtensionsServiceBackend DictionaryValue* ReadManifest(const FilePath& extension_path, scoped_refptr<ExtensionsServiceFrontendInterface> frontend); + // Reads the Current Version file from |extension_path|. + bool ReadCurrentVersion(const FilePath& extension_path, + std::string* version_string); + // Check that the version to be installed is > the current installed // extension. bool CheckCurrentVersion(const FilePath& extension_path, diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index 03b0b24..c6af8ff 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -139,7 +139,7 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { // Note: There can be more errors if there are extra directories, like .svn // directories. EXPECT_TRUE(frontend->errors()->size() >= 2u); - ASSERT_EQ(2u, frontend->extensions()->size()); + ASSERT_EQ(3u, frontend->extensions()->size()); EXPECT_EQ(std::string("com.google.myextension1"), frontend->extensions()->at(0)->id()); @@ -168,6 +168,14 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { EXPECT_EQ(std::string(""), frontend->extensions()->at(1)->description()); ASSERT_EQ(0u, frontend->extensions()->at(1)->user_scripts().size()); + + EXPECT_EQ(std::string("com.google.myextension3"), + frontend->extensions()->at(2)->id()); + EXPECT_EQ(std::string("My extension 3"), + frontend->extensions()->at(2)->name()); + EXPECT_EQ(std::string(""), + frontend->extensions()->at(2)->description()); + ASSERT_EQ(0u, frontend->extensions()->at(2)->user_scripts().size()); }; // Test installing extensions. |