Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: content/browser/background_fetch/background_fetch_batch_manager.cc

Issue 2708943002: Create the BackgroundFetchBatchManager and initiate a download. (Closed)
Patch Set: Integrated code review comments and added BackgroundFetchDataManager::BatchData which feeds FetchRe… Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/memory/ptr_util.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/download_manager.h"
15 #include "content/public/browser/storage_partition.h"
16
17 namespace content {
18
19 BackgroundFetchBatchManager::BackgroundFetchBatchManager(
20 BrowserContext* browser_context,
21 StoragePartition* storage_partition)
22 : browser_context_(browser_context),
23 storage_partition_(storage_partition) {}
24
25 BackgroundFetchBatchManager::~BackgroundFetchBatchManager() = default;
26
27 void BackgroundFetchBatchManager::ProcessBatch(
28 const std::string& batch_guid,
29 BackgroundFetchDataManager::BatchData* batch_data) {
30 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
31 const FetchRequest& fetch_request = batch_data->GetNextFetchRequest();
32 ProcessRequest(batch_guid, fetch_request);
33
34 // Currently this only supports batches of size 1.
35 // TODO(crbug.com/692544)
36 DCHECK(!batch_data->HasRequestsRemaining());
37
38 // TODO(harkness): Save the BatchData so that when the download completes we
39 // can notify the DataManager.
40 }
41
42 void BackgroundFetchBatchManager::ProcessRequest(
43 const std::string& batch_guid,
44 const FetchRequest& fetch_request) {
45 // First add the new request to the internal map tracking in-progress
46 // requests.
47 fetch_map_[batch_guid] = std::move(fetch_request);
48
49 // TODO(harkness): Check if the download is already in progress or completed.
50
51 // Send the fetch request to the DownloadManager.
52 std::unique_ptr<DownloadUrlParameters> params(
53 base::MakeUnique<DownloadUrlParameters>(
54 fetch_request.url(), storage_partition_->GetURLRequestContext()));
55 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
56 ->DownloadUrl(std::move(params));
57 }
58
59 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698