setup_mac.mm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2020 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 "chrome/updater/setup.h"
  5. #include "base/bind.h"
  6. #include "base/callback.h"
  7. #include "base/task/task_traits.h"
  8. #include "base/task/thread_pool.h"
  9. #include "base/time/time.h"
  10. #include "chrome/updater/constants.h"
  11. #include "chrome/updater/launchd_util.h"
  12. #include "chrome/updater/mac/setup/setup.h"
  13. #include "chrome/updater/mac/xpc_service_names.h"
  14. #include "chrome/updater/updater_scope.h"
  15. namespace updater {
  16. namespace {
  17. void SetupDone(base::OnceCallback<void(int)> callback,
  18. UpdaterScope scope,
  19. int result) {
  20. if (result != kErrorOk) {
  21. std::move(callback).Run(result);
  22. return;
  23. }
  24. PollLaunchctlList(
  25. scope, GetUpdateServiceInternalLaunchdName(scope),
  26. LaunchctlPresence::kPresent, base::Seconds(kWaitForLaunchctlUpdateSec),
  27. base::BindOnce(
  28. [](base::OnceCallback<void(int)> callback, bool service_exists) {
  29. std::move(callback).Run(
  30. service_exists
  31. ? kErrorOk
  32. : kErrorFailedAwaitingLaunchdUpdateServiceInternalJob);
  33. },
  34. std::move(callback)));
  35. }
  36. } // namespace
  37. void InstallCandidate(UpdaterScope scope,
  38. base::OnceCallback<void(int)> callback) {
  39. base::ThreadPool::PostTaskAndReplyWithResult(
  40. FROM_HERE, {base::MayBlock()}, base::BindOnce(&Setup, scope),
  41. base::BindOnce(&SetupDone, std::move(callback), scope));
  42. }
  43. } // namespace updater