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" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted_delete_on_sequence.h" |
| 14 #include "base/sequence_checker.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "content/browser/background_fetch/background_fetch_constants.h" | 16 #include "content/browser/background_fetch/background_fetch_constants.h" |
16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 #include "content/common/service_worker/service_worker_types.h" | 18 #include "content/common/service_worker/service_worker_types.h" |
18 #include "content/public/browser/download_interrupt_reasons.h" | 19 #include "content/public/browser/download_interrupt_reasons.h" |
19 #include "content/public/browser/download_item.h" | 20 #include "content/public/browser/download_item.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 | 24 |
24 class DownloadItem; | 25 class DownloadItem; |
25 | 26 |
26 // Simple class to encapsulate the components of a fetch request. | 27 // Simple class to encapsulate the components of a fetch request. |
27 // TODO(peter): This can likely change to have a single owner, and thus become | 28 // TODO(peter): This can likely change to have a single owner, and thus become |
28 // an std::unique_ptr<>, when persistent storage has been implemented. | 29 // an std::unique_ptr<>, when persistent storage has been implemented. |
29 class CONTENT_EXPORT BackgroundFetchRequestInfo | 30 class CONTENT_EXPORT BackgroundFetchRequestInfo |
30 : public base::RefCountedThreadSafe<BackgroundFetchRequestInfo> { | 31 : public base::RefCountedDeleteOnSequence<BackgroundFetchRequestInfo> { |
31 public: | 32 public: |
32 BackgroundFetchRequestInfo(int request_index, | 33 BackgroundFetchRequestInfo(int request_index, |
33 const ServiceWorkerFetchRequest& fetch_request); | 34 const ServiceWorkerFetchRequest& fetch_request); |
34 | 35 |
35 // Populates the cached state for the in-progress |download_item|. | 36 // Populates the cached state for the in-progress |download_item|. |
36 void PopulateDownloadState(DownloadItem* download_item, | 37 void PopulateDownloadStateOnUI( |
37 DownloadInterruptReason download_interrupt_reason); | 38 DownloadItem* download_item, |
| 39 DownloadInterruptReason download_interrupt_reason); |
| 40 |
| 41 void SetDownloadStatePopulated(); |
38 | 42 |
39 // Populates the response portion of this object from the information made | 43 // Populates the response portion of this object from the information made |
40 // available in the |download_item|. | 44 // available in the |download_item|. |
41 void PopulateResponseFromDownloadItem(DownloadItem* download_item); | 45 void PopulateResponseFromDownloadItemOnUI(DownloadItem* download_item); |
| 46 |
| 47 void SetResponseDataPopulated(); |
42 | 48 |
43 // Returns the index of this request within a Background Fetch registration. | 49 // Returns the index of this request within a Background Fetch registration. |
44 int request_index() const { return request_index_; } | 50 int request_index() const { return request_index_; } |
45 | 51 |
46 // Returns the Fetch API Request object that details the developer's request. | 52 // Returns the Fetch API Request object that details the developer's request. |
47 const ServiceWorkerFetchRequest& fetch_request() const { | 53 const ServiceWorkerFetchRequest& fetch_request() const { |
48 return fetch_request_; | 54 return fetch_request_; |
49 } | 55 } |
50 | 56 |
51 // Returns the response code for the download. Available for both successful | 57 // Returns the response code for the download. Available for both successful |
(...skipping 14 matching lines...) Expand all Loading... |
66 // Returns the absolute path to the file in which the response is stored. | 72 // Returns the absolute path to the file in which the response is stored. |
67 const base::FilePath& GetFilePath() const; | 73 const base::FilePath& GetFilePath() const; |
68 | 74 |
69 // Returns the size of the file containing the response, in bytes. | 75 // Returns the size of the file containing the response, in bytes. |
70 int64_t GetFileSize() const; | 76 int64_t GetFileSize() const; |
71 | 77 |
72 // Returns the time at which the response was completed. | 78 // Returns the time at which the response was completed. |
73 const base::Time& GetResponseTime() const; | 79 const base::Time& GetResponseTime() const; |
74 | 80 |
75 private: | 81 private: |
76 friend class base::RefCountedThreadSafe<BackgroundFetchRequestInfo>; | 82 friend class base::RefCountedDeleteOnSequence<BackgroundFetchRequestInfo>; |
| 83 friend class base::DeleteHelper<BackgroundFetchRequestInfo>; |
77 friend class BackgroundFetchCrossOriginFilterTest; | 84 friend class BackgroundFetchCrossOriginFilterTest; |
78 | 85 |
79 ~BackgroundFetchRequestInfo(); | 86 ~BackgroundFetchRequestInfo(); |
80 | 87 |
81 // ---- Data associated with the request ------------------------------------- | 88 // ---- Data associated with the request ------------------------------------- |
82 | 89 |
83 int request_index_ = kInvalidBackgroundFetchRequestIndex; | 90 int request_index_ = kInvalidBackgroundFetchRequestIndex; |
84 ServiceWorkerFetchRequest fetch_request_; | 91 ServiceWorkerFetchRequest fetch_request_; |
85 | 92 |
86 // ---- Data associated with the in-progress download ------------------------ | 93 // ---- Data associated with the in-progress download ------------------------ |
(...skipping 11 matching lines...) Expand all Loading... |
98 // ---- Data associated with the response ------------------------------------ | 105 // ---- Data associated with the response ------------------------------------ |
99 | 106 |
100 // Indicates whether response data has been populated. | 107 // Indicates whether response data has been populated. |
101 bool response_data_populated_ = false; | 108 bool response_data_populated_ = false; |
102 | 109 |
103 std::vector<GURL> url_chain_; | 110 std::vector<GURL> url_chain_; |
104 base::FilePath file_path_; | 111 base::FilePath file_path_; |
105 int64_t file_size_ = 0; | 112 int64_t file_size_ = 0; |
106 base::Time response_time_; | 113 base::Time response_time_; |
107 | 114 |
| 115 SEQUENCE_CHECKER(sequence_checker_); |
| 116 |
108 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchRequestInfo); | 117 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchRequestInfo); |
109 }; | 118 }; |
110 | 119 |
111 } // namespace content | 120 } // namespace content |
112 | 121 |
113 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_REQUEST_INFO_H_ | 122 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_REQUEST_INFO_H_ |
OLD | NEW |