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

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

Issue 1932953002: [Offline pages] Empty RequestQueue and SavePageRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated with documentation and formatting Created 4 years, 7 months 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 "base/callback.h"
11
12 namespace offline_pages {
13
14 class SavePageRequest;
15
16 // Class responsible for managing save page requests.
17 class RequestQueue {
18 public:
19 enum class GetRequestsResult {
20 kSuccess,
21 kStoreFailure,
22 };
23
24 enum class AddRequestResult {
25 kSuccess,
26 kStoreFailure,
27 kActiveRequestQuotaHit, // Cannot add a request with this namespace, as
28 // it has reached a quota of active requests.
Pete Williamson 2016/04/28 23:16:07 Why do we need two quotas? Would one suffice? I s
fgorski 2016/04/29 05:19:15 Done.
29 kTotalRequestQuotaHit, // Cannot add a request with this namespace, as
30 // it has reached a quota of total requests.
31 };
32
33 enum class UpdateRequestResult {
34 kSuccess,
35 kStoreFailure,
36 kRequestDoesNotExist, // Failed to delete the request because it does not
37 // exist.
38 };
39
40 // Callback used for |GetRequests|.
Pete Williamson 2016/04/28 23:16:07 Why make these async? I'm not averse to async per
fgorski 2016/04/29 05:19:15 The capability to store and read it from a file.
41 typedef base::Callback <
42 void(GetRequestsResult,
43 const std::vector<SavePageRequest>&) GetRequestsCallback;
44
45 // Callback used for |AddRequest|.
46 typedef base::Callback<void(AddRequestResult, const SavePageRequest& request)>
47 AddRequestCallback;
48
49 // Callback used by |UdpateRequest| and |RemoveRequest|.
50 typedef base::Callback<void(UpdateRequestResult)> UpdateRequestCallback;
51
52 // Gets all of the active requests from the store. Calling this method may
53 // schedule purging of the request queue.
Pete Williamson 2016/04/28 23:16:07 Why not have all the methods schedule a queue purg
fgorski 2016/04/29 05:19:15 Because other methods don't know if there is anyth
54 void GetRequests(const GetRequestsResult& callback);
55
56 // Adds |request| to the request queue. Result is returned through |callback|.
57 // In case adding the request violates policy, the result will fail with
58 // appropriate result. Callback will also return a copy of a request with all
59 // fields set.
60 void AddRequest(const SavePageRequest& request,
61 const AddRequestCallback& callback);
62
63 // Updates a request in the request queue if a request with matching ID
64 // exists. Does nothing otherwise. Result is returned through |callback|.
65 void UpdateRequest(const SavePageRequest& request,
66 const UpdateRequestCallback& callback);
67
68 // Removes the request matching the |request_id|. Result is returned through
69 // |callback|.
70 void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback);
71
72 private:
73 // Callback used by |PurgeRequests|.
74 typedef base::Callback<void(UpdateRequestResult,
75 int /* removed requests count */)>
76 PurgeRequestsCallback;
77
78 // Purges the queue, removing the requests that are no longer relevant, e.g.
79 // expired request. Result is returned through |callback| carries the number
80 // of removed requests.
81 void PurgeRequests(const PurgeRequestsCallback& callback);
82 };
83
84 } // namespace offline_pages
85
86 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698