| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 |
| 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_CLEANUP_TASK_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_CLEANUP_TASK_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "components/offline_pages/background/request_queue_results.h" |
| 12 #include "components/offline_pages/background/save_page_request.h" |
| 13 #include "components/offline_pages/core/task.h" |
| 14 |
| 15 namespace offline_pages { |
| 16 |
| 17 class OfflinerPolicy; |
| 18 class RequestCoordinatorEventLogger; |
| 19 class RequestNotifier; |
| 20 class RequestQueueStore; |
| 21 |
| 22 class CleanupTask : public Task { |
| 23 public: |
| 24 CleanupTask(RequestQueueStore* store, |
| 25 OfflinerPolicy* policy, |
| 26 RequestNotifier* notifier, |
| 27 RequestCoordinatorEventLogger* logger); |
| 28 ~CleanupTask() override; |
| 29 |
| 30 // TaskQueue::Task implementation, starts the async chain |
| 31 void Run() override; |
| 32 |
| 33 private: |
| 34 // Step 1. get results from the store |
| 35 void GetRequests(); |
| 36 |
| 37 // Step 2. Prune stale requests |
| 38 void Prune(bool success, |
| 39 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 40 |
| 41 // Step 3. Handle deleting stale entries and notifying observers. |
| 42 void RemoveStaleRequests(std::vector<int64_t> stale_request_ids); |
| 43 |
| 44 // Step 4. Send delete notifications for the expired requests. |
| 45 void OnRequestsExpired(std::unique_ptr<UpdateRequestsResult> result); |
| 46 |
| 47 // Build a list of IDs whose request has expired. |
| 48 void GetExpiredRequestIds( |
| 49 std::vector<std::unique_ptr<SavePageRequest>> requests, |
| 50 std::vector<int64_t>* expired_request_ids); |
| 51 |
| 52 // Member variables, all pointers are not owned here. |
| 53 RequestQueueStore* store_; |
| 54 OfflinerPolicy* policy_; |
| 55 RequestNotifier* notifier_; |
| 56 RequestCoordinatorEventLogger* event_logger_; |
| 57 // Allows us to pass a weak pointer to callbacks. |
| 58 base::WeakPtrFactory<CleanupTask> weak_ptr_factory_; |
| 59 }; |
| 60 |
| 61 } // namespace offline_pages |
| 62 |
| 63 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_CLEANUP_TASK_H_ |
| OLD | NEW |