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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_PUBLIC_BROWSER_BACKGROUND_FETCH_RESPONSE_H_ 6 #define CONTENT_PUBLIC_BROWSER_BACKGROUND_FETCH_RESPONSE_H_ 7 8 #include <vector> 9 10 #include "base/files/file_path.h" 11 #include "base/optional.h" 12 #include "base/time/time.h" 13 #include "content/common/content_export.h" 14 #include "net/http/http_response_headers.h" 15 #include "storage/browser/blob/blob_data_handle.h" 16 #include "url/gurl.h" 17 18 namespace content { 19 20 // Contains the response after a background fetch has started. 21 struct CONTENT_EXPORT BackgroundFetchResponse { 22 BackgroundFetchResponse( 23 const std::vector<GURL>& url_chain, 24 const scoped_refptr<const net::HttpResponseHeaders>& headers); 25 26 ~BackgroundFetchResponse(); 27 28 const std::vector<GURL> url_chain; 29 const scoped_refptr<const net::HttpResponseHeaders> headers; // May be null. 30 31 private: 32 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchResponse); 33 }; 34 35 struct CONTENT_EXPORT BackgroundFetchResult { 36 // Failures that happen after the download has already started and are 37 // reported via |BackgroundFetchDelegate::Client::OnDownloadComplete|. 38 enum class FailureReason { 39 // None of below failures occurred, although the fetch could still have 40 // failed with an error code such as 404. 41 NONE, 42 43 // Used when the download has been aborted after reaching a threshold where 44 // it was decided it is not worth attempting to start again. This could be 45 // either due to a specific number of failed retry attempts or a specific 46 // number of wasted bytes due to the download restarting. 47 NETWORK, 48 49 // Used when the download was not completed before the timeout. 50 TIMEDOUT, 51 52 // Used when the download was cancelled by the user. 53 CANCELLED, 54 55 // Catch-all error. Used when the failure reason is unknown or not exposed 56 // to the developer. 57 FETCH_ERROR, 58 }; 59 60 // Constructor for failed downloads. 61 BackgroundFetchResult(std::unique_ptr<BackgroundFetchResponse> response, 62 base::Time response_time, 63 FailureReason failure_reason); 64 65 // Constructor for successful downloads. 66 BackgroundFetchResult(std::unique_ptr<BackgroundFetchResponse> response, 67 base::Time response_time, 68 const base::FilePath& path, 69 base::Optional<storage::BlobDataHandle> blob_handle, 70 uint64_t file_size); 71 72 ~BackgroundFetchResult(); 73 74 std::unique_ptr<BackgroundFetchResponse> response; 75 const base::Time response_time; 76 const base::FilePath file_path; 77 base::Optional<storage::BlobDataHandle> blob_handle; 78 const uint64_t file_size = 0; 79 FailureReason failure_reason; 80 81 private: 82 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchResult); 83 }; 84 85 } // namespace content 86 87 #endif // CONTENT_PUBLIC_BROWSER_BACKGROUND_FETCH_RESPONSE_H_ 88