activity.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/activity.h"
  5. #include <set>
  6. #include <string>
  7. #include <utility>
  8. #include <vector>
  9. #include "base/bind.h"
  10. #include "base/callback.h"
  11. #include "base/task/task_traits.h"
  12. #include "base/task/thread_pool.h"
  13. #include "chrome/updater/activity_impl.h"
  14. #include "chrome/updater/updater_scope.h"
  15. namespace updater {
  16. namespace {
  17. constexpr int kDaysUnknown = -2;
  18. }
  19. ActivityDataService::ActivityDataService(UpdaterScope scope) : scope_(scope) {}
  20. void ActivityDataService::GetActiveBits(
  21. const std::vector<std::string>& ids,
  22. base::OnceCallback<void(const std::set<std::string>&)> callback) const {
  23. base::ThreadPool::PostTaskAndReplyWithResult(
  24. FROM_HERE, {base::MayBlock()},
  25. base::BindOnce(
  26. [](UpdaterScope scope, const std::vector<std::string>& ids) {
  27. std::set<std::string> result;
  28. for (const auto& id : ids) {
  29. if (GetActiveBit(scope, id))
  30. result.insert(id);
  31. }
  32. return result;
  33. },
  34. scope_, ids),
  35. std::move(callback));
  36. }
  37. void ActivityDataService::GetAndClearActiveBits(
  38. const std::vector<std::string>& ids,
  39. base::OnceCallback<void(const std::set<std::string>&)> callback) {
  40. base::ThreadPool::PostTaskAndReplyWithResult(
  41. FROM_HERE, {base::MayBlock()},
  42. base::BindOnce(
  43. [](UpdaterScope scope, const std::vector<std::string>& ids) {
  44. std::set<std::string> result;
  45. for (const auto& id : ids) {
  46. if (GetActiveBit(scope, id))
  47. result.insert(id);
  48. ClearActiveBit(scope, id);
  49. }
  50. return result;
  51. },
  52. scope_, ids),
  53. std::move(callback));
  54. }
  55. int ActivityDataService::GetDaysSinceLastActive(const std::string& id) const {
  56. // The updater does not report DaysSince data, only DateLast data.
  57. return kDaysUnknown;
  58. }
  59. int ActivityDataService::GetDaysSinceLastRollCall(const std::string& id) const {
  60. // The updater does not report DaysSince data, only DateLast data.
  61. return kDaysUnknown;
  62. }
  63. } // namespace updater