variations_request_scheduler_mobile.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (c) 2013 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. #ifndef COMPONENTS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_MOBILE_H_
  5. #define COMPONENTS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_MOBILE_H_
  6. #include "base/bind.h"
  7. #include "base/component_export.h"
  8. #include "base/gtest_prod_util.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/time/time.h"
  11. #include "base/timer/timer.h"
  12. #include "components/variations/variations_request_scheduler.h"
  13. class PrefService;
  14. namespace variations {
  15. // A specialized VariationsRequestScheduler that manages request cycles for the
  16. // VariationsService on mobile platforms.
  17. class COMPONENT_EXPORT(VARIATIONS) VariationsRequestSchedulerMobile
  18. : public VariationsRequestScheduler {
  19. public:
  20. // |task| is the closure to call when the scheduler deems ready. |local_state|
  21. // is the PrefService that contains the time of the last fetch.
  22. VariationsRequestSchedulerMobile(const base::RepeatingClosure& task,
  23. PrefService* local_state);
  24. VariationsRequestSchedulerMobile(const VariationsRequestSchedulerMobile&) =
  25. delete;
  26. VariationsRequestSchedulerMobile& operator=(
  27. const VariationsRequestSchedulerMobile&) = delete;
  28. ~VariationsRequestSchedulerMobile() override;
  29. // VariationsRequestScheduler:
  30. void Start() override;
  31. void Reset() override;
  32. void OnAppEnterForeground() override;
  33. private:
  34. FRIEND_TEST_ALL_PREFIXES(VariationsRequestSchedulerMobileTest,
  35. OnAppEnterForegroundNoRun);
  36. FRIEND_TEST_ALL_PREFIXES(VariationsRequestSchedulerMobileTest,
  37. OnAppEnterForegroundRun);
  38. FRIEND_TEST_ALL_PREFIXES(VariationsRequestSchedulerMobileTest,
  39. OnAppEnterForegroundOnStartup);
  40. // Determines whether we should fetch a seed depending on how much time has
  41. // passed since the last seed fetch. If the
  42. // |kDisableVariationsSeedFetchThrottling| command line switch is present,
  43. // this always returns true.
  44. bool ShouldFetchSeed(base::Time last_fetch_time);
  45. // The local state instance that provides the last fetch time.
  46. raw_ptr<PrefService> local_state_;
  47. // Timer used for triggering a delayed fetch for ScheduleFetch().
  48. base::OneShotTimer schedule_fetch_timer_;
  49. // The time the last seed request was initiated.
  50. base::Time last_request_time_;
  51. };
  52. } // namespace variations
  53. #endif // COMPONENTS_VARIATIONS_VARIATIONS_REQUEST_SCHEDULER_MOBILE_H_