| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 | 13 |
| 14 class ExtensionMessageBundle; | 14 class ExtensionMessageBundle; |
| 15 | 15 |
| 16 // Utilties for manipulating the on-disk storage of extensions. | 16 // Utilties for manipulating the on-disk storage of extensions. |
| 17 namespace extension_file_util { | 17 namespace extension_file_util { |
| 18 | 18 |
| 19 // The name of the directory inside the profile that we store installed | 19 // The name of the directory inside the profile that we store installed |
| 20 // extension in. | 20 // extension in. |
| 21 extern const char kInstallDirectoryName[]; | 21 extern const char kInstallDirectoryName[]; |
| 22 | 22 |
| 23 // The name of the file that contains the current version of an installed | 23 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. |
| 24 // extension. | 24 // The destination directiory is returned on success, or empty path is returned |
| 25 extern const char kCurrentVersionFileName[]; | 25 // on failure. |
| 26 FilePath InstallExtension(const FilePath& unpacked_source_dir, |
| 27 const std::string& id, |
| 28 const std::string& version, |
| 29 const FilePath& extensions_dir); |
| 26 | 30 |
| 27 // Move source_dir to dest_dir (it will actually be named dest_dir, not inside | 31 // Removes all versions of the extension with |id| from |extensions_dir|. |
| 28 // dest_dir). If the parent path doesn't exist, create it. If something else is | 32 void UninstallExtension(const FilePath& extensions_dir, |
| 29 // already there, remove it. | 33 const std::string& id); |
| 30 bool MoveDirSafely(const FilePath& source_dir, const FilePath& dest_dir); | |
| 31 | |
| 32 // Updates the Current Version file inside the installed extension. | |
| 33 bool SetCurrentVersion(const FilePath& dest_dir, | |
| 34 const std::string& version, | |
| 35 std::string* error); | |
| 36 | |
| 37 // Reads the Current Version file. | |
| 38 bool ReadCurrentVersion(const FilePath& dir, std::string* version_string); | |
| 39 | |
| 40 // Determine what type of install it is (new, upgrade, overinstall, downgrade) | |
| 41 // given the current version and a newly installing version. |extensions_dir| is | |
| 42 // the root directory containing all extensions in the user profile. | |
| 43 // |extension_id| and |current_version_str| are the id and version of the | |
| 44 // extension contained in |src_dir|, if any. | |
| 45 // | |
| 46 // Returns the full path to the destination version directory and the type of | |
| 47 // install that was attempted. | |
| 48 Extension::InstallType CompareToInstalledVersion( | |
| 49 const FilePath& extensions_dir, | |
| 50 const std::string& extension_id, | |
| 51 const std::string& current_version_str, | |
| 52 const std::string& new_version_str, | |
| 53 FilePath* version_dir); | |
| 54 | |
| 55 // Sanity check that the directory has the minimum files to be a working | |
| 56 // extension. | |
| 57 bool SanityCheckExtension(const FilePath& extension_root); | |
| 58 | |
| 59 // Installs an extension unpacked in |src_dir|. | |
| 60 // | |
| 61 // On failure, also returns an error message. | |
| 62 // | |
| 63 // NOTE: |src_dir| is not actually copied in the case of downgrades or | |
| 64 // overinstall of previous verisons of the extension. In that case, the function | |
| 65 // returns true and install_type is populated. | |
| 66 bool InstallExtension(const FilePath& src_dir, | |
| 67 const FilePath& version_dir, | |
| 68 std::string* error); | |
| 69 | 34 |
| 70 // Loads and validates an extension from the specified directory. Returns NULL | 35 // Loads and validates an extension from the specified directory. Returns NULL |
| 71 // on failure, with a description of the error in |error|. | 36 // on failure, with a description of the error in |error|. |
| 72 Extension* LoadExtension(const FilePath& extension_root, | 37 Extension* LoadExtension(const FilePath& extension_root, |
| 73 bool require_key, | 38 bool require_key, |
| 74 std::string* error); | 39 std::string* error); |
| 75 | 40 |
| 76 // Returns true if the given extension object is valid and consistent. | 41 // Returns true if the given extension object is valid and consistent. |
| 77 // Otherwise, a description of the error is returned in |error|. | 42 // Otherwise, a description of the error is returned in |error|. |
| 78 bool ValidateExtension(Extension* extension, std::string* error); | 43 bool ValidateExtension(Extension* extension, std::string* error); |
| 79 | 44 |
| 80 // Uninstalls the extension |id| from the install directory |extensions_dir|. | 45 // Cleans up the extension install directory. It can end up with garbage in it |
| 81 void UninstallExtension(const std::string& id, const FilePath& extensions_dir); | 46 // if extensions can't initially be removed when they are uninstalled (eg if a |
| 82 | 47 // file is in use). |
| 83 // Clean up directories that aren't valid extensions from the install directory. | 48 // |
| 49 // |extensions_dir| is the install directory to look in. |extension_paths| is a |
| 50 // map from extension id to full installation path. |
| 51 // |
| 52 // Obsolete version directories are removed, as are directories that aren't |
| 53 // found in |extension_paths|. |
| 84 void GarbageCollectExtensions( | 54 void GarbageCollectExtensions( |
| 85 const FilePath& extensions_dir, | 55 const FilePath& extensions_dir, |
| 86 const std::set<std::string>& installed_ids, | 56 const std::map<std::string, FilePath>& extension_paths); |
| 87 const std::map<std::string, std::string>& installed_versions); | |
| 88 | 57 |
| 89 // Loads extension message catalogs and returns message bundle. | 58 // Loads extension message catalogs and returns message bundle. |
| 90 // Returns NULL on error, or if extension is not localized. | 59 // Returns NULL on error, or if extension is not localized. |
| 91 ExtensionMessageBundle* LoadExtensionMessageBundle( | 60 ExtensionMessageBundle* LoadExtensionMessageBundle( |
| 92 const FilePath& extension_path, | 61 const FilePath& extension_path, |
| 93 const std::string& default_locale, | 62 const std::string& default_locale, |
| 94 std::string* error); | 63 std::string* error); |
| 95 | 64 |
| 96 // We need to reserve the namespace of entries that start with "_" for future | 65 // We need to reserve the namespace of entries that start with "_" for future |
| 97 // use by Chrome. | 66 // use by Chrome. |
| 98 // If any files or directories are found using "_" prefix and are not on | 67 // If any files or directories are found using "_" prefix and are not on |
| 99 // reserved list we return false, and set error message. | 68 // reserved list we return false, and set error message. |
| 100 bool CheckForIllegalFilenames(const FilePath& extension_path, | 69 bool CheckForIllegalFilenames(const FilePath& extension_path, |
| 101 std::string* error); | 70 std::string* error); |
| 102 | 71 |
| 103 // Get a relative file path from a chrome-extension:// URL. | 72 // Get a relative file path from a chrome-extension:// URL. |
| 104 FilePath ExtensionURLToRelativeFilePath(const GURL& url); | 73 FilePath ExtensionURLToRelativeFilePath(const GURL& url); |
| 105 | 74 |
| 106 } // extension_file_util | 75 } // extension_file_util |
| 107 | 76 |
| 108 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 77 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
| OLD | NEW |