| 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 | 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // exists. Does nothing otherwise. Result is returned through |callback|. | 81 // exists. Does nothing otherwise. Result is returned through |callback|. |
| 82 void UpdateRequest(const SavePageRequest& request, | 82 void UpdateRequest(const SavePageRequest& request, |
| 83 const UpdateRequestCallback& callback); | 83 const UpdateRequestCallback& callback); |
| 84 | 84 |
| 85 // Removes the requests matching the |request_ids|. Result is returned through | 85 // Removes the requests matching the |request_ids|. Result is returned through |
| 86 // |callback|. If a request id cannot be removed, this will still remove the | 86 // |callback|. If a request id cannot be removed, this will still remove the |
| 87 // others. | 87 // others. |
| 88 void RemoveRequests(const std::vector<int64_t>& request_ids, | 88 void RemoveRequests(const std::vector<int64_t>& request_ids, |
| 89 const RemoveRequestsCallback& callback); | 89 const RemoveRequestsCallback& callback); |
| 90 | 90 |
| 91 // Changes the state to |new_state_ for requests matching the |
| 92 // |request_ids|. Results are returned through |callback|. |
| 93 // TODO(petewil): Instead of having one function per property, |
| 94 // modify this to have a single update function that updates an entire |
| 95 // request, and doesn't need to care what updates. |
| 96 void ChangeRequestsState(const std::vector<int64_t>& request_ids, |
| 97 const SavePageRequest::RequestState new_state, |
| 98 const UpdateRequestCallback& callback); |
| 99 |
| 91 void GetForUpdateDone( | 100 void GetForUpdateDone( |
| 92 const RequestQueue::UpdateRequestCallback& update_callback, | 101 const RequestQueue::UpdateRequestCallback& update_callback, |
| 93 const SavePageRequest& update_request, | 102 const SavePageRequest& update_request, |
| 94 bool success, | 103 bool success, |
| 95 const std::vector<SavePageRequest>& requests); | 104 const std::vector<SavePageRequest>& requests); |
| 96 | 105 |
| 97 private: | 106 private: |
| 98 // Callback used by |PurgeRequests|. | 107 // Callback used by |PurgeRequests|. |
| 99 typedef base::Callback<void(UpdateRequestResult, | 108 typedef base::Callback<void(UpdateRequestResult, |
| 100 int /* removed requests count */)> | 109 int /* removed requests count */)> |
| 101 PurgeRequestsCallback; | 110 PurgeRequestsCallback; |
| 102 | 111 |
| 103 // Purges the queue, removing the requests that are no longer relevant, e.g. | 112 // Purges the queue, removing the requests that are no longer relevant, e.g. |
| 104 // expired request. Result is returned through |callback| carries the number | 113 // expired request. Result is returned through |callback| carries the number |
| 105 // of removed requests. | 114 // of removed requests. |
| 106 void PurgeRequests(const PurgeRequestsCallback& callback); | 115 void PurgeRequests(const PurgeRequestsCallback& callback); |
| 107 | 116 |
| 108 std::unique_ptr<RequestQueueStore> store_; | 117 std::unique_ptr<RequestQueueStore> store_; |
| 109 | 118 |
| 110 // Allows us to pass a weak pointer to callbacks. | 119 // Allows us to pass a weak pointer to callbacks. |
| 111 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; | 120 base::WeakPtrFactory<RequestQueue> weak_ptr_factory_; |
| 112 | 121 |
| 113 DISALLOW_COPY_AND_ASSIGN(RequestQueue); | 122 DISALLOW_COPY_AND_ASSIGN(RequestQueue); |
| 114 }; | 123 }; |
| 115 | 124 |
| 116 } // namespace offline_pages | 125 } // namespace offline_pages |
| 117 | 126 |
| 118 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ | 127 #endif // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_H_ |
| OLD | NEW |