| 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_BROWSER_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 6 #define CHROME_BROWSER_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; |
| 15 |
| 14 // Utilties for manipulating the on-disk storage of extensions. | 16 // Utilties for manipulating the on-disk storage of extensions. |
| 15 namespace extension_file_util { | 17 namespace extension_file_util { |
| 16 | 18 |
| 17 // 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 |
| 18 // extension in. | 20 // extension in. |
| 19 extern const char kInstallDirectoryName[]; | 21 extern const char kInstallDirectoryName[]; |
| 20 | 22 |
| 21 // The name of the file that contains the current version of an installed | 23 // The name of the file that contains the current version of an installed |
| 22 // extension. | 24 // extension. |
| 23 extern const char kCurrentVersionFileName[]; | 25 extern const char kCurrentVersionFileName[]; |
| 24 | 26 |
| 25 // Move source_dir to dest_dir (it will actually be named dest_dir, not inside | 27 // Move source_dir to dest_dir (it will actually be named dest_dir, not inside |
| 26 // dest_dir). If the parent path doesn't exixt, create it. If something else is | 28 // dest_dir). If the parent path doesn't exixt, create it. If something else is |
| 27 // already there, remove it. | 29 // already there, remove it. |
| 28 bool MoveDirSafely(const FilePath& source_dir, const FilePath& dest_dir); | 30 bool MoveDirSafely(const FilePath& source_dir, const FilePath& dest_dir); |
| 29 | 31 |
| 30 // Updates the Current Version file inside the installed extension. | 32 // Updates the Current Version file inside the installed extension. |
| 31 bool SetCurrentVersion(const FilePath& dest_dir, const std::string& version, | 33 bool SetCurrentVersion(const FilePath& dest_dir, |
| 34 const std::string& version, |
| 32 std::string* error); | 35 std::string* error); |
| 33 | 36 |
| 34 // Reads the Current Version file. | 37 // Reads the Current Version file. |
| 35 bool ReadCurrentVersion(const FilePath& dir, std::string* version_string); | 38 bool ReadCurrentVersion(const FilePath& dir, std::string* version_string); |
| 36 | 39 |
| 37 // Determine what type of install it is (new, upgrade, overinstall, downgrade) | 40 // Determine what type of install it is (new, upgrade, overinstall, downgrade) |
| 38 // given the current version and a newly installing version. |extensions_dir| is | 41 // given the current version and a newly installing version. |extensions_dir| is |
| 39 // the root directory containing all extensions in the user profile. | 42 // the root directory containing all extensions in the user profile. |
| 40 // |extension_id| and |current_version_str| are the id and version of the | 43 // |extension_id| and |current_version_str| are the id and version of the |
| 41 // extension contained in |src_dir|, if any. | 44 // extension contained in |src_dir|, if any. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 // | 62 // |
| 60 // NOTE: |src_dir| is not actually copied in the case of downgrades or | 63 // NOTE: |src_dir| is not actually copied in the case of downgrades or |
| 61 // overinstall of previous verisons of the extension. In that case, the function | 64 // overinstall of previous verisons of the extension. In that case, the function |
| 62 // returns true and install_type is populated. | 65 // returns true and install_type is populated. |
| 63 bool InstallExtension(const FilePath& src_dir, | 66 bool InstallExtension(const FilePath& src_dir, |
| 64 const FilePath& version_dir, | 67 const FilePath& version_dir, |
| 65 std::string* error); | 68 std::string* error); |
| 66 | 69 |
| 67 // Loads and validates an extension from the specified directory. Returns NULL | 70 // Loads and validates an extension from the specified directory. Returns NULL |
| 68 // on failure, with a description of the error in |error|. | 71 // on failure, with a description of the error in |error|. |
| 69 Extension* LoadExtension(const FilePath& extension_root, bool require_key, | 72 Extension* LoadExtension(const FilePath& extension_root, |
| 73 bool require_key, |
| 70 std::string* error); | 74 std::string* error); |
| 71 | 75 |
| 72 // Returns true if the given extension object is valid and consistent. | 76 // Returns true if the given extension object is valid and consistent. |
| 73 // Otherwise, a description of the error is returned in |error|. | 77 // Otherwise, a description of the error is returned in |error|. |
| 74 bool ValidateExtension(Extension* extension, std::string* error); | 78 bool ValidateExtension(Extension* extension, std::string* error); |
| 75 | 79 |
| 76 // Uninstalls the extension |id| from the install directory |extensions_dir|. | 80 // Uninstalls the extension |id| from the install directory |extensions_dir|. |
| 77 void UninstallExtension(const std::string& id, const FilePath& extensions_dir); | 81 void UninstallExtension(const std::string& id, const FilePath& extensions_dir); |
| 78 | 82 |
| 79 // Clean up directories that aren't valid extensions from the install directory. | 83 // Clean up directories that aren't valid extensions from the install directory. |
| 80 // TODO(aa): Also consider passing in a list of known current extensions and | 84 // TODO(aa): Also consider passing in a list of known current extensions and |
| 81 // removing others? | 85 // removing others? |
| 82 void GarbageCollectExtensions(const FilePath& extensions_dir, | 86 void GarbageCollectExtensions(const FilePath& extensions_dir, |
| 83 const std::set<std::string>& installed_ids); | 87 const std::set<std::string>& installed_ids); |
| 84 | 88 |
| 89 // Loads locale information if _locales folder is present. |
| 90 // Returns message bundle if there were no errors. If _locales folder is not |
| 91 // present it returns NULL with empty error string. |
| 92 // Loading failed only if function returns NULL and error is not empty. |
| 93 ExtensionMessageBundle* LoadLocaleInfo(const FilePath& extension_path, |
| 94 const DictionaryValue& manifest, |
| 95 std::string* error); |
| 96 |
| 85 // We need to reserve the namespace of entries that start with "_" for future | 97 // We need to reserve the namespace of entries that start with "_" for future |
| 86 // use by Chrome. | 98 // use by Chrome. |
| 87 // If any files or directories are found using "_" prefix and are not on | 99 // If any files or directories are found using "_" prefix and are not on |
| 88 // reserved list we return false, and set error message. | 100 // reserved list we return false, and set error message. |
| 89 bool CheckForIllegalFilenames(const FilePath& extension_path, | 101 bool CheckForIllegalFilenames(const FilePath& extension_path, |
| 90 std::string* error); | 102 std::string* error); |
| 91 | 103 |
| 92 } // extension_file_util | 104 } // extension_file_util |
| 93 | 105 |
| 94 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 106 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
| OLD | NEW |