Chromium Code Reviews| 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_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" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/download_manager.h" | 12 #include "content/public/browser/download_manager.h" |
| 13 #include "content/public/browser/storage_partition.h" | 13 #include "content/public/browser/storage_partition.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 BackgroundFetchContext::BackgroundFetchContext( | 17 BackgroundFetchContext::BackgroundFetchContext( |
| 18 BrowserContext* browser_context, | 18 BrowserContext* browser_context, |
| 19 StoragePartition* storage_partition, | 19 StoragePartition* storage_partition, |
| 20 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) | 20 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) |
| 21 : service_worker_context_(service_worker_context), | 21 : browser_context_(browser_context), |
| 22 background_fetch_job_controller_(browser_context, storage_partition), | 22 storage_partition_(storage_partition), |
| 23 service_worker_context_(service_worker_context), | |
| 23 background_fetch_data_manager_(this) { | 24 background_fetch_data_manager_(this) { |
| 24 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 25 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 25 // TODO(harkness): BackgroundFetchContext should have | 26 // TODO(harkness): BackgroundFetchContext should have |
| 26 // ServiceWorkerContextObserver as a parent class and should register as an | 27 // ServiceWorkerContextObserver as a parent class and should register as an |
| 27 // observer here. | 28 // observer here. |
| 28 } | 29 } |
| 29 | 30 |
| 30 BackgroundFetchContext::~BackgroundFetchContext() { | 31 BackgroundFetchContext::~BackgroundFetchContext() { |
| 31 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
|
Peter Beverloo
2017/03/08 14:27:04
There is nothing that ensures that this gets delet
harkness
2017/03/09 13:33:25
Updated it to have DeleteOnUI.
| |
| 32 } | 33 } |
| 33 | 34 |
| 34 void BackgroundFetchContext::Init() { | 35 void BackgroundFetchContext::Init() { |
| 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 36 | 37 |
| 37 // TODO(harkness): Create the Download observer. | 38 // TODO(harkness): Create the Download observer. |
| 38 } | 39 } |
| 39 | 40 |
| 40 void BackgroundFetchContext::Shutdown() { | 41 void BackgroundFetchContext::Shutdown() { |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 43 | |
| 44 BrowserThread::PostTask( | |
| 45 BrowserThread::IO, FROM_HERE, | |
| 46 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); | |
| 47 } | |
| 48 | |
| 49 void BackgroundFetchContext::ShutdownOnIO() { | |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 51 | |
| 52 // Call Shutdown on all pending job controllers to give them a chance to flush | |
| 53 // any status to the DataManager. | |
|
Peter Beverloo
2017/03/08 14:27:04
That does mean that such flushing must be synchron
harkness
2017/03/09 13:33:25
Yes, it will either mean that or that we do the fl
Peter Beverloo
2017/03/09 15:18:57
Not flushing means potential data loss, that's not
harkness
2017/03/09 18:35:31
As discussed in person, we should be able to avoid
| |
| 54 for (auto& job : job_map_) | |
| 55 job.second->Shutdown(); | |
| 42 } | 56 } |
| 43 | 57 |
| 44 void BackgroundFetchContext::CreateRequest( | 58 void BackgroundFetchContext::CreateRequest( |
| 45 const BackgroundFetchJobInfo& job_info, | 59 const BackgroundFetchJobInfo& job_info, |
| 46 std::vector<BackgroundFetchRequestInfo>& request_infos) { | 60 std::vector<BackgroundFetchRequestInfo>& request_infos) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 47 DCHECK_GE(1U, request_infos.size()); | 62 DCHECK_GE(1U, request_infos.size()); |
| 63 | |
| 48 // Inform the data manager about the new download. | 64 // Inform the data manager about the new download. |
| 49 BackgroundFetchJobData* job_data = | 65 BackgroundFetchJobData* job_data = |
| 50 background_fetch_data_manager_.CreateRequest(job_info, request_infos); | 66 background_fetch_data_manager_.CreateRequest(job_info, request_infos); |
| 67 | |
| 51 // If job_data is null, the DataManager will have logged an error. | 68 // If job_data is null, the DataManager will have logged an error. |
| 52 if (job_data) | 69 if (job_data) { |
| 53 background_fetch_job_controller_.ProcessJob(job_info.guid(), job_data); | 70 // Create a controller which drives the processing of the job. It will use |
| 71 // the JobData to get information about individual requests for the job. | |
| 72 job_map_[job_info.guid()] = base::MakeUnique<BackgroundFetchJobController>( | |
| 73 job_info.guid(), browser_context_, storage_partition_, job_data); | |
| 74 } | |
| 54 } | 75 } |
| 55 | 76 |
| 56 } // namespace content | 77 } // namespace content |
| OLD | NEW |