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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); | 43 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); |
44 } | 44 } |
45 | 45 |
46 void BackgroundFetchContext::ShutdownOnIO() { | 46 void BackgroundFetchContext::ShutdownOnIO() { |
47 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 47 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
48 | 48 |
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 |
| 54 job_map_.clear(); |
53 } | 55 } |
54 | 56 |
55 void BackgroundFetchContext::CreateRequest( | 57 void BackgroundFetchContext::CreateRequest( |
56 const BackgroundFetchJobInfo& job_info, | 58 const BackgroundFetchJobInfo& job_info, |
57 std::vector<BackgroundFetchRequestInfo>& request_infos) { | 59 std::vector<BackgroundFetchRequestInfo>& request_infos) { |
58 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 60 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
59 DCHECK_GE(1U, request_infos.size()); | 61 DCHECK_GE(1U, request_infos.size()); |
60 | 62 |
61 // Inform the data manager about the new download. | 63 // Inform the data manager about the new download. |
62 std::unique_ptr<BackgroundFetchJobData> job_data = | 64 std::unique_ptr<BackgroundFetchJobData> job_data = |
63 background_fetch_data_manager_.CreateRequest(job_info, request_infos); | 65 background_fetch_data_manager_.CreateRequest(job_info, request_infos); |
64 | 66 |
65 // 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. |
66 if (job_data) { | 68 if (job_data) { |
67 // Create a controller which drives the processing of the job. It will use | 69 // Create a controller which drives the processing of the job. It will use |
68 // the JobData to get information about individual requests for the job. | 70 // the JobData to get information about individual requests for the job. |
69 job_map_[job_info.guid()] = base::MakeUnique<BackgroundFetchJobController>( | 71 job_map_[job_info.guid()] = base::MakeUnique<BackgroundFetchJobController>( |
70 job_info.guid(), browser_context_, storage_partition_, | 72 job_info.guid(), browser_context_, storage_partition_, |
71 std::move(job_data)); | 73 std::move(job_data), |
| 74 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this, |
| 75 job_info.guid())); |
72 } | 76 } |
73 } | 77 } |
74 | 78 |
| 79 void BackgroundFetchContext::DidCompleteJob(const std::string& job_guid) { |
| 80 DCHECK(job_map_.find(job_guid) != job_map_.end()); |
| 81 |
| 82 job_map_.erase(job_guid); |
| 83 |
| 84 // TODO(harkness): Once the caller receives the message, inform the |
| 85 // DataManager that it can clean up the pending job. |
| 86 } |
| 87 |
75 } // namespace content | 88 } // namespace content |
OLD | NEW |