tile_service_scheduler.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #ifndef COMPONENTS_QUERY_TILES_INTERNAL_TILE_SERVICE_SCHEDULER_H_
  5. #define COMPONENTS_QUERY_TILES_INTERNAL_TILE_SERVICE_SCHEDULER_H_
  6. #include "components/background_task_scheduler/background_task_scheduler.h"
  7. #include "components/query_tiles/internal/tile_types.h"
  8. namespace query_tiles {
  9. struct TileGroup;
  10. // Coordinates with native background task scheduler to schedule or cancel a
  11. // TileBackgroundTask.
  12. class TileServiceScheduler {
  13. public:
  14. class Delegate {
  15. public:
  16. Delegate() = default;
  17. virtual ~Delegate() = default;
  18. Delegate(const Delegate& other) = delete;
  19. Delegate& operator=(const Delegate& other) = delete;
  20. // Returns the tile group instance holds in memory.
  21. virtual TileGroup* GetTileGroup() = 0;
  22. };
  23. // Set delegate object for the scheduler.
  24. virtual void SetDelegate(Delegate* delegate) = 0;
  25. // Called when fetching task starts.
  26. virtual void OnFetchStarted() = 0;
  27. // Called on fetch task completed, schedule another task with or without
  28. // backoff based on the status. Success status will lead a regular schedule
  29. // after around 14 - 18 hours. Failure status will lead a backoff, the release
  30. // duration is related to count of failures. Suspend status will directly set
  31. // the release time until 24 hours later.
  32. virtual void OnFetchCompleted(TileInfoRequestStatus status) = 0;
  33. // Called on tile manager initialization completed, schedule another task with
  34. // or without backoff based on the status. NoTiles status will lead a regular
  35. // schedule after around 14 - 18 hours. DbOperationFailure status will
  36. // directly set the release time until 24 hours later.
  37. virtual void OnTileManagerInitialized(TileGroupStatus status) = 0;
  38. // Called when database is purged. Reset the flow and update the status.
  39. virtual void OnDbPurged(TileGroupStatus status) = 0;
  40. // Called when parsed group data are saved.
  41. virtual void OnGroupDataSaved(TileGroupStatus status) = 0;
  42. // Cancel current existing task, and reset scheduler.
  43. virtual void CancelTask() = 0;
  44. virtual ~TileServiceScheduler() = default;
  45. TileServiceScheduler(const TileServiceScheduler& other) = delete;
  46. TileServiceScheduler& operator=(const TileServiceScheduler& other) = delete;
  47. protected:
  48. TileServiceScheduler() = default;
  49. };
  50. } // namespace query_tiles
  51. #endif // COMPONENTS_QUERY_TILES_INTERNAL_TILE_SERVICE_SCHEDULER_H_