Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_batch_manager.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "content/public/browser/browser_context.h" | |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 #include "content/public/browser/download_manager.h" | |
| 14 #include "content/public/browser/storage_partition.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 BackgroundFetchBatchManager::BackgroundFetchBatchManager( | |
| 19 BrowserContext* browser_context, | |
| 20 StoragePartition* storage_partition) | |
| 21 : browser_context_(browser_context), | |
| 22 storage_partition_(storage_partition) {} | |
| 23 | |
| 24 BackgroundFetchBatchManager::~BackgroundFetchBatchManager() = default; | |
| 25 | |
| 26 void BackgroundFetchBatchManager::ProcessBatch( | |
| 27 const std::string& batch_uid, | |
| 28 const std::vector<FetchRequest>& requests) { | |
| 29 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 30 // 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.
| |
| 31 DCHECK_EQ(1U, requests.size()); | |
| 32 ProcessRequest(batch_uid, requests[0]); | |
| 33 } | |
| 34 | |
| 35 void BackgroundFetchBatchManager::ProcessRequest( | |
| 36 const std::string& batch_uid, | |
| 37 const FetchRequest& fetch_request) { | |
| 38 // First add the new request to the internal map tracking in-progress | |
| 39 // requests. | |
| 40 fetch_map[batch_uid] = std::move(fetch_request); | |
| 41 | |
| 42 // TODO(harkness): Check if the download is already in progress or completed. | |
| 43 | |
| 44 // Send the fetch request to the DownloadManager. | |
| 45 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.
| |
| 46 new content::DownloadUrlParameters( | |
|
Peter Beverloo
2017/02/23 12:14:55
nit:
base::MakeUnique<DownloadUrlParameters>(fetc
harkness
2017/02/23 17:08:41
Done.
| |
| 47 fetch_request.url(), storage_partition_->GetURLRequestContext())); | |
| 48 BrowserContext::GetDownloadManager(browser_context_) | |
| 49 ->DownloadUrl(std::move(params)); | |
| 50 } | |
| 51 | |
| 52 } // namespace content | |
| OLD | NEW |