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

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

Issue 2767373002: Implement GetJobResponse and merge JobData into DataManager. (Closed)
Patch Set: Removed typedef and added DISALLOW_COPY_AND_ASSIGN Created 3 years, 8 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/download_manager.h" 11 #include "content/public/browser/download_manager.h"
12 #include "content/public/browser/storage_partition.h" 12 #include "content/public/browser/storage_partition.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 BackgroundFetchContext::BackgroundFetchContext( 16 BackgroundFetchContext::BackgroundFetchContext(
17 BrowserContext* browser_context, 17 BrowserContext* browser_context,
18 StoragePartition* storage_partition, 18 StoragePartition* storage_partition,
19 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) 19 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context)
20 : browser_context_(browser_context), 20 : browser_context_(browser_context),
21 storage_partition_(storage_partition), 21 storage_partition_(storage_partition),
22 service_worker_context_(service_worker_context), 22 service_worker_context_(service_worker_context),
23 background_fetch_data_manager_(this) { 23 background_fetch_data_manager_(browser_context) {
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
(...skipping 15 matching lines...) Expand all
49 // Call Shutdown on all pending job controllers to give them a chance to flush 49 // Call Shutdown on all pending job controllers to give them a chance to flush
50 // any status to the DataManager. 50 // any status to the DataManager.
51 for (auto& job : job_map_) 51 for (auto& job : job_map_)
52 job.second->Shutdown(); 52 job.second->Shutdown();
53 53
54 job_map_.clear(); 54 job_map_.clear();
55 } 55 }
56 56
57 void BackgroundFetchContext::CreateRequest( 57 void BackgroundFetchContext::CreateRequest(
58 std::unique_ptr<BackgroundFetchJobInfo> job_info, 58 std::unique_ptr<BackgroundFetchJobInfo> job_info,
59 std::vector<BackgroundFetchRequestInfo>& request_infos) { 59 std::vector<std::unique_ptr<BackgroundFetchRequestInfo>> request_infos) {
60 DCHECK_CURRENTLY_ON(BrowserThread::IO); 60 DCHECK_CURRENTLY_ON(BrowserThread::IO);
61 DCHECK_GE(1U, request_infos.size()); 61 DCHECK_GE(1U, request_infos.size());
62 62
63 // Inform the data manager about the new download. 63 // Inform the data manager about the new download.
64 const std::string job_guid = job_info->guid(); 64 const std::string job_guid = job_info->guid();
65 std::unique_ptr<BackgroundFetchJobData> job_data = 65 background_fetch_data_manager_.CreateRequest(std::move(job_info),
66 background_fetch_data_manager_.CreateRequest(std::move(job_info), 66 std::move(request_infos));
67 request_infos);
68 67
69 // If job_data is null, the DataManager will have logged an error. 68 // Create a controller which drives the processing of the job. It will use
70 if (job_data) { 69 // the DataManager to get information about individual requests for the job.
71 // Create a controller which drives the processing of the job. It will use 70 job_map_[job_guid] = base::MakeUnique<BackgroundFetchJobController>(
72 // the JobData to get information about individual requests for the job. 71 job_guid, browser_context_, storage_partition_,
73 job_map_[job_guid] = base::MakeUnique<BackgroundFetchJobController>( 72 &background_fetch_data_manager_,
74 job_guid, browser_context_, storage_partition_, std::move(job_data), 73 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this, job_guid));
75 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this,
76 job_guid));
77 }
78 } 74 }
79 75
80 void BackgroundFetchContext::DidCompleteJob(const std::string& job_guid) { 76 void BackgroundFetchContext::DidCompleteJob(const std::string& job_guid) {
81 DCHECK(job_map_.find(job_guid) != job_map_.end()); 77 DCHECK(job_map_.find(job_guid) != job_map_.end());
82 78
83 job_map_.erase(job_guid); 79 job_map_.erase(job_guid);
84 80
85 // TODO(harkness): Once the caller receives the message, inform the 81 // TODO(harkness): Once the caller receives the message, inform the
86 // DataManager that it can clean up the pending job. 82 // DataManager that it can clean up the pending job.
87 } 83 }
88 84
89 } // namespace content 85 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698