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_CHANGE_REQUESTS_STATE_TASK_H_ | |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_CHANGE_REQUESTS_STATE_TASK_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 #include <unordered_set> | |
12 #include <vector> | |
13 | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "components/offline_pages/background/request_queue_store.h" | |
16 #include "components/offline_pages/background/save_page_request.h" | |
17 #include "components/offline_pages/core/task.h" | |
18 | |
19 namespace offline_pages { | |
20 | |
21 class ChangeRequestsStateTask : public Task { | |
22 public: | |
23 ChangeRequestsStateTask(RequestQueueStore* store, | |
24 const std::vector<int64_t>& request_ids, | |
25 const SavePageRequest::RequestState new_state, | |
26 const RequestQueueStore::UpdateCallback& callback); | |
27 ~ChangeRequestsStateTask() override; | |
28 | |
29 // TaskQueue::Task implementation. | |
30 void Run() override; | |
31 | |
32 private: | |
33 // Step 1. Reading the requests. | |
34 void ReadRequests(); | |
35 // Step 2. Updates available requests. | |
36 void UpdateRequests(std::unique_ptr<UpdateRequestsResult> read_result); | |
37 // Step 3. Processes update result, calls callback. | |
38 void UpdateCompleted(std::unique_ptr<UpdateRequestsResult> update_result); | |
39 | |
40 // Store that this task updates. | |
41 RequestQueueStore* store_; | |
42 // Request IDs to be updated. Kept as a set to remove duplicates and simplify | |
43 // the look up of requests that are not found in step 3. | |
44 std::unordered_set<int64_t> request_ids_; | |
45 // New state to be set on all entries. | |
46 SavePageRequest::RequestState new_state_; | |
47 // Callback to complete the task. | |
48 RequestQueueStore::UpdateCallback callback_; | |
49 | |
50 base::WeakPtrFactory<ChangeRequestsStateTask> weak_ptr_factory_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(ChangeRequestsStateTask); | |
53 }; | |
54 | |
55 } // namespace offline_pages | |
56 | |
57 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_CHANGE_REQUESTS_STATE_TASK_H_ | |
OLD | NEW |