Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Side by Side Diff: components/offline_pages/background/request_queue.h

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_REQUEST_QUEUE_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <set>
12 #include <string>
13 #include <vector>
14
15 #include "base/callback.h"
16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h"
18 #include "components/offline_pages/background/cleanup_task_factory.h"
19 #include "components/offline_pages/background/device_conditions.h"
20 #include "components/offline_pages/background/pick_request_task.h"
21 #include "components/offline_pages/background/request_queue_results.h"
22 #include "components/offline_pages/background/save_page_request.h"
23 #include "components/offline_pages/core/task_queue.h"
24 #include "components/offline_pages/offline_page_item.h"
25 #include "components/offline_pages/offline_store_types.h"
26
27 namespace offline_pages {
28
29 class CleanupTaskFactory;
30 class RequestQueueStore;
31
32 // Class responsible for managing save page requests.
33 class RequestQueue {
34 public:
35
36 // Callback used for |GetRequests|.
37 typedef base::Callback<void(GetRequestsResult,
38 std::vector<std::unique_ptr<SavePageRequest>>)>
39 GetRequestsCallback;
40
41 // Callback used for |AddRequest|.
42 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)>
43 AddRequestCallback;
44
45 // Callback used by |ChangeRequestsState|.
46 typedef base::Callback<void(std::unique_ptr<UpdateRequestsResult>)>
47 UpdateCallback;
48
49 // Callback used by |UdpateRequest|.
50 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback;
51
52 explicit RequestQueue(std::unique_ptr<RequestQueueStore> store);
53 ~RequestQueue();
54
55 // Gets all of the active requests from the store. Calling this method may
56 // schedule purging of the request queue.
57 void GetRequests(const GetRequestsCallback& callback);
58
59 // Adds |request| to the request queue. Result is returned through |callback|.
60 // In case adding the request violates policy, the result will fail with
61 // appropriate result. Callback will also return a copy of a request with all
62 // fields set.
63 void AddRequest(const SavePageRequest& request,
64 const AddRequestCallback& callback);
65
66 // Removes the requests matching the |request_ids|. Result is returned through
67 // |callback|. If a request id cannot be removed, this will still remove the
68 // others.
69 void RemoveRequests(const std::vector<int64_t>& request_ids,
70 const UpdateCallback& callback);
71
72 // Changes the state to |new_state| for requests matching the
73 // |request_ids|. Results are returned through |callback|.
74 void ChangeRequestsState(const std::vector<int64_t>& request_ids,
75 const SavePageRequest::RequestState new_state,
76 const UpdateCallback& callback);
77
78 // Marks attempt with |request_id| as started. Results are returned through
79 // |callback|.
80 void MarkAttemptStarted(int64_t request_id, const UpdateCallback& callback);
81
82 // Marks attempt with |request_id| as aborted. Results are returned through
83 // |callback|.
84 void MarkAttemptAborted(int64_t request_id, const UpdateCallback& callback);
85
86 // Marks attempt with |request_id| as completed. The attempt may have
87 // completed with either success or failure (not denoted here). Results
88 // are returned through |callback|.
89 void MarkAttemptCompleted(int64_t request_id, const UpdateCallback& callback);
90
91 // Make a task to pick the next request, and report our choice to the
92 // callbacks.
93 void PickNextRequest(
94 OfflinerPolicy* policy,
95 PickRequestTask::RequestPickedCallback picked_callback,
96 PickRequestTask::RequestNotPickedCallback not_picked_callback,
97 PickRequestTask::RequestCountCallback request_count_callback,
98 DeviceConditions& conditions,
99 std::set<int64_t>& disabled_requests);
100
101 // Cleanup requests that have expired, exceeded the start or completed retry
102 // limit.
103 void CleanupRequestQueue();
104
105 // Takes ownership of the factory. We use a setter to allow users of the
106 // request queue to not need a CleanupFactory to create it, since we have lots
107 // of code using the request queue. The request coordinator will set a
108 // factory before calling CleanupRequestQueue.
109 void SetCleanupFactory(std::unique_ptr<CleanupTaskFactory> factory) {
110 cleanup_factory_ = std::move(factory);
111 }
112
113 private:
114 // Store initialization functions.
115 void Initialize();
116 void InitializeStoreDone(bool success);
117
118 std::unique_ptr<RequestQueueStore> store_;
119
120 // Task queue to serialize store access.
121 TaskQueue task_queue_;
122
123 // Builds CleanupTask objects.
124 std::unique_ptr<CleanupTaskFactory> cleanup_factory_;
125
126 // Allows us to pass a weak pointer to callbacks.
127 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_;
128
129 DISALLOW_COPY_AND_ASSIGN(RequestQueue);
130 };
131
132 } // namespace offline_pages
133
134 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_notifier.h ('k') | components/offline_pages/background/request_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698