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_UPDATE_REQUEST_TASK_H_ | |
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_UPDATE_REQUEST_TASK_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "components/offline_pages/background/request_queue_store.h" | |
14 #include "components/offline_pages/core/task.h" | |
15 | |
16 namespace offline_pages { | |
17 | |
18 // Base class for update requests that only work on a single save page request. | |
19 // Derived classes should implement appropriate functionality by overloading | |
20 // |UpdateRequestImpl| method. | |
21 class UpdateRequestTask : public Task { | |
22 public: | |
23 UpdateRequestTask(RequestQueueStore* store, | |
24 int64_t request_id, | |
25 const RequestQueueStore::UpdateCallback& callback); | |
26 ~UpdateRequestTask() override; | |
27 | |
28 // TaskQueue::Task implementation. | |
29 void Run() override; | |
30 | |
31 protected: | |
32 // Step 1. Reading the requests. | |
33 void ReadRequest(); | |
34 // Step 2. Work is done in the implementation step. | |
35 virtual void UpdateRequestImpl( | |
36 std::unique_ptr<UpdateRequestsResult> result) = 0; | |
37 // Step 3. Completes once update is done. | |
38 void CompleteWithResult(std::unique_ptr<UpdateRequestsResult> result); | |
39 | |
40 // Function to uniformly validate read request call for store errors and | |
41 // presence of the request. | |
42 bool ValidateReadResult(UpdateRequestsResult* result); | |
43 | |
44 RequestQueueStore* store() const { return store_; } | |
45 | |
46 int64_t request_id() const { return request_id_; } | |
47 | |
48 base::WeakPtr<UpdateRequestTask> GetWeakPtr() { | |
49 return weak_ptr_factory_.GetWeakPtr(); | |
50 } | |
51 | |
52 private: | |
53 // Store that this task updates. Not owned. | |
54 RequestQueueStore* store_; | |
55 // Request ID of the request to be started. | |
56 int64_t request_id_; | |
57 // Callback to complete the task. | |
58 RequestQueueStore::UpdateCallback callback_; | |
59 | |
60 base::WeakPtrFactory<UpdateRequestTask> weak_ptr_factory_; | |
61 DISALLOW_COPY_AND_ASSIGN(UpdateRequestTask); | |
62 }; | |
63 | |
64 } // namespace offline_pages | |
65 | |
66 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_UPDATE_REQUEST_TASK_H_ | |
OLD | NEW |