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

Side by Side Diff: content/browser/background_fetch/background_fetch_context.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_context.h" 5 #include "content/browser/background_fetch/background_fetch_context.h"
6 6
7 #include "content/browser/background_fetch/background_fetch_job_info.h" 7 #include "content/browser/background_fetch/background_fetch_job_info.h"
8 #include "content/browser/background_fetch/background_fetch_request_info.h" 8 #include "content/browser/background_fetch/background_fetch_request_info.h"
9 #include "content/browser/service_worker/service_worker_context_wrapper.h" 9 #include "content/browser/service_worker/service_worker_context_wrapper.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/download_manager.h" 11 #include "content/public/browser/download_manager.h"
13 #include "content/public/browser/storage_partition.h" 12 #include "content/public/browser/storage_partition.h"
14 13
15 namespace content { 14 namespace content {
16 15
17 BackgroundFetchContext::BackgroundFetchContext( 16 BackgroundFetchContext::BackgroundFetchContext(
18 BrowserContext* browser_context, 17 BrowserContext* browser_context,
19 StoragePartition* storage_partition, 18 StoragePartition* storage_partition,
20 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) 19 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context)
21 : service_worker_context_(service_worker_context), 20 : browser_context_(browser_context),
22 background_fetch_job_controller_(browser_context, storage_partition), 21 storage_partition_(storage_partition),
22 service_worker_context_(service_worker_context),
23 background_fetch_data_manager_(this) { 23 background_fetch_data_manager_(this) {
24 DCHECK_CURRENTLY_ON(BrowserThread::UI); 24 DCHECK_CURRENTLY_ON(BrowserThread::UI);
25 // TODO(harkness): BackgroundFetchContext should have 25 // TODO(harkness): BackgroundFetchContext should have
26 // ServiceWorkerContextObserver as a parent class and should register as an 26 // ServiceWorkerContextObserver as a parent class and should register as an
27 // observer here. 27 // observer here.
28 } 28 }
29 29
30 BackgroundFetchContext::~BackgroundFetchContext() { 30 BackgroundFetchContext::~BackgroundFetchContext() {
31 DCHECK_CURRENTLY_ON(BrowserThread::UI); 31 DCHECK_CURRENTLY_ON(BrowserThread::UI);
32 } 32 }
33 33
34 void BackgroundFetchContext::Init() { 34 void BackgroundFetchContext::Init() {
35 DCHECK_CURRENTLY_ON(BrowserThread::UI); 35 DCHECK_CURRENTLY_ON(BrowserThread::UI);
36 36
37 // TODO(harkness): Create the Download observer. 37 // TODO(harkness): Create the Download observer.
38 } 38 }
39 39
40 void BackgroundFetchContext::Shutdown() { 40 void BackgroundFetchContext::Shutdown() {
41 DCHECK_CURRENTLY_ON(BrowserThread::UI); 41 DCHECK_CURRENTLY_ON(BrowserThread::UI);
42
43 BrowserThread::PostTask(
44 BrowserThread::IO, FROM_HERE,
45 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this));
46 }
47
48 void BackgroundFetchContext::ShutdownOnIO() {
49 DCHECK_CURRENTLY_ON(BrowserThread::IO);
50
51 // Call Shutdown on all pending job controllers to give them a chance to flush
52 // any status to the DataManager.
53 for (auto& job : job_map_)
54 job.second->Shutdown();
42 } 55 }
43 56
44 void BackgroundFetchContext::CreateRequest( 57 void BackgroundFetchContext::CreateRequest(
45 const BackgroundFetchJobInfo& job_info, 58 const BackgroundFetchJobInfo& job_info,
46 std::vector<BackgroundFetchRequestInfo>& request_infos) { 59 std::vector<BackgroundFetchRequestInfo>& request_infos) {
60 DCHECK_CURRENTLY_ON(BrowserThread::IO);
47 DCHECK_GE(1U, request_infos.size()); 61 DCHECK_GE(1U, request_infos.size());
62
48 // Inform the data manager about the new download. 63 // Inform the data manager about the new download.
49 BackgroundFetchJobData* job_data = 64 std::unique_ptr<BackgroundFetchJobData> job_data =
50 background_fetch_data_manager_.CreateRequest(job_info, request_infos); 65 background_fetch_data_manager_.CreateRequest(job_info, request_infos);
66
51 // If job_data is null, the DataManager will have logged an error. 67 // If job_data is null, the DataManager will have logged an error.
52 if (job_data) 68 if (job_data) {
53 background_fetch_job_controller_.ProcessJob(job_info.guid(), job_data); 69 // Create a controller which drives the processing of the job. It will use
70 // the JobData to get information about individual requests for the job.
71 job_map_[job_info.guid()] = base::MakeUnique<BackgroundFetchJobController>(
72 job_info.guid(), browser_context_, storage_partition_,
73 std::move(job_data));
74 }
54 } 75 }
55 76
56 } // namespace content 77 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698