Chromium Code Reviews| Index: components/offline_pages/background/change_requests_state_task.h |
| diff --git a/components/offline_pages/background/change_requests_state_task.h b/components/offline_pages/background/change_requests_state_task.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..437ed25cfbf3ecec83821381d5183d350e85d4d5 |
| --- /dev/null |
| +++ b/components/offline_pages/background/change_requests_state_task.h |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_CHANGE_REQUEST_STATE_TASK_H_ |
| +#define COMPONENTS_OFFLINE_PAGES_BACKGROUND_CHANGE_REQUEST_STATE_TASK_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <memory> |
| +#include <unordered_set> |
| +#include <vector> |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/offline_pages/background/request_queue_store.h" |
| +#include "components/offline_pages/background/save_page_request.h" |
| +#include "components/offline_pages/core/task_queue.h" |
| + |
| +namespace offline_pages { |
| + |
| +class ChangeRequestsStateTask : public TaskQueue::Task { |
|
Pete Williamson
2016/09/27 23:49:56
Does chrome already have a way to do this It seem
fgorski
2016/09/28 22:39:06
I wasn't able to find anything like that. I think
|
| + public: |
| + ChangeRequestsStateTask(RequestQueueStore* store, |
| + const std::vector<int64_t>& request_ids, |
| + const SavePageRequest::RequestState new_state, |
| + const RequestQueueStore::UpdateCallback& callback); |
| + ~ChangeRequestsStateTask() override; |
| + |
| + // TaskQueue::Task implementation. |
| + // Step 1. Reading the requests. |
| + void Run() override; |
| + |
| + // Step 2. Selecting requests to be updated. Calls update. |
| + void SelectItemsToUpdate( |
| + bool success, |
| + std::vector<std::unique_ptr<SavePageRequest>> requests); |
| + |
| + // Step 3. Processes update result, calls callback. |
| + void UpdateCompleted(std::unique_ptr<UpdateRequestsResult> update_result); |
| + |
| + private: |
| + void CompleteEarly(ItemActionStatus status); |
| + void CompleteWithStatus(std::unique_ptr<UpdateRequestsResult> result, |
| + ItemActionStatus status); |
| + |
| + // Store that this task updates. |
| + RequestQueueStore* store_; |
| + // Request IDs to be updated. |
| + // TODO(fgorski): perhaps convert to unique_ptr to a vector. |
|
Pete Williamson
2016/09/27 23:49:56
comment out of date?
fgorski
2016/09/28 22:39:06
Done
|
| + std::unordered_set<int64_t> request_ids_; |
| + // New state to be set on all entries. |
| + SavePageRequest::RequestState new_state_; |
| + // Callback to complete the task. |
| + RequestQueueStore::UpdateCallback callback_; |
| + |
| + base::WeakPtrFactory<ChangeRequestsStateTask> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ChangeRequestsStateTask); |
| +}; |
| + |
| +} // namespace offline_pages |
| + |
| +#endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_CHANGE_REQUEST_STATE_TASK_H_ |