OLD | NEW |
| (Empty) |
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 #include "content/browser/background_fetch/background_fetch_job_response_data.h" | |
6 | |
7 #include "base/time/time.h" | |
8 #include "content/browser/background_fetch/background_fetch_request_info.h" | |
9 #include "url/gurl.h" | |
10 | |
11 namespace content { | |
12 | |
13 BackgroundFetchJobResponseData::BackgroundFetchJobResponseData( | |
14 size_t num_requests, | |
15 const BackgroundFetchResponseCompleteCallback& completion_callback) | |
16 : num_requests_(num_requests), | |
17 completion_callback_(std::move(completion_callback)) {} | |
18 | |
19 BackgroundFetchJobResponseData::~BackgroundFetchJobResponseData() {} | |
20 | |
21 void BackgroundFetchJobResponseData::AddResponse( | |
22 const BackgroundFetchRequestInfo& request_info, | |
23 std::unique_ptr<BlobHandle> response) { | |
24 auto urls = base::MakeUnique<std::vector<GURL>>(std::vector<GURL>()); | |
25 urls->push_back(request_info.GetURL()); | |
26 | |
27 // TODO(harkness): Fill in headers and status code/text. | |
28 auto headers = base::MakeUnique<ServiceWorkerHeaderMap>(); | |
29 responses_.emplace_back( | |
30 std::move(urls), 0 /* status code */, std::string("") /* status text */, | |
31 blink::WebServiceWorkerResponseTypeBasic, std::move(headers), | |
32 response->GetUUID(), request_info.received_bytes(), GURL(), | |
33 blink::WebServiceWorkerResponseErrorUnknown, | |
34 base::Time() /* response time */, false /* is_in_cache_storage */, | |
35 std::string("") /* cache_storage_cache_name */, | |
36 base::MakeUnique<ServiceWorkerHeaderList>()); | |
37 | |
38 blobs_.push_back(std::move(response)); | |
39 completed_requests_++; | |
40 | |
41 if (completed_requests_ == num_requests_) { | |
42 std::move(completion_callback_) | |
43 .Run(std::move(responses_), std::move(blobs_)); | |
44 } | |
45 } | |
46 | |
47 bool BackgroundFetchJobResponseData::IsComplete() { | |
48 return completed_requests_ == num_requests_; | |
49 } | |
50 | |
51 } // namespace content | |
OLD | NEW |