OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/background_fetch/background_fetch_job_controller.h" | 5 #include "content/browser/background_fetch/background_fetch_job_controller.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | |
9 | 8 |
10 #include "base/bind.h" | 9 #include "base/bind.h" |
11 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "content/browser/background_fetch/background_fetch_job_data.h" | |
12 #include "content/browser/background_fetch/background_fetch_request_info.h" | |
12 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/download_manager.h" | 15 #include "content/public/browser/download_manager.h" |
15 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 BackgroundFetchJobController::BackgroundFetchJobController( | 20 BackgroundFetchJobController::BackgroundFetchJobController( |
21 const std::string& job_guid, | |
20 BrowserContext* browser_context, | 22 BrowserContext* browser_context, |
21 StoragePartition* storage_partition) | 23 StoragePartition* storage_partition, |
24 BackgroundFetchJobData* job_data) | |
22 : browser_context_(browser_context), | 25 : browser_context_(browser_context), |
23 storage_partition_(storage_partition) {} | 26 storage_partition_(storage_partition), |
27 job_data_(base::WrapUnique(job_data)) {} | |
24 | 28 |
25 BackgroundFetchJobController::~BackgroundFetchJobController() = default; | 29 BackgroundFetchJobController::~BackgroundFetchJobController() = default; |
26 | 30 |
27 void BackgroundFetchJobController::ProcessJob( | 31 void BackgroundFetchJobController::Shutdown() { |
28 const std::string& job_guid, | 32 // TODO(harkness): Remove any observers. |
29 BackgroundFetchJobData* job_data) { | 33 // TODO(harkness): Write final status to the DataManager. After this call, the |
34 // |job_data_| is no longer valid. | |
35 job_data_.reset(nullptr); | |
36 } | |
37 | |
38 void BackgroundFetchJobController::StartProcessing() { | |
30 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 39 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
31 DCHECK(job_data); | 40 DCHECK(job_data_); |
Peter Beverloo
2017/03/08 14:27:04
nit: this DCHECK should happen in the constructor
harkness
2017/03/09 13:33:25
Done.
| |
41 | |
32 const BackgroundFetchRequestInfo& fetch_request = | 42 const BackgroundFetchRequestInfo& fetch_request = |
33 job_data->GetNextBackgroundFetchRequestInfo(); | 43 job_data_->GetNextBackgroundFetchRequestInfo(); |
34 ProcessRequest(job_guid, fetch_request); | 44 ProcessRequest(fetch_request); |
35 | 45 |
36 // Currently this only supports jobs of size 1. | 46 // Currently this only supports jobs of size 1. |
37 // TODO(crbug.com/692544) | 47 // TODO(crbug.com/692544) |
38 DCHECK(!job_data->HasRequestsRemaining()); | 48 DCHECK(!job_data_->HasRequestsRemaining()); |
39 | |
40 // TODO(harkness): Save the BackgroundFetchJobData so that when the download | |
41 // completes we can notify the DataManager. | |
42 } | 49 } |
43 | 50 |
44 void BackgroundFetchJobController::ProcessRequest( | 51 void BackgroundFetchJobController::ProcessRequest( |
45 const std::string& job_guid, | |
46 const BackgroundFetchRequestInfo& fetch_request) { | 52 const BackgroundFetchRequestInfo& fetch_request) { |
47 // First add the new request to the internal map tracking in-progress | 53 // TODO(harkness): Start the observer watching for this download. |
48 // requests. | |
49 fetch_map_[job_guid] = fetch_request; | |
50 | |
51 // TODO(harkness): Check if the download is already in progress or completed. | 54 // TODO(harkness): Check if the download is already in progress or completed. |
52 | 55 |
53 // Send the fetch request to the DownloadManager. | 56 // Send the fetch request to the DownloadManager. |
54 std::unique_ptr<DownloadUrlParameters> params( | 57 std::unique_ptr<DownloadUrlParameters> params( |
55 base::MakeUnique<DownloadUrlParameters>( | 58 base::MakeUnique<DownloadUrlParameters>( |
56 fetch_request.url(), storage_partition_->GetURLRequestContext())); | 59 fetch_request.url(), storage_partition_->GetURLRequestContext())); |
57 // TODO(harkness): Currently this is the only place the browser_context is | 60 // 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. | 61 // used. Evaluate whether we can just pass in the download manager explicitly. |
59 BrowserContext::GetDownloadManager(browser_context_) | 62 BrowserContext::GetDownloadManager(browser_context_) |
60 ->DownloadUrl(std::move(params)); | 63 ->DownloadUrl(std::move(params)); |
61 } | 64 } |
62 | 65 |
63 } // namespace content | 66 } // namespace content |
OLD | NEW |