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_job_controller.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 BackgroundFetchJobController::BackgroundFetchJobController( | |
20 BrowserContext* browser_context, | |
21 StoragePartition* storage_partition) | |
22 : browser_context_(browser_context), | |
23 storage_partition_(storage_partition) {} | |
24 | |
25 BackgroundFetchJobController::~BackgroundFetchJobController() = default; | |
26 | |
27 void BackgroundFetchJobController::ProcessJob( | |
28 const std::string& job_guid, | |
29 BackgroundFetchJobData* job_data) { | |
30 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
31 DCHECK(job_data); | |
32 const BackgroundFetchRequestInfo& fetch_request = | |
33 job_data->GetNextBackgroundFetchRequestInfo(); | |
34 ProcessRequest(job_guid, fetch_request); | |
35 | |
36 // Currently this only supports jobs of size 1. | |
37 // TODO(crbug.com/692544) | |
38 DCHECK(!job_data->HasRequestsRemaining()); | |
39 | |
40 // TODO(harkness): Save the BackgroundFetchJobData so that when the download | |
41 // completes we can notify the DataManager. | |
42 } | |
43 | |
44 void BackgroundFetchJobController::ProcessRequest( | |
45 const std::string& job_guid, | |
46 const BackgroundFetchRequestInfo& fetch_request) { | |
47 // First add the new request to the internal map tracking in-progress | |
48 // requests. | |
49 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
| |
50 | |
51 // TODO(harkness): Check if the download is already in progress or completed. | |
52 | |
53 // Send the fetch request to the DownloadManager. | |
54 std::unique_ptr<DownloadUrlParameters> params( | |
55 base::MakeUnique<DownloadUrlParameters>( | |
56 fetch_request.url(), storage_partition_->GetURLRequestContext())); | |
57 // TODO(harkness): Currently this is the only place the browser_context is | |
58 // used. Evaluate whether we can just pass in the download manager explicitly. | |
59 BrowserContext::GetDownloadManager(browser_context_) | |
60 ->DownloadUrl(std::move(params)); | |
61 } | |
62 | |
63 } // namespace content | |
OLD | NEW |