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

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

Issue 2724783002: Make the BackgroundFetchJobController a per-job object (Closed)
Patch Set: ACTUALLY fix the compile error Created 3 years, 9 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
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 std::unique_ptr<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_(std::move(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
30 DCHECK_CURRENTLY_ON(BrowserThread::IO); 34 // |job_data_| is no longer valid.
31 DCHECK(job_data); 35 job_data_.reset(nullptr);
36 }
37
38 void BackgroundFetchJobController::StartProcessing() {
39 DCHECK(job_data_);
40
32 const BackgroundFetchRequestInfo& fetch_request = 41 const BackgroundFetchRequestInfo& fetch_request =
33 job_data->GetNextBackgroundFetchRequestInfo(); 42 job_data_->GetNextBackgroundFetchRequestInfo();
34 ProcessRequest(job_guid, fetch_request); 43 ProcessRequest(fetch_request);
35 44
36 // Currently this only supports jobs of size 1. 45 // Currently this only supports jobs of size 1.
37 // TODO(crbug.com/692544) 46 // TODO(crbug.com/692544)
38 DCHECK(!job_data->HasRequestsRemaining()); 47 DCHECK(!job_data_->HasRequestsRemaining());
39
40 // TODO(harkness): Save the BackgroundFetchJobData so that when the download
41 // completes we can notify the DataManager.
42 } 48 }
43 49
44 void BackgroundFetchJobController::ProcessRequest( 50 void BackgroundFetchJobController::ProcessRequest(
45 const std::string& job_guid,
46 const BackgroundFetchRequestInfo& fetch_request) { 51 const BackgroundFetchRequestInfo& fetch_request) {
47 // First add the new request to the internal map tracking in-progress 52 // 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. 53 // TODO(harkness): Check if the download is already in progress or completed.
52 54
53 // Send the fetch request to the DownloadManager. 55 // Send the fetch request to the DownloadManager.
54 std::unique_ptr<DownloadUrlParameters> params( 56 std::unique_ptr<DownloadUrlParameters> params(
55 base::MakeUnique<DownloadUrlParameters>( 57 base::MakeUnique<DownloadUrlParameters>(
56 fetch_request.url(), storage_partition_->GetURLRequestContext())); 58 fetch_request.url(), storage_partition_->GetURLRequestContext()));
57 // TODO(harkness): Currently this is the only place the browser_context is 59 // 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. 60 // used. Evaluate whether we can just pass in the download manager explicitly.
59 BrowserContext::GetDownloadManager(browser_context_) 61 BrowserContext::GetDownloadManager(browser_context_)
60 ->DownloadUrl(std::move(params)); 62 ->DownloadUrl(std::move(params));
61 } 63 }
62 64
63 } // namespace content 65 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698