| 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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "content/browser/background_fetch/background_fetch_data_manager.h" | 8 #include "content/browser/background_fetch/background_fetch_data_manager.h" |
| 9 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h" | 9 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h" |
| 10 #include "content/browser/background_fetch/background_fetch_job_controller.h" | 10 #include "content/browser/background_fetch/background_fetch_job_controller.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 registration_id, requests, options, | 74 registration_id, requests, options, |
| 75 base::BindOnce(&BackgroundFetchContext::DidCreateRegistration, this, | 75 base::BindOnce(&BackgroundFetchContext::DidCreateRegistration, this, |
| 76 registration_id, options, callback)); | 76 registration_id, options, callback)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void BackgroundFetchContext::DidCreateRegistration( | 79 void BackgroundFetchContext::DidCreateRegistration( |
| 80 const BackgroundFetchRegistrationId& registration_id, | 80 const BackgroundFetchRegistrationId& registration_id, |
| 81 const BackgroundFetchOptions& options, | 81 const BackgroundFetchOptions& options, |
| 82 const blink::mojom::BackgroundFetchService::FetchCallback& callback, | 82 const blink::mojom::BackgroundFetchService::FetchCallback& callback, |
| 83 blink::mojom::BackgroundFetchError error, | 83 blink::mojom::BackgroundFetchError error, |
| 84 std::vector<BackgroundFetchRequestInfo> initial_requests) { | 84 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) { |
| 85 RecordRegistrationCreatedError(error); | 85 RecordRegistrationCreatedError(error); |
| 86 if (error != blink::mojom::BackgroundFetchError::NONE) { | 86 if (error != blink::mojom::BackgroundFetchError::NONE) { |
| 87 callback.Run(error, base::nullopt /* registration */); | 87 callback.Run(error, base::nullopt /* registration */); |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Create the BackgroundFetchJobController, which will do the actual fetching. | 91 // Create the BackgroundFetchJobController, which will do the actual fetching. |
| 92 CreateController(registration_id, options, std::move(initial_requests)); | 92 CreateController(registration_id, options, std::move(initial_requests)); |
| 93 | 93 |
| 94 // Create the BackgroundFetchRegistration the renderer process will receive, | 94 // Create the BackgroundFetchRegistration the renderer process will receive, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 controller->state() == BackgroundFetchJobController::State::COMPLETED) { | 135 controller->state() == BackgroundFetchJobController::State::COMPLETED) { |
| 136 return nullptr; | 136 return nullptr; |
| 137 } | 137 } |
| 138 | 138 |
| 139 return controller; | 139 return controller; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void BackgroundFetchContext::CreateController( | 142 void BackgroundFetchContext::CreateController( |
| 143 const BackgroundFetchRegistrationId& registration_id, | 143 const BackgroundFetchRegistrationId& registration_id, |
| 144 const BackgroundFetchOptions& options, | 144 const BackgroundFetchOptions& options, |
| 145 std::vector<BackgroundFetchRequestInfo> initial_requests) { | 145 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) { |
| 146 std::unique_ptr<BackgroundFetchJobController> controller = | 146 std::unique_ptr<BackgroundFetchJobController> controller = |
| 147 base::MakeUnique<BackgroundFetchJobController>( | 147 base::MakeUnique<BackgroundFetchJobController>( |
| 148 registration_id, options, data_manager_.get(), browser_context_, | 148 registration_id, options, data_manager_.get(), browser_context_, |
| 149 request_context_, | 149 request_context_, |
| 150 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this)); | 150 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this)); |
| 151 | 151 |
| 152 // TODO(peter): We should actually be able to use Background Fetch in layout | 152 // TODO(peter): We should actually be able to use Background Fetch in layout |
| 153 // tests. That requires a download manager and a request context. | 153 // tests. That requires a download manager and a request context. |
| 154 if (request_context_) { | 154 if (request_context_) { |
| 155 // Start fetching the |initial_requests| immediately. At some point in the | 155 // Start fetching the |initial_requests| immediately. At some point in the |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 // Delete all persistent information associated with the |registration_id|. | 212 // Delete all persistent information associated with the |registration_id|. |
| 213 data_manager_->DeleteRegistration( | 213 data_manager_->DeleteRegistration( |
| 214 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); | 214 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); |
| 215 | 215 |
| 216 // Delete the local state associated with the |registration_id|. | 216 // Delete the local state associated with the |registration_id|. |
| 217 active_fetches_.erase(registration_id); | 217 active_fetches_.erase(registration_id); |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace content | 220 } // namespace content |
| OLD | NEW |