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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/extensions/extension_message_bundle.h" | 13 #include "chrome/common/extensions/extension_message_bundle.h" |
14 | 14 |
15 class Extension; | |
16 class ExtensionMessageBundle; | 15 class ExtensionMessageBundle; |
17 class FilePath; | 16 class FilePath; |
18 class GURL; | 17 class GURL; |
19 namespace base { | 18 namespace base { |
20 class DictionaryValue; | 19 class DictionaryValue; |
21 } | 20 } |
22 | 21 |
23 // Utilities for manipulating the on-disk storage of extensions. | 22 // Utilities for manipulating the on-disk storage of extensions. |
24 namespace extension_file_util { | 23 namespace extension_file_util { |
25 | 24 |
26 // The name of the directory inside the profile that we store installed | 25 // The name of the directory inside the profile that we store installed |
27 // extension in. | 26 // extension in. |
28 extern const char kInstallDirectoryName[]; | 27 extern const char kInstallDirectoryName[]; |
29 | 28 |
30 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. | 29 // Copies |unpacked_source_dir| into the right location under |extensions_dir|. |
31 // The destination directory is returned on success, or empty path is returned | 30 // The destination directory is returned on success, or empty path is returned |
32 // on failure. | 31 // on failure. |
33 FilePath InstallExtension(const FilePath& unpacked_source_dir, | 32 FilePath InstallExtension(const FilePath& unpacked_source_dir, |
34 const std::string& id, | 33 const std::string& id, |
35 const std::string& version, | 34 const std::string& version, |
36 const FilePath& extensions_dir); | 35 const FilePath& extensions_dir); |
37 | 36 |
38 // Removes all versions of the extension with |id| from |extensions_dir|. | 37 // Removes all versions of the extension with |id| from |extensions_dir|. |
39 void UninstallExtension(const FilePath& extensions_dir, | 38 void UninstallExtension(const FilePath& extensions_dir, |
40 const std::string& id); | 39 const std::string& id); |
41 | 40 |
42 // Loads and validates an extension from the specified directory. Returns NULL | 41 // Loads and validates an extension from the specified directory. Returns NULL |
43 // on failure, with a description of the error in |error|. | 42 // on failure, with a description of the error in |error|. |
44 scoped_refptr<Extension> LoadExtension(const FilePath& extension_root, | 43 scoped_refptr<extensions::Extension> LoadExtension( |
45 Extension::Location location, | 44 const FilePath& extension_root, |
46 int flags, | 45 extensions::Extension::Location location, |
47 std::string* error); | 46 int flags, |
| 47 std::string* error); |
48 | 48 |
49 // The same as LoadExtension except use the provided |extension_id|. | 49 // The same as LoadExtension except use the provided |extension_id|. |
50 scoped_refptr<Extension> LoadExtension(const FilePath& extension_root, | 50 scoped_refptr<extensions::Extension> LoadExtension( |
51 const std::string& extension_id, | 51 const FilePath& extension_root, |
52 Extension::Location location, | 52 const std::string& extension_id, |
53 int flags, | 53 extensions::Extension::Location location, |
54 std::string* error); | 54 int flags, |
| 55 std::string* error); |
55 | 56 |
56 // Loads an extension manifest from the specified directory. Returns NULL | 57 // Loads an extension manifest from the specified directory. Returns NULL |
57 // on failure, with a description of the error in |error|. | 58 // on failure, with a description of the error in |error|. |
58 base::DictionaryValue* LoadManifest(const FilePath& extension_root, | 59 base::DictionaryValue* LoadManifest(const FilePath& extension_root, |
59 std::string* error); | 60 std::string* error); |
60 | 61 |
61 // Returns true if the given extension object is valid and consistent. | 62 // Returns true if the given extension object is valid and consistent. |
62 // Otherwise, a description of the error is returned in |error|. | 63 // Otherwise, a description of the error is returned in |error|. |
63 bool ValidateExtension(const Extension* extension, std::string* error); | 64 bool ValidateExtension(const extensions::Extension* extension, |
| 65 std::string* error); |
64 | 66 |
65 // Cleans up the extension install directory. It can end up with garbage in it | 67 // Cleans up the extension install directory. It can end up with garbage in it |
66 // if extensions can't initially be removed when they are uninstalled (eg if a | 68 // if extensions can't initially be removed when they are uninstalled (eg if a |
67 // file is in use). | 69 // file is in use). |
68 // | 70 // |
69 // |extensions_dir| is the install directory to look in. |extension_paths| is a | 71 // |extensions_dir| is the install directory to look in. |extension_paths| is a |
70 // map from extension id to full installation path. | 72 // map from extension id to full installation path. |
71 // | 73 // |
72 // Obsolete version directories are removed, as are directories that aren't | 74 // Obsolete version directories are removed, as are directories that aren't |
73 // found in |extension_paths|. | 75 // found in |extension_paths|. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 FilePath GetUserDataTempDir(); | 113 FilePath GetUserDataTempDir(); |
112 | 114 |
113 // Helper function to delete files. This is used to avoid ugly casts which | 115 // Helper function to delete files. This is used to avoid ugly casts which |
114 // would be necessary with PostMessage since file_util::Delete is overloaded. | 116 // would be necessary with PostMessage since file_util::Delete is overloaded. |
115 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. | 117 // TODO(skerner): Make a version of Delete that is not overloaded in file_util. |
116 void DeleteFile(const FilePath& path, bool recursive); | 118 void DeleteFile(const FilePath& path, bool recursive); |
117 | 119 |
118 } // namespace extension_file_util | 120 } // namespace extension_file_util |
119 | 121 |
120 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ | 122 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_FILE_UTIL_H_ |
OLD | NEW |