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

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: Fixed destructor threading and nits 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)) {
28 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Peter Beverloo 2017/03/09 15:18:57 Does this live in its entirety on the IO thread no
harkness 2017/03/09 18:35:31 Done.
29 }
24 30
25 BackgroundFetchJobController::~BackgroundFetchJobController() = default; 31 BackgroundFetchJobController::~BackgroundFetchJobController() = default;
26 32
27 void BackgroundFetchJobController::ProcessJob( 33 void BackgroundFetchJobController::Shutdown() {
28 const std::string& job_guid, 34 // TODO(harkness): Remove any observers.
29 BackgroundFetchJobData* job_data) { 35 // TODO(harkness): Write final status to the DataManager. After this call, the
30 DCHECK_CURRENTLY_ON(BrowserThread::IO); 36 // |job_data_| is no longer valid.
31 DCHECK(job_data); 37 job_data_.reset(nullptr);
38 }
39
40 void BackgroundFetchJobController::StartProcessing() {
41 DCHECK(job_data_);
42
32 const BackgroundFetchRequestInfo& fetch_request = 43 const BackgroundFetchRequestInfo& fetch_request =
33 job_data->GetNextBackgroundFetchRequestInfo(); 44 job_data_->GetNextBackgroundFetchRequestInfo();
34 ProcessRequest(job_guid, fetch_request); 45 ProcessRequest(fetch_request);
35 46
36 // Currently this only supports jobs of size 1. 47 // Currently this only supports jobs of size 1.
37 // TODO(crbug.com/692544) 48 // TODO(crbug.com/692544)
38 DCHECK(!job_data->HasRequestsRemaining()); 49 DCHECK(!job_data_->HasRequestsRemaining());
39
40 // TODO(harkness): Save the BackgroundFetchJobData so that when the download
41 // completes we can notify the DataManager.
42 } 50 }
43 51
44 void BackgroundFetchJobController::ProcessRequest( 52 void BackgroundFetchJobController::ProcessRequest(
45 const std::string& job_guid,
46 const BackgroundFetchRequestInfo& fetch_request) { 53 const BackgroundFetchRequestInfo& fetch_request) {
47 // First add the new request to the internal map tracking in-progress 54 // 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. 55 // TODO(harkness): Check if the download is already in progress or completed.
52 56
53 // Send the fetch request to the DownloadManager. 57 // Send the fetch request to the DownloadManager.
54 std::unique_ptr<DownloadUrlParameters> params( 58 std::unique_ptr<DownloadUrlParameters> params(
55 base::MakeUnique<DownloadUrlParameters>( 59 base::MakeUnique<DownloadUrlParameters>(
56 fetch_request.url(), storage_partition_->GetURLRequestContext())); 60 fetch_request.url(), storage_partition_->GetURLRequestContext()));
57 // TODO(harkness): Currently this is the only place the browser_context is 61 // 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. 62 // used. Evaluate whether we can just pass in the download manager explicitly.
59 BrowserContext::GetDownloadManager(browser_context_) 63 BrowserContext::GetDownloadManager(browser_context_)
60 ->DownloadUrl(std::move(params)); 64 ->DownloadUrl(std::move(params));
61 } 65 }
62 66
63 } // namespace content 67 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698