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

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

Issue 2221323003: Add an API to Pause and Resume background offlining requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More FGorski CR feedback Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ 6 #define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "components/offline_pages/background/save_page_request.h"
17 #include "components/offline_pages/offline_page_item.h" 18 #include "components/offline_pages/offline_page_item.h"
18 19
19 namespace offline_pages { 20 namespace offline_pages {
20 21
21 class RequestQueueStore; 22 class RequestQueueStore;
22 class SavePageRequest;
23 23
24 // Class responsible for managing save page requests. 24 // Class responsible for managing save page requests.
25 class RequestQueue { 25 class RequestQueue {
26 public: 26 public:
27 enum class GetRequestsResult { 27 enum class GetRequestsResult {
28 SUCCESS, 28 SUCCESS,
29 STORE_FAILURE, 29 STORE_FAILURE,
30 }; 30 };
31 31
32 enum class AddRequestResult { 32 enum class AddRequestResult {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 // Removes the request matching the |request_id|. Result is returned through 77 // Removes the request matching the |request_id|. Result is returned through
78 // |callback|. 78 // |callback|.
79 void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback); 79 void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback);
80 80
81 // Removes the requests matching the |client_ids|. Results are returned 81 // Removes the requests matching the |client_ids|. Results are returned
82 // through |callback|. 82 // through |callback|.
83 void RemoveRequestsByClientId(const std::vector<ClientId>& client_id, 83 void RemoveRequestsByClientId(const std::vector<ClientId>& client_id,
84 const UpdateRequestCallback& callback); 84 const UpdateRequestCallback& callback);
85 85
86 // Changes the state to |new_state_ for requests matching the
87 // |request_ids|. Results are returned through |callback|.
88 // TODO(petewil): Instead of having one function per property,
89 // modify this to have a single update function that updates an entire
90 // request, and doesn't need to care what updates.
91 void ChangeRequestsState(const std::vector<int64_t>& request_ids,
92 const SavePageRequest::RequestState new_state,
93 const UpdateRequestCallback& callback);
94
86 void GetForUpdateDone( 95 void GetForUpdateDone(
87 const RequestQueue::UpdateRequestCallback& update_callback, 96 const RequestQueue::UpdateRequestCallback& update_callback,
88 const SavePageRequest& update_request, 97 const SavePageRequest& update_request,
89 bool success, 98 bool success,
90 const std::vector<SavePageRequest>& requests); 99 const std::vector<SavePageRequest>& requests);
91 100
92 private: 101 private:
93 // Callback used by |PurgeRequests|. 102 // Callback used by |PurgeRequests|.
94 typedef base::Callback<void(UpdateRequestResult, 103 typedef base::Callback<void(UpdateRequestResult,
95 int /* removed requests count */)> 104 int /* removed requests count */)>
96 PurgeRequestsCallback; 105 PurgeRequestsCallback;
97 106
98 // Purges the queue, removing the requests that are no longer relevant, e.g. 107 // Purges the queue, removing the requests that are no longer relevant, e.g.
99 // expired request. Result is returned through |callback| carries the number 108 // expired request. Result is returned through |callback| carries the number
100 // of removed requests. 109 // of removed requests.
101 void PurgeRequests(const PurgeRequestsCallback& callback); 110 void PurgeRequests(const PurgeRequestsCallback& callback);
102 111
103 std::unique_ptr<RequestQueueStore> store_; 112 std::unique_ptr<RequestQueueStore> store_;
104 113
105 // Allows us to pass a weak pointer to callbacks. 114 // Allows us to pass a weak pointer to callbacks.
106 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; 115 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_;
107 116
108 DISALLOW_COPY_AND_ASSIGN(RequestQueue); 117 DISALLOW_COPY_AND_ASSIGN(RequestQueue);
109 }; 118 };
110 119
111 } // namespace offline_pages 120 } // namespace offline_pages
112 121
113 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ 122 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698