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 16 matching lines...) Expand all Loading... |
27 // ServiceWorkerContextObserver as a parent class and should register as an | 27 // ServiceWorkerContextObserver as a parent class and should register as an |
28 // observer here. | 28 // observer here. |
29 } | 29 } |
30 | 30 |
31 BackgroundFetchContext::~BackgroundFetchContext() { | 31 BackgroundFetchContext::~BackgroundFetchContext() { |
32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
33 } | 33 } |
34 | 34 |
35 void BackgroundFetchContext::Init() { | 35 void BackgroundFetchContext::Init() { |
36 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
37 | |
38 // TODO(harkness): Create the Download observer. | |
39 } | 37 } |
40 | 38 |
41 void BackgroundFetchContext::Shutdown() { | 39 void BackgroundFetchContext::Shutdown() { |
42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
43 | 41 |
44 BrowserThread::PostTask( | 42 BrowserThread::PostTask( |
45 BrowserThread::IO, FROM_HERE, | 43 BrowserThread::IO, FROM_HERE, |
46 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); | 44 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); |
47 } | 45 } |
48 | 46 |
49 void BackgroundFetchContext::ShutdownOnIO() { | 47 void BackgroundFetchContext::ShutdownOnIO() { |
50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 48 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
51 | 49 |
52 // Call Shutdown on all pending job controllers to give them a chance to flush | 50 // Call Shutdown on all pending job controllers to give them a chance to flush |
53 // any status to the DataManager. | 51 // any status to the DataManager. |
54 for (auto& job : job_map_) | 52 for (auto& job : job_map_) |
55 job.second->Shutdown(); | 53 job.second->Shutdown(); |
56 } | 54 } |
57 | 55 |
| 56 void BackgroundFetchContext::JobComplete(const std::string& job_guid) { |
| 57 DCHECK(job_map_.find(job_guid) != job_map_.end()); |
| 58 |
| 59 // TODO(harkness): Get enough data to send the response back to the caller. |
| 60 |
| 61 job_map_.erase(job_guid); |
| 62 |
| 63 // TODO(harkness): Once the caller receives the message, inform the |
| 64 // DataManager that it can clean up the pending job. |
| 65 } |
| 66 |
58 void BackgroundFetchContext::CreateRequest( | 67 void BackgroundFetchContext::CreateRequest( |
59 const BackgroundFetchJobInfo& job_info, | 68 const BackgroundFetchJobInfo& job_info, |
60 std::vector<BackgroundFetchRequestInfo>& request_infos) { | 69 std::vector<BackgroundFetchRequestInfo>& request_infos) { |
61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 70 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
62 DCHECK_GE(1U, request_infos.size()); | 71 DCHECK_GE(1U, request_infos.size()); |
63 | 72 |
64 // Inform the data manager about the new download. | 73 // Inform the data manager about the new download. |
65 BackgroundFetchJobData* job_data = | 74 BackgroundFetchJobData* job_data = |
66 background_fetch_data_manager_.CreateRequest(job_info, request_infos); | 75 background_fetch_data_manager_.CreateRequest(job_info, request_infos); |
67 | 76 |
68 // If job_data is null, the DataManager will have logged an error. | 77 // If job_data is null, the DataManager will have logged an error. |
69 if (job_data) { | 78 if (job_data) { |
70 // Create a controller which drives the processing of the job. It will use | 79 // 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. | 80 // the JobData to get information about individual requests for the job. |
72 job_map_[job_info.guid()] = base::MakeUnique<BackgroundFetchJobController>( | 81 job_map_[job_info.guid()] = base::MakeUnique<BackgroundFetchJobController>( |
73 job_info.guid(), browser_context_, storage_partition_, job_data); | 82 job_info.guid(), browser_context_, storage_partition_, job_data); |
74 } | 83 } |
75 } | 84 } |
76 | 85 |
77 } // namespace content | 86 } // namespace content |
OLD | NEW |