| 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_client_proxy.h" |
| 8 #include "content/browser/background_fetch/background_fetch_data_manager.h" | 9 #include "content/browser/background_fetch/background_fetch_data_manager.h" |
| 9 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h" | 10 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h" |
| 10 #include "content/browser/background_fetch/background_fetch_job_controller.h" | 11 #include "content/browser/background_fetch/background_fetch_job_controller.h" |
| 11 #include "content/browser/background_fetch/background_fetch_registration_id.h" | 12 #include "content/browser/background_fetch/background_fetch_registration_id.h" |
| 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 13 #include "content/browser/storage_partition_impl.h" | 14 #include "content/browser/storage_partition_impl.h" |
| 15 #include "content/public/browser/background_fetch_client.h" |
| 14 #include "content/public/browser/blob_handle.h" | 16 #include "content/public/browser/blob_handle.h" |
| 15 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 17 #include "url/origin.h" | 19 #include "url/origin.h" |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // Records the |error| status issued by the DataManager after it was requested | 25 // Records the |error| status issued by the DataManager after it was requested |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 } // namespace | 37 } // namespace |
| 36 | 38 |
| 37 BackgroundFetchContext::BackgroundFetchContext( | 39 BackgroundFetchContext::BackgroundFetchContext( |
| 38 BrowserContext* browser_context, | 40 BrowserContext* browser_context, |
| 39 StoragePartitionImpl* storage_partition, | 41 StoragePartitionImpl* storage_partition, |
| 40 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) | 42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) |
| 41 : browser_context_(browser_context), | 43 : browser_context_(browser_context), |
| 42 data_manager_( | 44 data_manager_( |
| 43 base::MakeUnique<BackgroundFetchDataManager>(browser_context)), | 45 base::MakeUnique<BackgroundFetchDataManager>(browser_context)), |
| 44 event_dispatcher_(base::MakeUnique<BackgroundFetchEventDispatcher>( | 46 event_dispatcher_(base::MakeUnique<BackgroundFetchEventDispatcher>( |
| 45 std::move(service_worker_context))) { | 47 std::move(service_worker_context))), |
| 48 client_proxy_(base::MakeUnique<BackgroundFetchClientProxy>(this)) { |
| 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 50 background_fetch_client_ = browser_context_->GetBackgroundFetchClient(); |
| 51 if (background_fetch_client_) |
| 52 background_fetch_client_->SetDelegate(client_proxy_.get()); |
| 47 } | 53 } |
| 48 | 54 |
| 49 BackgroundFetchContext::~BackgroundFetchContext() { | 55 BackgroundFetchContext::~BackgroundFetchContext() { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 51 } | 57 } |
| 52 | 58 |
| 53 void BackgroundFetchContext::InitializeOnIOThread( | 59 void BackgroundFetchContext::InitializeOnIOThread( |
| 54 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { | 60 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 56 request_context_getter_ = request_context_getter; | 62 request_context_getter_ = request_context_getter; |
| 57 } | 63 } |
| 58 | 64 |
| 59 void BackgroundFetchContext::Shutdown() { | 65 void BackgroundFetchContext::Shutdown() { |
| 60 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 66 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 67 |
| 61 BrowserThread::PostTask( | 68 BrowserThread::PostTask( |
| 62 BrowserThread::IO, FROM_HERE, | 69 BrowserThread::IO, FROM_HERE, |
| 63 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); | 70 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); |
| 64 } | 71 } |
| 65 | 72 |
| 66 void BackgroundFetchContext::ShutdownOnIO() { | 73 void BackgroundFetchContext::ShutdownOnIO() { |
| 67 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 68 active_fetches_.clear(); | 75 active_fetches_.clear(); |
| 69 } | 76 } |
| 70 | 77 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 DCHECK_GT(active_fetches_.count(registration_id), 0u); | 223 DCHECK_GT(active_fetches_.count(registration_id), 0u); |
| 217 | 224 |
| 218 // Delete all persistent information associated with the |registration_id|. | 225 // Delete all persistent information associated with the |registration_id|. |
| 219 data_manager_->DeleteRegistration( | 226 data_manager_->DeleteRegistration( |
| 220 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); | 227 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); |
| 221 | 228 |
| 222 // Delete the local state associated with the |registration_id|. | 229 // Delete the local state associated with the |registration_id|. |
| 223 active_fetches_.erase(registration_id); | 230 active_fetches_.erase(registration_id); |
| 224 } | 231 } |
| 225 | 232 |
| 233 void BackgroundFetchContext::CleanupAllTasks() { |
| 234 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 235 // TODO(harkness): Iterate over all tasks and cancel them. |
| 236 } |
| 237 |
| 238 void BackgroundFetchContext::CancelFetch( |
| 239 const BackgroundFetchRegistrationId& registration_id) { |
| 240 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 241 // TODO(harkness): pass the command to the JobController for the given task. |
| 242 } |
| 243 |
| 244 void BackgroundFetchContext::PauseFetch( |
| 245 const BackgroundFetchRegistrationId& registration_id) { |
| 246 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 247 // TODO(harkness): pass the command to the JobController for the given task. |
| 248 } |
| 249 |
| 250 void BackgroundFetchContext::ResumeFetch( |
| 251 const BackgroundFetchRegistrationId& registration_id) { |
| 252 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 253 // TODO(harkness): pass the command to the JobController for the given task. |
| 254 } |
| 255 |
| 226 } // namespace content | 256 } // namespace content |
| OLD | NEW |