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 #include "chrome/browser/component_updater/component_unpacker.h" | 5 #include "chrome/browser/component_updater/component_unpacker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 std::vector<uint8> public_key_; | 85 std::vector<uint8> public_key_; |
86 }; | 86 }; |
87 | 87 |
88 // Deserialize the CRX manifest. The top level must be a dictionary. | 88 // Deserialize the CRX manifest. The top level must be a dictionary. |
89 // TODO(cpu): add a specific attribute check to a component json that the | 89 // TODO(cpu): add a specific attribute check to a component json that the |
90 // extension unpacker will reject, so that a component cannot be installed | 90 // extension unpacker will reject, so that a component cannot be installed |
91 // as an extension. | 91 // as an extension. |
92 base::DictionaryValue* ReadManifest(const base::FilePath& unpack_path) { | 92 base::DictionaryValue* ReadManifest(const base::FilePath& unpack_path) { |
93 base::FilePath manifest = | 93 base::FilePath manifest = |
94 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); | 94 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); |
95 if (!file_util::PathExists(manifest)) | 95 if (!base::PathExists(manifest)) |
96 return NULL; | 96 return NULL; |
97 JSONFileValueSerializer serializer(manifest); | 97 JSONFileValueSerializer serializer(manifest); |
98 std::string error; | 98 std::string error; |
99 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); | 99 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); |
100 if (!root.get()) | 100 if (!root.get()) |
101 return NULL; | 101 return NULL; |
102 if (!root->IsType(base::Value::TYPE_DICTIONARY)) | 102 if (!root->IsType(base::Value::TYPE_DICTIONARY)) |
103 return NULL; | 103 return NULL; |
104 return static_cast<base::DictionaryValue*>(root.release()); | 104 return static_cast<base::DictionaryValue*>(root.release()); |
105 } | 105 } |
106 | 106 |
107 // Deletes a path if it exists, and then creates a directory there. | 107 // Deletes a path if it exists, and then creates a directory there. |
108 // Returns true if and only if these operations were successful. | 108 // Returns true if and only if these operations were successful. |
109 // This method doesn't take any special steps to prevent files from | 109 // This method doesn't take any special steps to prevent files from |
110 // being inserted into the target directory by another process or thread. | 110 // being inserted into the target directory by another process or thread. |
111 bool MakeEmptyDirectory(const base::FilePath& path) { | 111 bool MakeEmptyDirectory(const base::FilePath& path) { |
112 if (file_util::PathExists(path)) { | 112 if (base::PathExists(path)) { |
113 if (!base::Delete(path, true)) | 113 if (!base::Delete(path, true)) |
114 return false; | 114 return false; |
115 } | 115 } |
116 if (!file_util::CreateDirectory(path)) | 116 if (!file_util::CreateDirectory(path)) |
117 return false; | 117 return false; |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 } // namespace. | 121 } // namespace. |
122 | 122 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return; | 218 return; |
219 } | 219 } |
220 // Installation successful. The directory is not our concern now. | 220 // Installation successful. The directory is not our concern now. |
221 unpack_path_.clear(); | 221 unpack_path_.clear(); |
222 } | 222 } |
223 | 223 |
224 ComponentUnpacker::~ComponentUnpacker() { | 224 ComponentUnpacker::~ComponentUnpacker() { |
225 if (!unpack_path_.empty()) | 225 if (!unpack_path_.empty()) |
226 base::Delete(unpack_path_, true); | 226 base::Delete(unpack_path_, true); |
227 } | 227 } |
OLD | NEW |