Chromium Code Reviews| 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 class UpdateRequestTask : public Task { | |
|
dougarnett
2016/10/19 21:23:10
doc? base class for updating a request?
fgorski
2016/10/20 16:56:34
Done.
| |
| 19 public: | |
| 20 UpdateRequestTask(RequestQueueStore* store, | |
| 21 int64_t request_id, | |
| 22 const RequestQueueStore::UpdateCallback& callback); | |
| 23 ~UpdateRequestTask() override; | |
| 24 | |
| 25 // TaskQueue::Task implementation. | |
| 26 void Run() override; | |
| 27 | |
| 28 protected: | |
| 29 // Step 1. Reading the requests. | |
| 30 void ReadRequest(); | |
| 31 // Step 2. Work is done in the implementation step. | |
| 32 virtual void UpdateRequestImpl( | |
| 33 std::unique_ptr<UpdateRequestsResult> result) = 0; | |
| 34 // Step 3. Completes once update is done. | |
| 35 void CompleteWithResult(std::unique_ptr<UpdateRequestsResult> result); | |
| 36 | |
| 37 // Function to uniformly validate read request call for store errors and | |
| 38 // presence of the request. | |
| 39 bool ValidateReadResult(UpdateRequestsResult* result); | |
| 40 | |
| 41 RequestQueueStore* store() const { return store_; } | |
| 42 | |
| 43 int64_t request_id() const { return request_id_; } | |
| 44 | |
| 45 base::WeakPtr<UpdateRequestTask> GetWeakPtr() { | |
| 46 return weak_ptr_factory_.GetWeakPtr(); | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 // Store that this task updates. Not owned. | |
| 51 RequestQueueStore* store_; | |
| 52 // Request ID of the request to be started. | |
| 53 int64_t request_id_; | |
| 54 // Callback to complete the task. | |
| 55 RequestQueueStore::UpdateCallback callback_; | |
| 56 | |
| 57 base::WeakPtrFactory<UpdateRequestTask> weak_ptr_factory_; | |
| 58 DISALLOW_COPY_AND_ASSIGN(UpdateRequestTask); | |
| 59 }; | |
| 60 | |
| 61 } // namespace offline_pages | |
| 62 | |
| 63 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_UPDATE_REQUEST_TASK_H_ | |
| OLD | NEW |