blob: e13df709f2f45a2feb56e08a405e5dabaab5afb8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/background_fetch/background_fetch_request_info.h"
#include <utility>
#include "base/guid.h"
#include "base/strings/string_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "components/download/public/common/download_item.h"
#include "content/public/browser/background_fetch_response.h"
#include "content/public/browser/browser_thread.h"
#include "net/http/http_response_headers.h"
namespace content {
BackgroundFetchRequestInfo::BackgroundFetchRequestInfo(
int request_index,
const ServiceWorkerFetchRequest& fetch_request)
: RefCountedDeleteOnSequence<BackgroundFetchRequestInfo>(
base::SequencedTaskRunnerHandle::Get()),
request_index_(request_index),
fetch_request_(fetch_request) {}
BackgroundFetchRequestInfo::~BackgroundFetchRequestInfo() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void BackgroundFetchRequestInfo::InitializeDownloadGuid() {
DCHECK(download_guid_.empty());
download_guid_ = base::GenerateGUID();
}
void BackgroundFetchRequestInfo::SetDownloadGuid(
const std::string& download_guid) {
DCHECK(!download_guid.empty());
DCHECK(download_guid_.empty());
download_guid_ = download_guid;
}
void BackgroundFetchRequestInfo::PopulateWithResponse(
std::unique_ptr<BackgroundFetchResponse> response) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
url_chain_ = response->url_chain;
// |headers| can be null when the request fails.
if (!response->headers)
return;
// The response code, text and headers all are stored in the
// net::HttpResponseHeaders object, shared by the |download_item|.
response_code_ = response->headers->response_code();
response_text_ = response->headers->GetStatusText();
size_t iter = 0;
std::string name, value;
while (response->headers->EnumerateHeaderLines(&iter, &name, &value))
response_headers_[base::ToLowerASCII(name)] = value;
}
void BackgroundFetchRequestInfo::SetResult(
std::unique_ptr<BackgroundFetchResult> result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
result_ = std::move(result);
}
int BackgroundFetchRequestInfo::GetResponseCode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return response_code_;
}
const std::string& BackgroundFetchRequestInfo::GetResponseText() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return response_text_;
}
const std::map<std::string, std::string>&
BackgroundFetchRequestInfo::GetResponseHeaders() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return response_headers_;
}
const std::vector<GURL>& BackgroundFetchRequestInfo::GetURLChain() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return url_chain_;
}
const base::Optional<storage::BlobDataHandle>&
BackgroundFetchRequestInfo::GetBlobDataHandle() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(result_);
return result_->blob_handle;
}
const base::FilePath& BackgroundFetchRequestInfo::GetFilePath() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(result_);
return result_->file_path;
}
int64_t BackgroundFetchRequestInfo::GetFileSize() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(result_);
return result_->file_size;
}
const base::Time& BackgroundFetchRequestInfo::GetResponseTime() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(result_);
return result_->response_time;
}
bool BackgroundFetchRequestInfo::IsResultSuccess() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(result_);
return result_->failure_reason == BackgroundFetchResult::FailureReason::NONE;
}
} // namespace content
|