patch_impl.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2019 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/update_client/patch/patch_impl.h"
  5. #include "base/callback.h"
  6. #include "base/files/file_path.h"
  7. #include "base/notreached.h"
  8. #include "components/services/patch/public/cpp/patch.h"
  9. #include "components/update_client/buildflags.h"
  10. #include "components/update_client/component_patcher_operation.h"
  11. namespace update_client {
  12. namespace {
  13. class PatcherImpl : public Patcher {
  14. public:
  15. explicit PatcherImpl(PatchChromiumFactory::Callback callback)
  16. : callback_(std::move(callback)) {}
  17. void PatchBsdiff(const base::FilePath& old_file,
  18. const base::FilePath& patch_file,
  19. const base::FilePath& destination,
  20. PatchCompleteCallback callback) const override {
  21. patch::Patch(callback_.Run(), update_client::kBsdiff, old_file, patch_file,
  22. destination, std::move(callback));
  23. }
  24. void PatchCourgette(const base::FilePath& old_file,
  25. const base::FilePath& patch_file,
  26. const base::FilePath& destination,
  27. PatchCompleteCallback callback) const override {
  28. patch::Patch(callback_.Run(), update_client::kCourgette, old_file,
  29. patch_file, destination, std::move(callback));
  30. }
  31. void PatchPuffPatch(base::File old_file,
  32. base::File patch_file,
  33. base::File destination_file,
  34. PatchCompleteCallback callback) const override {
  35. #if BUILDFLAG(ENABLE_PUFFIN_PATCHES)
  36. // TODO(crbug.com/1349060) once Puffin patches are fully implemented,
  37. // we should remove this #if.
  38. patch::PuffPatch(callback_.Run(), std::move(old_file),
  39. std::move(patch_file), std::move(destination_file),
  40. std::move(callback));
  41. #else
  42. NOTREACHED();
  43. #endif
  44. }
  45. protected:
  46. ~PatcherImpl() override = default;
  47. private:
  48. const PatchChromiumFactory::Callback callback_;
  49. };
  50. } // namespace
  51. PatchChromiumFactory::PatchChromiumFactory(Callback callback)
  52. : callback_(std::move(callback)) {}
  53. scoped_refptr<Patcher> PatchChromiumFactory::Create() const {
  54. return base::MakeRefCounted<PatcherImpl>(callback_);
  55. }
  56. PatchChromiumFactory::~PatchChromiumFactory() = default;
  57. } // namespace update_client