Chromium Code Reviews| Index: content/browser/background_fetch/background_fetch_job_controller.cc |
| diff --git a/content/browser/background_fetch/background_fetch_job_controller.cc b/content/browser/background_fetch/background_fetch_job_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6c52a2bda5ab79b79296f166900468684cf2cc08 |
| --- /dev/null |
| +++ b/content/browser/background_fetch/background_fetch_job_controller.cc |
| @@ -0,0 +1,63 @@ |
| +// 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_job_controller.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 { |
| + |
| +BackgroundFetchJobController::BackgroundFetchJobController( |
| + BrowserContext* browser_context, |
| + StoragePartition* storage_partition) |
| + : browser_context_(browser_context), |
| + storage_partition_(storage_partition) {} |
| + |
| +BackgroundFetchJobController::~BackgroundFetchJobController() = default; |
| + |
| +void BackgroundFetchJobController::ProcessJob( |
| + const std::string& job_guid, |
| + BackgroundFetchJobData* job_data) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + DCHECK(job_data); |
| + const BackgroundFetchRequestInfo& fetch_request = |
| + job_data->GetNextBackgroundFetchRequestInfo(); |
| + ProcessRequest(job_guid, fetch_request); |
| + |
| + // Currently this only supports jobs of size 1. |
| + // TODO(crbug.com/692544) |
| + DCHECK(!job_data->HasRequestsRemaining()); |
| + |
| + // TODO(harkness): Save the BackgroundFetchJobData so that when the download |
| + // completes we can notify the DataManager. |
| +} |
| + |
| +void BackgroundFetchJobController::ProcessRequest( |
| + const std::string& job_guid, |
| + const BackgroundFetchRequestInfo& fetch_request) { |
| + // First add the new request to the internal map tracking in-progress |
| + // requests. |
| + fetch_map_[job_guid] = std::move(fetch_request); |
|
Peter Beverloo
2017/02/28 03:32:54
Can't move a const&, so this is a copy
harkness
2017/02/28 11:31:08
fetch_map_ is being refactored later today, so I j
|
| + |
| + // 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())); |
| + // TODO(harkness): Currently this is the only place the browser_context is |
| + // used. Evaluate whether we can just pass in the download manager explicitly. |
| + BrowserContext::GetDownloadManager(browser_context_) |
| + ->DownloadUrl(std::move(params)); |
| +} |
| + |
| +} // namespace content |