Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 class SavePageRequest; |
|
fgorski
2016/08/10 16:00:09
please remove now that you are adding the .h file.
Pete Williamson
2016/08/10 21:38:00
Done.
| |
| 23 | 24 |
| 24 // Class responsible for managing save page requests. | 25 // Class responsible for managing save page requests. |
| 25 class RequestQueue { | 26 class RequestQueue { |
| 26 public: | 27 public: |
| 27 enum class GetRequestsResult { | 28 enum class GetRequestsResult { |
| 28 SUCCESS, | 29 SUCCESS, |
| 29 STORE_FAILURE, | 30 STORE_FAILURE, |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 enum class AddRequestResult { | 33 enum class AddRequestResult { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 | 77 |
| 77 // Removes the request matching the |request_id|. Result is returned through | 78 // Removes the request matching the |request_id|. Result is returned through |
| 78 // |callback|. | 79 // |callback|. |
| 79 void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback); | 80 void RemoveRequest(int64_t request_id, const UpdateRequestCallback& callback); |
| 80 | 81 |
| 81 // Removes the requests matching the |client_ids|. Results are returned | 82 // Removes the requests matching the |client_ids|. Results are returned |
| 82 // through |callback|. | 83 // through |callback|. |
| 83 void RemoveRequestsByClientId(const std::vector<ClientId>& client_id, | 84 void RemoveRequestsByClientId(const std::vector<ClientId>& client_id, |
| 84 const UpdateRequestCallback& callback); | 85 const UpdateRequestCallback& callback); |
| 85 | 86 |
| 87 // Changes the state to |new_state_ for requests matching the | |
| 88 // |request_ids|. Results are returned through |callback|. | |
| 89 void ChangeRequestsState(const std::vector<int64_t>& request_ids, | |
|
fgorski
2016/08/10 16:00:09
Is the plan to add one of these for everything tha
Pete Williamson
2016/08/10 21:38:00
Sure, let's discuss this. Leaving code as is for
Pete Williamson
2016/08/10 23:34:40
After discussion, plan is to start updating the en
| |
| 90 const SavePageRequest::RequestState new_state, | |
| 91 const UpdateRequestCallback& callback); | |
| 92 | |
| 86 void GetForUpdateDone( | 93 void GetForUpdateDone( |
| 87 const RequestQueue::UpdateRequestCallback& update_callback, | 94 const RequestQueue::UpdateRequestCallback& update_callback, |
| 88 const SavePageRequest& update_request, | 95 const SavePageRequest& update_request, |
| 89 bool success, | 96 bool success, |
| 90 const std::vector<SavePageRequest>& requests); | 97 const std::vector<SavePageRequest>& requests); |
| 91 | 98 |
| 92 private: | 99 private: |
| 93 // Callback used by |PurgeRequests|. | 100 // Callback used by |PurgeRequests|. |
| 94 typedef base::Callback<void(UpdateRequestResult, | 101 typedef base::Callback<void(UpdateRequestResult, |
| 95 int /* removed requests count */)> | 102 int /* removed requests count */)> |
| 96 PurgeRequestsCallback; | 103 PurgeRequestsCallback; |
| 97 | 104 |
| 98 // Purges the queue, removing the requests that are no longer relevant, e.g. | 105 // Purges the queue, removing the requests that are no longer relevant, e.g. |
| 99 // expired request. Result is returned through |callback| carries the number | 106 // expired request. Result is returned through |callback| carries the number |
| 100 // of removed requests. | 107 // of removed requests. |
| 101 void PurgeRequests(const PurgeRequestsCallback& callback); | 108 void PurgeRequests(const PurgeRequestsCallback& callback); |
| 102 | 109 |
| 103 std::unique_ptr<RequestQueueStore> store_; | 110 std::unique_ptr<RequestQueueStore> store_; |
| 104 | 111 |
| 105 // Allows us to pass a weak pointer to callbacks. | 112 // Allows us to pass a weak pointer to callbacks. |
| 106 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; | 113 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; |
| 107 | 114 |
| 108 DISALLOW_COPY_AND_ASSIGN(RequestQueue); | 115 DISALLOW_COPY_AND_ASSIGN(RequestQueue); |
| 109 }; | 116 }; |
| 110 | 117 |
| 111 } // namespace offline_pages | 118 } // namespace offline_pages |
| 112 | 119 |
| 113 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 120 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
| OLD | NEW |