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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/background_fetch/background_fetch_context.cc
diff --git a/content/browser/background_fetch/background_fetch_context.cc b/content/browser/background_fetch/background_fetch_context.cc
index 2fde2c68454d1fabccfca1805a53360911a1802a..256eb5a460c629275cb80ebc341f5dd906706ad0 100644
--- a/content/browser/background_fetch/background_fetch_context.cc
+++ b/content/browser/background_fetch/background_fetch_context.cc
@@ -8,7 +8,6 @@
#include "content/browser/background_fetch/background_fetch_request_info.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/public/browser/browser_context.h"
-#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/storage_partition.h"
@@ -18,8 +17,9 @@ BackgroundFetchContext::BackgroundFetchContext(
BrowserContext* browser_context,
StoragePartition* storage_partition,
const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context)
- : service_worker_context_(service_worker_context),
- background_fetch_job_controller_(browser_context, storage_partition),
+ : browser_context_(browser_context),
+ storage_partition_(storage_partition),
+ service_worker_context_(service_worker_context),
background_fetch_data_manager_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// TODO(harkness): BackgroundFetchContext should have
@@ -39,18 +39,39 @@ void BackgroundFetchContext::Init() {
void BackgroundFetchContext::Shutdown() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&BackgroundFetchContext::ShutdownOnIO, this));
+}
+
+void BackgroundFetchContext::ShutdownOnIO() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ // Call Shutdown on all pending job controllers to give them a chance to flush
+ // any status to the DataManager.
+ for (auto& job : job_map_)
+ job.second->Shutdown();
}
void BackgroundFetchContext::CreateRequest(
const BackgroundFetchJobInfo& job_info,
std::vector<BackgroundFetchRequestInfo>& request_infos) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_GE(1U, request_infos.size());
+
// Inform the data manager about the new download.
- BackgroundFetchJobData* job_data =
+ std::unique_ptr<BackgroundFetchJobData> job_data =
background_fetch_data_manager_.CreateRequest(job_info, request_infos);
+
// If job_data is null, the DataManager will have logged an error.
- if (job_data)
- background_fetch_job_controller_.ProcessJob(job_info.guid(), job_data);
+ if (job_data) {
+ // Create a controller which drives the processing of the job. It will use
+ // the JobData to get information about individual requests for the job.
+ job_map_[job_info.guid()] = base::MakeUnique<BackgroundFetchJobController>(
+ job_info.guid(), browser_context_, storage_partition_,
+ std::move(job_data));
+ }
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698