Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: content/browser/background_fetch/background_fetch_job_info.cc

Issue 2786783002: Dispatch a bare Service Worker event for a finished Background Fetch (Closed)
Patch Set: Dispatch a bare Service Worker event for a finished Background Fetch Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_info.h"
6
7 #include "base/guid.h"
8
9 #include "content/browser/background_fetch/background_fetch_job_response_data.h"
10 #include "content/browser/background_fetch/background_fetch_request_info.h"
11
12 namespace content {
13
14 BackgroundFetchJobInfo::BackgroundFetchJobInfo(
15 const std::string& tag,
16 const url::Origin& origin,
17 int64_t service_worker_registration_id)
18 : guid_(base::GenerateGUID()),
19 tag_(tag),
20 origin_(origin),
21 service_worker_registration_id_(service_worker_registration_id) {}
22
23 BackgroundFetchJobInfo::~BackgroundFetchJobInfo() = default;
24
25 void BackgroundFetchJobInfo::set_job_response_data(
26 std::unique_ptr<BackgroundFetchJobResponseData> job_response_data) {
27 job_response_data_ = std::move(job_response_data);
28 }
29
30 bool BackgroundFetchJobInfo::IsComplete() const {
31 return !HasRequestsRemaining() && active_requests_.empty();
32 }
33
34 bool BackgroundFetchJobInfo::HasRequestsRemaining() const {
35 return next_request_index_ != num_requests_;
36 }
37
38 void BackgroundFetchJobInfo::AddActiveRequest(
39 std::unique_ptr<BackgroundFetchRequestInfo> request) {
40 active_requests_.insert(std::move(request));
41 next_request_index_++;
42 }
43
44 BackgroundFetchRequestInfo* BackgroundFetchJobInfo::GetActiveRequest(
45 const std::string& request_guid) const {
46 for (auto& request : active_requests_) {
47 if (request->guid() == request_guid)
48 return request.get();
49 }
50 return nullptr;
51 }
52
53 void BackgroundFetchJobInfo::RemoveActiveRequest(
54 const std::string& request_guid) {
55 // active_requests_.erase(request_guid);
56 for (const auto& request : active_requests_) {
57 if (request->guid() == request_guid) {
58 active_requests_.erase(request);
59 return;
60 }
61 }
62 }
63
64 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698