file_patcher_impl.cc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/services/patch/file_patcher_impl.h"
  5. #include <utility>
  6. #include "base/callback.h"
  7. #include "base/notreached.h"
  8. #include "components/update_client/buildflags.h"
  9. #include "courgette/courgette.h"
  10. #include "courgette/third_party/bsdiff/bsdiff.h"
  11. #if BUILDFLAG(ENABLE_PUFFIN_PATCHES)
  12. // TODO(crbug.com/1349060) once Puffin patches are fully implemented,
  13. // we should remove this #if
  14. #include "third_party/puffin/puffin/src/include/puffin/puffpatch.h"
  15. #endif
  16. namespace patch {
  17. FilePatcherImpl::FilePatcherImpl() = default;
  18. FilePatcherImpl::FilePatcherImpl(
  19. mojo::PendingReceiver<mojom::FilePatcher> receiver)
  20. : receiver_(this, std::move(receiver)) {}
  21. FilePatcherImpl::~FilePatcherImpl() = default;
  22. // TODO(crbug.com/1349158): Remove this function once PatchFilePuffPatch is
  23. // implemented as this becomes obsolete.
  24. void FilePatcherImpl::PatchFileBsdiff(base::File input_file,
  25. base::File patch_file,
  26. base::File output_file,
  27. PatchFileBsdiffCallback callback) {
  28. DCHECK(input_file.IsValid());
  29. DCHECK(patch_file.IsValid());
  30. DCHECK(output_file.IsValid());
  31. const int patch_result_status = bsdiff::ApplyBinaryPatch(
  32. std::move(input_file), std::move(patch_file), std::move(output_file));
  33. std::move(callback).Run(patch_result_status);
  34. }
  35. // TODO(crbug.com/1349158): Remove this function once PatchFilePuffPatch is
  36. // implemented as this becomes obsolete.
  37. void FilePatcherImpl::PatchFileCourgette(base::File input_file,
  38. base::File patch_file,
  39. base::File output_file,
  40. PatchFileCourgetteCallback callback) {
  41. DCHECK(input_file.IsValid());
  42. DCHECK(patch_file.IsValid());
  43. DCHECK(output_file.IsValid());
  44. const int patch_result_status = courgette::ApplyEnsemblePatch(
  45. std::move(input_file), std::move(patch_file), std::move(output_file));
  46. std::move(callback).Run(patch_result_status);
  47. }
  48. void FilePatcherImpl::PatchFilePuffPatch(base::File input_file,
  49. base::File patch_file,
  50. base::File output_file,
  51. PatchFilePuffPatchCallback callback) {
  52. #if BUILDFLAG(ENABLE_PUFFIN_PATCHES)
  53. // TODO(crbug.com/1349060) once Puffin patches are fully implemented,
  54. // we should remove this #if.
  55. const int patch_result_status = puffin::ApplyPuffPatch(
  56. std::move(input_file), std::move(patch_file), std::move(output_file));
  57. std::move(callback).Run(patch_result_status);
  58. #else
  59. NOTREACHED();
  60. #endif
  61. }
  62. } // namespace patch