| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CONTENT_BROWSER_BACKGROUND_FETCH_REQUEST_INFO_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_REQUEST_INFO_H_ |
| 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_REQUEST_INFO_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_REQUEST_INFO_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 12 #include "content/browser/background_fetch/background_fetch_constants.h" | 14 #include "content/browser/background_fetch/background_fetch_constants.h" |
| 13 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 14 #include "content/common/service_worker/service_worker_types.h" | 16 #include "content/common/service_worker/service_worker_types.h" |
| 15 #include "content/public/browser/download_interrupt_reasons.h" | 17 #include "content/public/browser/download_interrupt_reasons.h" |
| 16 #include "content/public/browser/download_item.h" | 18 #include "content/public/browser/download_item.h" |
| 17 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 | 22 |
| 21 // Simple class to encapsulate the components of a fetch request. | 23 // Simple class to encapsulate the components of a fetch request. |
| 22 class CONTENT_EXPORT BackgroundFetchRequestInfo { | 24 // TODO(peter): This can likely change to have a single owner, and thus become |
| 25 // an std::unique_ptr<>, when persistent storage has been implemented. |
| 26 class CONTENT_EXPORT BackgroundFetchRequestInfo |
| 27 : public base::RefCountedThreadSafe<BackgroundFetchRequestInfo> { |
| 23 public: | 28 public: |
| 24 BackgroundFetchRequestInfo(); | |
| 25 BackgroundFetchRequestInfo(int request_index, | 29 BackgroundFetchRequestInfo(int request_index, |
| 26 const ServiceWorkerFetchRequest& fetch_request); | 30 const ServiceWorkerFetchRequest& fetch_request); |
| 27 // TODO(harkness): Remove copy constructor once the final (non-map-based) | |
| 28 // state management is in place. | |
| 29 BackgroundFetchRequestInfo(const BackgroundFetchRequestInfo& request); | |
| 30 ~BackgroundFetchRequestInfo(); | |
| 31 | 31 |
| 32 // Returns the index of this request in the larger Background Fetch fetch. | 32 // Returns the index of this request in the larger Background Fetch fetch. |
| 33 // Should only be consumed by the BackgroundFetchDataManager. | 33 // Should only be consumed by the BackgroundFetchDataManager. |
| 34 int request_index() const { return request_index_; } | 34 int request_index() const { return request_index_; } |
| 35 | 35 |
| 36 // Returns the Fetch API request object this object encapsulates. | 36 // Returns the Fetch API request object this object encapsulates. |
| 37 const ServiceWorkerFetchRequest& fetch_request() const { | 37 const ServiceWorkerFetchRequest& fetch_request() const { |
| 38 return fetch_request_; | 38 return fetch_request_; |
| 39 } | 39 } |
| 40 | 40 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 59 } | 59 } |
| 60 | 60 |
| 61 int64_t received_bytes() const { return received_bytes_; } | 61 int64_t received_bytes() const { return received_bytes_; } |
| 62 void set_received_bytes(int64_t received_bytes) { | 62 void set_received_bytes(int64_t received_bytes) { |
| 63 received_bytes_ = received_bytes; | 63 received_bytes_ = received_bytes; |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool IsComplete() const; | 66 bool IsComplete() const; |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 friend class base::RefCountedThreadSafe<BackgroundFetchRequestInfo>; |
| 70 |
| 71 ~BackgroundFetchRequestInfo(); |
| 72 |
| 69 // Index of this request within a Background Fetch registration. | 73 // Index of this request within a Background Fetch registration. |
| 70 int request_index_ = kInvalidBackgroundFetchRequestIndex; | 74 int request_index_ = kInvalidBackgroundFetchRequestIndex; |
| 71 | 75 |
| 72 // The request information provided by the developer. | 76 // The request information provided by the developer. |
| 73 ServiceWorkerFetchRequest fetch_request_; | 77 ServiceWorkerFetchRequest fetch_request_; |
| 74 | 78 |
| 75 std::string download_guid_; | 79 std::string download_guid_; |
| 76 | 80 |
| 77 // The following members do not need to be persisted, they can be reset after | 81 // The following members do not need to be persisted, they can be reset after |
| 78 // a chrome restart. | 82 // a chrome restart. |
| 79 DownloadItem::DownloadState state_ = | 83 DownloadItem::DownloadState state_ = |
| 80 DownloadItem::DownloadState::MAX_DOWNLOAD_STATE; | 84 DownloadItem::DownloadState::MAX_DOWNLOAD_STATE; |
| 81 DownloadInterruptReason interrupt_reason_ = | 85 DownloadInterruptReason interrupt_reason_ = |
| 82 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE; | 86 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE; |
| 83 base::FilePath file_path_; | 87 base::FilePath file_path_; |
| 84 int64_t received_bytes_ = 0; | 88 int64_t received_bytes_ = 0; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchRequestInfo); |
| 85 }; | 91 }; |
| 86 | 92 |
| 87 } // namespace content | 93 } // namespace content |
| 88 | 94 |
| 89 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_REQUEST_INFO_H_ | 95 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_REQUEST_INFO_H_ |
| OLD | NEW |