Chromium Code Reviews| 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 #include "content/browser/background_fetch/background_fetch_data_manager.h" | 5 #include "content/browser/background_fetch/background_fetch_data_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | |
| 7 #include "content/browser/background_fetch/background_fetch_context.h" | 8 #include "content/browser/background_fetch/background_fetch_context.h" |
| 8 #include "content/browser/background_fetch/fetch_request.h" | 9 #include "content/browser/background_fetch/background_fetch_job_info.h" |
| 10 #include "content/browser/background_fetch/background_fetch_request_info.h" | |
| 9 | 11 |
| 10 namespace content { | 12 namespace content { |
| 11 | 13 |
| 12 BackgroundFetchDataManager::BackgroundFetchDataManager( | 14 BackgroundFetchDataManager::BackgroundFetchDataManager( |
| 13 BackgroundFetchContext* background_fetch_context) | 15 BackgroundFetchContext* background_fetch_context) |
| 14 : background_fetch_context_(background_fetch_context) { | 16 : background_fetch_context_(background_fetch_context) { |
| 15 DCHECK(background_fetch_context_); | 17 DCHECK(background_fetch_context_); |
| 16 // TODO(harkness) Read from persistent storage and recreate requests. | 18 // TODO(harkness) Read from persistent storage and recreate requests. |
| 17 } | 19 } |
| 18 | 20 |
| 19 BackgroundFetchDataManager::~BackgroundFetchDataManager() {} | 21 BackgroundFetchDataManager::~BackgroundFetchDataManager() = default; |
| 20 | 22 |
| 21 void BackgroundFetchDataManager::CreateRequest( | 23 BackgroundFetchJobData* BackgroundFetchDataManager::CreateRequest( |
| 22 const FetchRequest& fetch_request) { | 24 const BackgroundFetchJobInfo& job_info, |
| 23 FetchIdentifier id(fetch_request.service_worker_registration_id(), | 25 BackgroundFetchRequestInfos& request_infos) { |
| 24 fetch_request.tag()); | 26 JobIdentifier id(job_info.service_worker_registration_id(), job_info.tag()); |
| 25 if (fetch_map_.find(id) != fetch_map_.end()) { | 27 // Ensure that this is not a duplicate request. |
| 26 DLOG(ERROR) << "Origin " << fetch_request.origin() | 28 if (service_worker_tag_map_.find(id) != service_worker_tag_map_.end()) { |
| 27 << " has already created a fetch request with tag " | 29 DLOG(ERROR) << "Origin " << job_info.origin() |
| 28 << fetch_request.tag(); | 30 << " has already created a batch request with tag " |
| 31 << job_info.tag(); | |
|
Peter Beverloo
2017/02/28 03:32:54
nit: We probably should move to DVLOG at some poin
harkness
2017/02/28 11:31:08
Done.
| |
| 29 // TODO(harkness) Figure out how to return errors like this. | 32 // TODO(harkness) Figure out how to return errors like this. |
| 30 return; | 33 return nullptr; |
| 31 } | 34 } |
| 32 fetch_map_[id] = fetch_request; | 35 if (batch_map_.find(job_info.guid()) != batch_map_.end()) { |
| 36 DLOG(ERROR) << "Job with UID " << job_info.guid() << " already exists."; | |
| 37 // TODO(harkness) Figure out how to return errors like this. | |
| 38 return nullptr; | |
| 39 } | |
| 40 | |
| 41 // Add the request to our maps and return a JobData to track the individual | |
| 42 // files in the request. | |
| 43 service_worker_tag_map_[id] = job_info.guid(); | |
| 44 batch_map_[job_info.guid()] = | |
|
Peter Beverloo
2017/02/28 03:32:54
note: We need to remove data from the batch_map_ a
harkness
2017/02/28 11:31:08
TODO added.
| |
| 45 base::MakeUnique<BackgroundFetchJobData>(request_infos); | |
|
Peter Beverloo
2017/02/28 03:32:54
std::move(), and pass by value to the constructor
harkness
2017/02/28 11:31:08
Done. I think I've got too many std::moves here, b
| |
| 46 return batch_map_[job_info.guid()].get(); | |
| 33 } | 47 } |
| 34 | 48 |
| 35 } // namespace content | 49 } // namespace content |
| OLD | NEW |