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..afecadf99a9f72426e770f6258f3bfa83a8005d9 |
| --- /dev/null |
| +++ b/content/browser/background_fetch/background_fetch_batch_manager.cc |
| @@ -0,0 +1,59 @@ |
| +// 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 "base/memory/ptr_util.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_guid, |
| + BackgroundFetchDataManager::BatchData* batch_data) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
|
Peter Beverloo
2017/02/24 02:05:15
For your consideration (not per se for this CL eit
harkness
2017/02/24 11:47:10
I think that's a really good idea, I'll switch it
|
| + const FetchRequest& fetch_request = batch_data->GetNextFetchRequest(); |
| + ProcessRequest(batch_guid, fetch_request); |
| + |
| + // Currently this only supports batches of size 1. |
| + // TODO(crbug.com/692544) |
| + DCHECK(!batch_data->HasRequestsRemaining()); |
| + |
| + // TODO(harkness): Save the BatchData so that when the download completes we |
| + // can notify the DataManager. |
| +} |
| + |
| +void BackgroundFetchBatchManager::ProcessRequest( |
| + const std::string& batch_guid, |
| + const FetchRequest& fetch_request) { |
| + // First add the new request to the internal map tracking in-progress |
| + // requests. |
| + fetch_map_[batch_guid] = 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<DownloadUrlParameters> params( |
| + base::MakeUnique<DownloadUrlParameters>( |
| + fetch_request.url(), storage_partition_->GetURLRequestContext())); |
| + BrowserContext::GetDownloadManager(browser_context_) |
|
Peter Beverloo
2017/02/24 02:05:15
Are we going to use the browser_context_ for more
harkness
2017/02/24 11:47:10
I'm not sure at this point. I'll add in a TODO to
|
| + ->DownloadUrl(std::move(params)); |
| +} |
| + |
| +} // namespace content |