| OLD | NEW |
| 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 #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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/common/extensions/message_bundle.h" | 13 #include "chrome/common/extensions/message_bundle.h" |
| 13 #include "extensions/common/manifest.h" | 14 #include "extensions/common/manifest.h" |
| 14 | 15 |
| 15 class ExtensionIconSet; | 16 class ExtensionIconSet; |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class DictionaryValue; | 19 class DictionaryValue; |
| 19 class FilePath; | 20 class FilePath; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 class Extension; | 24 class Extension; |
| 24 class MessageBundle; | 25 class MessageBundle; |
| 25 struct InstallWarning; | 26 struct InstallWarning; |
| 26 } | 27 } |
| 27 | 28 |
| 28 // Utilities for manipulating the on-disk storage of extensions. | 29 // Utilities for manipulating the on-disk storage of extensions. |
| 29 namespace extension_file_util { | 30 namespace extension_file_util { |
| 30 | 31 |
| 32 extern const base::FilePath::CharType kTempDirectoryName[]; |
| 33 |
| 31 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. | 34 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. |
| 32 // The destination directory is returned on success, or empty path is returned | 35 // The destination directory is returned on success, or empty path is returned |
| 33 // on failure. | 36 // on failure. |
| 34 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, | 37 base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir, |
| 35 const std::string& id, | 38 const std::string& id, |
| 36 const std::string& version, | 39 const std::string& version, |
| 37 const base::FilePath& extensions_dir); | 40 const base::FilePath& extensions_dir); |
| 38 | 41 |
| 39 // Removes all versions of the extension with |id| from |extensions_dir|. | 42 // Removes all versions of the extension with |id| from |extensions_dir|. |
| 40 void UninstallExtension(const base::FilePath& extensions_dir, | 43 void UninstallExtension(const base::FilePath& extensions_dir, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Returns a list of paths (relative to the extension dir) for images that | 87 // Returns a list of paths (relative to the extension dir) for images that |
| 85 // the browser might load (like themes and page action icons) for the given | 88 // the browser might load (like themes and page action icons) for the given |
| 86 // extension. | 89 // extension. |
| 87 std::set<base::FilePath> GetBrowserImagePaths( | 90 std::set<base::FilePath> GetBrowserImagePaths( |
| 88 const extensions::Extension* extension); | 91 const extensions::Extension* extension); |
| 89 | 92 |
| 90 // Returns a list of files that contain private keys inside |extension_dir|. | 93 // Returns a list of files that contain private keys inside |extension_dir|. |
| 91 std::vector<base::FilePath> FindPrivateKeyFiles( | 94 std::vector<base::FilePath> FindPrivateKeyFiles( |
| 92 const base::FilePath& extension_dir); | 95 const base::FilePath& extension_dir); |
| 93 | 96 |
| 94 // Cleans up the extension install directory. It can end up with garbage in it | |
| 95 // if extensions can't initially be removed when they are uninstalled (eg if a | |
| 96 // file is in use). | |
| 97 // | |
| 98 // |extensions_dir| is the install directory to look in. |extension_paths| is a | |
| 99 // map from extension id to full installation path. | |
| 100 // | |
| 101 // Obsolete version directories are removed, as are directories that aren't | |
| 102 // found in |extension_paths|. | |
| 103 // | |
| 104 // The "Temp" directory that is used during extension installation only gets | |
| 105 // removed if |clean_temp_dir| is true. | |
| 106 void GarbageCollectExtensions( | |
| 107 const base::FilePath& extensions_dir, | |
| 108 const std::multimap<std::string, base::FilePath>& extension_paths, | |
| 109 bool clean_temp_dir); | |
| 110 | |
| 111 // Loads extension message catalogs and returns message bundle. | 97 // Loads extension message catalogs and returns message bundle. |
| 112 // Returns NULL on error, or if extension is not localized. | 98 // Returns NULL on error, or if extension is not localized. |
| 113 extensions::MessageBundle* LoadMessageBundle( | 99 extensions::MessageBundle* LoadMessageBundle( |
| 114 const base::FilePath& extension_path, | 100 const base::FilePath& extension_path, |
| 115 const std::string& default_locale, | 101 const std::string& default_locale, |
| 116 std::string* error); | 102 std::string* error); |
| 117 | 103 |
| 118 // Loads the extension message bundle substitution map. Contains at least | 104 // Loads the extension message bundle substitution map. Contains at least |
| 119 // extension_id item. | 105 // extension_id item. |
| 120 extensions::MessageBundle::SubstitutionMap* LoadMessageBundleSubstitutionMap( | 106 extensions::MessageBundle::SubstitutionMap* LoadMessageBundleSubstitutionMap( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 base::FilePath GetInstallTempDir(const base::FilePath& extensions_dir); | 123 base::FilePath GetInstallTempDir(const base::FilePath& extensions_dir); |
| 138 | 124 |
| 139 // Helper function to delete files. This is used to avoid ugly casts which | 125 // Helper function to delete files. This is used to avoid ugly casts which |
| 140 // would be necessary with PostMessage since base::Delete is overloaded. | 126 // would be necessary with PostMessage since base::Delete is overloaded. |
| 141 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. | 127 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. |
| 142 void DeleteFile(const base::FilePath& path, bool recursive); | 128 void DeleteFile(const base::FilePath& path, bool recursive); |
| 143 | 129 |
| 144 } // namespace extension_file_util | 130 } // namespace extension_file_util |
| 145 | 131 |
| 146 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 132 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
| OLD | NEW |