Chromium Code Reviews| Index: content/browser/background_fetch/background_fetch_batch_manager.cc |
| diff --git a/content/browser/background_fetch/background_fetch_batch_manager.cc b/content/browser/background_fetch/background_fetch_batch_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c47c5c14f20d962acfe843ffdc023552974d67a1 |
| --- /dev/null |
| +++ b/content/browser/background_fetch/background_fetch_batch_manager.cc |
| @@ -0,0 +1,52 @@ |
| +// 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_batch_manager.h" |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/bind.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/download_manager.h" |
| +#include "content/public/browser/storage_partition.h" |
| + |
| +namespace content { |
| + |
| +BackgroundFetchBatchManager::BackgroundFetchBatchManager( |
| + BrowserContext* browser_context, |
| + StoragePartition* storage_partition) |
| + : browser_context_(browser_context), |
| + storage_partition_(storage_partition) {} |
| + |
| +BackgroundFetchBatchManager::~BackgroundFetchBatchManager() = default; |
| + |
| +void BackgroundFetchBatchManager::ProcessBatch( |
| + const std::string& batch_uid, |
| + const std::vector<FetchRequest>& requests) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + // Currently this only supports batches of size 1. |
|
Peter Beverloo
2017/02/23 12:14:55
TODO(crbug.com/123456). This is something that Ani
harkness
2017/02/23 17:08:41
Done.
|
| + DCHECK_EQ(1U, requests.size()); |
| + ProcessRequest(batch_uid, requests[0]); |
| +} |
| + |
| +void BackgroundFetchBatchManager::ProcessRequest( |
| + const std::string& batch_uid, |
| + const FetchRequest& fetch_request) { |
| + // First add the new request to the internal map tracking in-progress |
| + // requests. |
| + fetch_map[batch_uid] = std::move(fetch_request); |
| + |
| + // TODO(harkness): Check if the download is already in progress or completed. |
| + |
| + // Send the fetch request to the DownloadManager. |
| + std::unique_ptr<content::DownloadUrlParameters> params( |
|
Peter Beverloo
2017/02/23 12:14:55
nit: drop "content::". You are in that namespace.
harkness
2017/02/23 17:08:41
Done.
|
| + new content::DownloadUrlParameters( |
|
Peter Beverloo
2017/02/23 12:14:55
nit:
base::MakeUnique<DownloadUrlParameters>(fetc
harkness
2017/02/23 17:08:41
Done.
|
| + fetch_request.url(), storage_partition_->GetURLRequestContext())); |
| + BrowserContext::GetDownloadManager(browser_context_) |
| + ->DownloadUrl(std::move(params)); |
| +} |
| + |
| +} // namespace content |