| 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/component_updater/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" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "components/component_updater/component_patcher.h" | 15 #include "components/update_client/component_patcher.h" |
| 16 #include "components/component_updater/component_updater_service.h" | 16 #include "components/update_client/update_client.h" |
| 17 #include "courgette/courgette.h" | 17 #include "courgette/courgette.h" |
| 18 #include "courgette/third_party/bsdiff.h" | 18 #include "courgette/third_party/bsdiff.h" |
| 19 #include "crypto/secure_hash.h" | 19 #include "crypto/secure_hash.h" |
| 20 #include "crypto/sha2.h" | 20 #include "crypto/sha2.h" |
| 21 #include "crypto/signature_verifier.h" | 21 #include "crypto/signature_verifier.h" |
| 22 | 22 |
| 23 using crypto::SecureHash; | 23 using crypto::SecureHash; |
| 24 | 24 |
| 25 namespace component_updater { | 25 namespace update_client { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const char kOutput[] = "output"; | 29 const char kOutput[] = "output"; |
| 30 const char kSha256[] = "sha256"; | 30 const char kSha256[] = "sha256"; |
| 31 | 31 |
| 32 // The integer offset disambiguates between overlapping error ranges. | 32 // The integer offset disambiguates between overlapping error ranges. |
| 33 const int kCourgetteErrorOffset = 300; | 33 const int kCourgetteErrorOffset = 300; |
| 34 const int kBsdiffErrorOffset = 600; | 34 const int kBsdiffErrorOffset = 600; |
| 35 | 35 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 patch_abs_path_ = | 211 patch_abs_path_ = |
| 212 input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path)); | 212 input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path)); |
| 213 | 213 |
| 214 return ComponentUnpacker::kNone; | 214 return ComponentUnpacker::kNone; |
| 215 } | 215 } |
| 216 | 216 |
| 217 void DeltaUpdateOpPatch::DoRun(const ComponentUnpacker::Callback& callback) { | 217 void DeltaUpdateOpPatch::DoRun(const ComponentUnpacker::Callback& callback) { |
| 218 if (out_of_process_patcher_.get()) { | 218 if (out_of_process_patcher_.get()) { |
| 219 out_of_process_patcher_->Patch( | 219 out_of_process_patcher_->Patch( |
| 220 operation_, | 220 operation_, GetTaskRunner(), input_abs_path_, patch_abs_path_, |
| 221 GetTaskRunner(), | |
| 222 input_abs_path_, | |
| 223 patch_abs_path_, | |
| 224 output_abs_path_, | 221 output_abs_path_, |
| 225 base::Bind(&DeltaUpdateOpPatch::DonePatching, this, callback)); | 222 base::Bind(&DeltaUpdateOpPatch::DonePatching, this, callback)); |
| 226 return; | 223 return; |
| 227 } | 224 } |
| 228 | 225 |
| 229 if (operation_ == kBsdiff) { | 226 if (operation_ == kBsdiff) { |
| 230 DonePatching(callback, | 227 DonePatching(callback, |
| 231 courgette::ApplyBinaryPatch( | 228 courgette::ApplyBinaryPatch(input_abs_path_, patch_abs_path_, |
| 232 input_abs_path_, patch_abs_path_, output_abs_path_)); | 229 output_abs_path_)); |
| 233 } else if (operation_ == kCourgette) { | 230 } else if (operation_ == kCourgette) { |
| 234 DonePatching( | 231 DonePatching(callback, courgette::ApplyEnsemblePatch( |
| 235 callback, | 232 input_abs_path_.value().c_str(), |
| 236 courgette::ApplyEnsemblePatch(input_abs_path_.value().c_str(), | 233 patch_abs_path_.value().c_str(), |
| 237 patch_abs_path_.value().c_str(), | 234 output_abs_path_.value().c_str())); |
| 238 output_abs_path_.value().c_str())); | |
| 239 } else { | 235 } else { |
| 240 NOTREACHED(); | 236 NOTREACHED(); |
| 241 } | 237 } |
| 242 } | 238 } |
| 243 | 239 |
| 244 void DeltaUpdateOpPatch::DonePatching( | 240 void DeltaUpdateOpPatch::DonePatching( |
| 245 const ComponentUnpacker::Callback& callback, | 241 const ComponentUnpacker::Callback& callback, |
| 246 int result) { | 242 int result) { |
| 247 if (operation_ == kBsdiff) { | 243 if (operation_ == kBsdiff) { |
| 248 if (result == courgette::OK) { | 244 if (result == courgette::OK) { |
| 249 callback.Run(ComponentUnpacker::kNone, 0); | 245 callback.Run(ComponentUnpacker::kNone, 0); |
| 250 } else { | 246 } else { |
| 251 callback.Run(ComponentUnpacker::kDeltaOperationFailure, | 247 callback.Run(ComponentUnpacker::kDeltaOperationFailure, |
| 252 result + kBsdiffErrorOffset); | 248 result + kBsdiffErrorOffset); |
| 253 } | 249 } |
| 254 } else if (operation_ == kCourgette) { | 250 } else if (operation_ == kCourgette) { |
| 255 if (result == courgette::C_OK) { | 251 if (result == courgette::C_OK) { |
| 256 callback.Run(ComponentUnpacker::kNone, 0); | 252 callback.Run(ComponentUnpacker::kNone, 0); |
| 257 } else { | 253 } else { |
| 258 callback.Run(ComponentUnpacker::kDeltaOperationFailure, | 254 callback.Run(ComponentUnpacker::kDeltaOperationFailure, |
| 259 result + kCourgetteErrorOffset); | 255 result + kCourgetteErrorOffset); |
| 260 } | 256 } |
| 261 } else { | 257 } else { |
| 262 NOTREACHED(); | 258 NOTREACHED(); |
| 263 } | 259 } |
| 264 } | 260 } |
| 265 | 261 |
| 266 } // namespace component_updater | 262 } // namespace update_client |
| OLD | NEW |