OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/update_client/component_patcher_operation.h" | 5 #include "components/update_client/component_patcher_operation.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 const char kOp[] = "op"; | 38 const char kOp[] = "op"; |
39 const char kBsdiff[] = "bsdiff"; | 39 const char kBsdiff[] = "bsdiff"; |
40 const char kCourgette[] = "courgette"; | 40 const char kCourgette[] = "courgette"; |
41 const char kInput[] = "input"; | 41 const char kInput[] = "input"; |
42 const char kPatch[] = "patch"; | 42 const char kPatch[] = "patch"; |
43 | 43 |
44 DeltaUpdateOp* CreateDeltaUpdateOp( | 44 DeltaUpdateOp* CreateDeltaUpdateOp( |
45 const std::string& operation, | 45 const std::string& operation, |
46 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher) { | 46 const scoped_refptr<OutOfProcessPatcher>& out_of_process_patcher) { |
47 if (operation == "copy") { | 47 if (operation == "copy") { |
48 return new DeltaUpdateOpCopy(); | 48 return new DeltaUpdateOpCopy(); |
49 } else if (operation == "create") { | 49 } else if (operation == "create") { |
50 return new DeltaUpdateOpCreate(); | 50 return new DeltaUpdateOpCreate(); |
51 } else if (operation == "bsdiff" || operation == "courgette") { | 51 } else if (operation == "bsdiff" || operation == "courgette") { |
52 return new DeltaUpdateOpPatch(operation, out_of_process_patcher); | 52 return new DeltaUpdateOpPatch(operation, out_of_process_patcher); |
53 } | 53 } |
54 return NULL; | 54 return NULL; |
55 } | 55 } |
56 | 56 |
57 DeltaUpdateOp::DeltaUpdateOp() { | 57 DeltaUpdateOp::DeltaUpdateOp() { |
58 } | 58 } |
59 | 59 |
60 DeltaUpdateOp::~DeltaUpdateOp() { | 60 DeltaUpdateOp::~DeltaUpdateOp() { |
61 } | 61 } |
62 | 62 |
63 void DeltaUpdateOp::Run(const base::DictionaryValue* command_args, | 63 void DeltaUpdateOp::Run( |
64 const base::FilePath& input_dir, | 64 const base::DictionaryValue* command_args, |
65 const base::FilePath& unpack_dir, | 65 const base::FilePath& input_dir, |
66 ComponentInstaller* installer, | 66 const base::FilePath& unpack_dir, |
67 const ComponentUnpacker::Callback& callback, | 67 const scoped_refptr<ComponentInstaller>& installer, |
68 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 68 const ComponentUnpacker::Callback& callback, |
| 69 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
69 callback_ = callback; | 70 callback_ = callback; |
70 task_runner_ = task_runner; | 71 task_runner_ = task_runner; |
71 std::string output_rel_path; | 72 std::string output_rel_path; |
72 if (!command_args->GetString(kOutput, &output_rel_path) || | 73 if (!command_args->GetString(kOutput, &output_rel_path) || |
73 !command_args->GetString(kSha256, &output_sha256_)) { | 74 !command_args->GetString(kSha256, &output_sha256_)) { |
74 DoneRunning(ComponentUnpacker::kDeltaBadCommands, 0); | 75 DoneRunning(ComponentUnpacker::kDeltaBadCommands, 0); |
75 return; | 76 return; |
76 } | 77 } |
77 | 78 |
78 output_abs_path_ = | 79 output_abs_path_ = |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 134 |
134 DeltaUpdateOpCopy::DeltaUpdateOpCopy() { | 135 DeltaUpdateOpCopy::DeltaUpdateOpCopy() { |
135 } | 136 } |
136 | 137 |
137 DeltaUpdateOpCopy::~DeltaUpdateOpCopy() { | 138 DeltaUpdateOpCopy::~DeltaUpdateOpCopy() { |
138 } | 139 } |
139 | 140 |
140 ComponentUnpacker::Error DeltaUpdateOpCopy::DoParseArguments( | 141 ComponentUnpacker::Error DeltaUpdateOpCopy::DoParseArguments( |
141 const base::DictionaryValue* command_args, | 142 const base::DictionaryValue* command_args, |
142 const base::FilePath& input_dir, | 143 const base::FilePath& input_dir, |
143 ComponentInstaller* installer) { | 144 const scoped_refptr<ComponentInstaller>& installer) { |
144 std::string input_rel_path; | 145 std::string input_rel_path; |
145 if (!command_args->GetString(kInput, &input_rel_path)) | 146 if (!command_args->GetString(kInput, &input_rel_path)) |
146 return ComponentUnpacker::kDeltaBadCommands; | 147 return ComponentUnpacker::kDeltaBadCommands; |
147 | 148 |
148 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) | 149 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) |
149 return ComponentUnpacker::kDeltaMissingExistingFile; | 150 return ComponentUnpacker::kDeltaMissingExistingFile; |
150 | 151 |
151 return ComponentUnpacker::kNone; | 152 return ComponentUnpacker::kNone; |
152 } | 153 } |
153 | 154 |
154 void DeltaUpdateOpCopy::DoRun(const ComponentUnpacker::Callback& callback) { | 155 void DeltaUpdateOpCopy::DoRun(const ComponentUnpacker::Callback& callback) { |
155 if (!base::CopyFile(input_abs_path_, output_abs_path_)) | 156 if (!base::CopyFile(input_abs_path_, output_abs_path_)) |
156 callback.Run(ComponentUnpacker::kDeltaOperationFailure, 0); | 157 callback.Run(ComponentUnpacker::kDeltaOperationFailure, 0); |
157 else | 158 else |
158 callback.Run(ComponentUnpacker::kNone, 0); | 159 callback.Run(ComponentUnpacker::kNone, 0); |
159 } | 160 } |
160 | 161 |
161 DeltaUpdateOpCreate::DeltaUpdateOpCreate() { | 162 DeltaUpdateOpCreate::DeltaUpdateOpCreate() { |
162 } | 163 } |
163 | 164 |
164 DeltaUpdateOpCreate::~DeltaUpdateOpCreate() { | 165 DeltaUpdateOpCreate::~DeltaUpdateOpCreate() { |
165 } | 166 } |
166 | 167 |
167 ComponentUnpacker::Error DeltaUpdateOpCreate::DoParseArguments( | 168 ComponentUnpacker::Error DeltaUpdateOpCreate::DoParseArguments( |
168 const base::DictionaryValue* command_args, | 169 const base::DictionaryValue* command_args, |
169 const base::FilePath& input_dir, | 170 const base::FilePath& input_dir, |
170 ComponentInstaller* installer) { | 171 const scoped_refptr<ComponentInstaller>& installer) { |
171 std::string patch_rel_path; | 172 std::string patch_rel_path; |
172 if (!command_args->GetString(kPatch, &patch_rel_path)) | 173 if (!command_args->GetString(kPatch, &patch_rel_path)) |
173 return ComponentUnpacker::kDeltaBadCommands; | 174 return ComponentUnpacker::kDeltaBadCommands; |
174 | 175 |
175 patch_abs_path_ = | 176 patch_abs_path_ = |
176 input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path)); | 177 input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path)); |
177 | 178 |
178 return ComponentUnpacker::kNone; | 179 return ComponentUnpacker::kNone; |
179 } | 180 } |
180 | 181 |
(...skipping 10 matching lines...) Expand all Loading... |
191 : operation_(operation), out_of_process_patcher_(out_of_process_patcher) { | 192 : operation_(operation), out_of_process_patcher_(out_of_process_patcher) { |
192 DCHECK(operation == kBsdiff || operation == kCourgette); | 193 DCHECK(operation == kBsdiff || operation == kCourgette); |
193 } | 194 } |
194 | 195 |
195 DeltaUpdateOpPatch::~DeltaUpdateOpPatch() { | 196 DeltaUpdateOpPatch::~DeltaUpdateOpPatch() { |
196 } | 197 } |
197 | 198 |
198 ComponentUnpacker::Error DeltaUpdateOpPatch::DoParseArguments( | 199 ComponentUnpacker::Error DeltaUpdateOpPatch::DoParseArguments( |
199 const base::DictionaryValue* command_args, | 200 const base::DictionaryValue* command_args, |
200 const base::FilePath& input_dir, | 201 const base::FilePath& input_dir, |
201 ComponentInstaller* installer) { | 202 const scoped_refptr<ComponentInstaller>& installer) { |
202 std::string patch_rel_path; | 203 std::string patch_rel_path; |
203 std::string input_rel_path; | 204 std::string input_rel_path; |
204 if (!command_args->GetString(kPatch, &patch_rel_path) || | 205 if (!command_args->GetString(kPatch, &patch_rel_path) || |
205 !command_args->GetString(kInput, &input_rel_path)) | 206 !command_args->GetString(kInput, &input_rel_path)) |
206 return ComponentUnpacker::kDeltaBadCommands; | 207 return ComponentUnpacker::kDeltaBadCommands; |
207 | 208 |
208 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) | 209 if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_)) |
209 return ComponentUnpacker::kDeltaMissingExistingFile; | 210 return ComponentUnpacker::kDeltaMissingExistingFile; |
210 | 211 |
211 patch_abs_path_ = | 212 patch_abs_path_ = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } else { | 254 } else { |
254 callback.Run(ComponentUnpacker::kDeltaOperationFailure, | 255 callback.Run(ComponentUnpacker::kDeltaOperationFailure, |
255 result + kCourgetteErrorOffset); | 256 result + kCourgetteErrorOffset); |
256 } | 257 } |
257 } else { | 258 } else { |
258 NOTREACHED(); | 259 NOTREACHED(); |
259 } | 260 } |
260 } | 261 } |
261 | 262 |
262 } // namespace update_client | 263 } // namespace update_client |
OLD | NEW |