| 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_job_controller.h" | 9 #include "content/browser/background_fetch/background_fetch_job_controller.h" |
| 10 #include "content/browser/background_fetch/background_fetch_registration_id.h" | 10 #include "content/browser/background_fetch/background_fetch_registration_id.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 100 } |
| 101 | 101 |
| 102 BackgroundFetchJobController* BackgroundFetchContext::GetActiveFetch( | 102 BackgroundFetchJobController* BackgroundFetchContext::GetActiveFetch( |
| 103 const BackgroundFetchRegistrationId& registration_id) const { | 103 const BackgroundFetchRegistrationId& registration_id) const { |
| 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 105 | 105 |
| 106 auto iter = active_fetches_.find(registration_id); | 106 auto iter = active_fetches_.find(registration_id); |
| 107 if (iter == active_fetches_.end()) | 107 if (iter == active_fetches_.end()) |
| 108 return nullptr; | 108 return nullptr; |
| 109 | 109 |
| 110 return iter->second.get(); | 110 BackgroundFetchJobController* controller = iter->second.get(); |
| 111 if (controller->state() == BackgroundFetchJobController::State::ABORTED || |
| 112 controller->state() == BackgroundFetchJobController::State::COMPLETED) { |
| 113 return nullptr; |
| 114 } |
| 115 |
| 116 return controller; |
| 111 } | 117 } |
| 112 | 118 |
| 113 void BackgroundFetchContext::CreateController( | 119 void BackgroundFetchContext::CreateController( |
| 114 const BackgroundFetchRegistrationId& registration_id, | 120 const BackgroundFetchRegistrationId& registration_id, |
| 115 const BackgroundFetchOptions& options) { | 121 const BackgroundFetchOptions& options) { |
| 116 std::unique_ptr<BackgroundFetchJobController> controller = | 122 std::unique_ptr<BackgroundFetchJobController> controller = |
| 117 base::MakeUnique<BackgroundFetchJobController>( | 123 base::MakeUnique<BackgroundFetchJobController>( |
| 118 registration_id, options, browser_context_, storage_partition_, | 124 registration_id, options, browser_context_, storage_partition_, |
| 119 background_fetch_data_manager_.get(), | 125 background_fetch_data_manager_.get(), |
| 120 base::BindOnce(&BackgroundFetchContext::DidFinishFetch, this)); | 126 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this)); |
| 121 | 127 |
| 122 active_fetches_.insert( | 128 active_fetches_.insert( |
| 123 std::make_pair(registration_id, std::move(controller))); | 129 std::make_pair(registration_id, std::move(controller))); |
| 124 } | 130 } |
| 125 | 131 |
| 126 void BackgroundFetchContext::DidFinishFetch( | 132 void BackgroundFetchContext::DidCompleteJob( |
| 127 const BackgroundFetchRegistrationId& registration_id, | 133 BackgroundFetchJobController* controller) { |
| 128 bool aborted_by_developer) { | 134 const BackgroundFetchRegistrationId& registration_id = |
| 135 controller->registration_id(); |
| 136 |
| 129 DCHECK_GT(active_fetches_.count(registration_id), 0u); | 137 DCHECK_GT(active_fetches_.count(registration_id), 0u); |
| 130 | 138 |
| 131 // TODO(peter): Dispatch the `backgroundfetched` or the `backgroundfetchfail` | 139 if (controller->state() == BackgroundFetchJobController::State::COMPLETED) { |
| 132 // event to the Service Worker when |aborted_by_developer| is not set. | 140 // TODO(peter): Dispatch the `backgroundfetched` or `backgroundfetchfail` |
| 141 // event to the Service Worker to inform the developer. |
| 142 } |
| 133 | 143 |
| 134 active_fetches_.erase(registration_id); | 144 active_fetches_.erase(registration_id); |
| 135 } | 145 } |
| 136 | 146 |
| 137 } // namespace content | 147 } // namespace content |
| OLD | NEW |