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_job_controller.h" | 10 #include "content/browser/background_fetch/background_fetch_job_controller.h" |
10 #include "content/browser/background_fetch/background_fetch_registration_id.h" | 11 #include "content/browser/background_fetch/background_fetch_registration_id.h" |
11 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
12 #include "content/browser/storage_partition_impl.h" | 13 #include "content/browser/storage_partition_impl.h" |
| 14 #include "content/public/browser/background_fetch_client.h" |
13 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
14 | 16 |
15 namespace content { | 17 namespace content { |
16 | 18 |
17 BackgroundFetchContext::BackgroundFetchContext( | 19 BackgroundFetchContext::BackgroundFetchContext( |
18 BrowserContext* browser_context, | 20 BrowserContext* browser_context, |
19 StoragePartitionImpl* storage_partition, | 21 StoragePartitionImpl* storage_partition, |
20 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) | 22 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) |
21 : browser_context_(browser_context), | 23 : browser_context_(browser_context), |
22 storage_partition_(storage_partition), | 24 storage_partition_(storage_partition), |
23 service_worker_context_(service_worker_context), | 25 service_worker_context_(service_worker_context), |
24 background_fetch_data_manager_( | 26 background_fetch_data_manager_( |
25 base::MakeUnique<BackgroundFetchDataManager>(browser_context)) { | 27 base::MakeUnique<BackgroundFetchDataManager>(browser_context)), |
| 28 client_proxy_(base::MakeUnique<BackgroundFetchClientProxy>(this)) { |
26 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 29 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 30 BackgroundFetchClient* client = browser_context_->GetBackgroundFetchClient(); |
| 31 if (client) |
| 32 client->SetDelegate(client_proxy_.get()); |
27 } | 33 } |
28 | 34 |
29 BackgroundFetchContext::~BackgroundFetchContext() { | 35 BackgroundFetchContext::~BackgroundFetchContext() { |
30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
31 } | 37 } |
32 | 38 |
33 void BackgroundFetchContext::Shutdown() { | 39 void BackgroundFetchContext::Shutdown() { |
34 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 41 |
| 42 BackgroundFetchClient* client = browser_context_->GetBackgroundFetchClient(); |
| 43 if (client) |
| 44 client->SetDelegate(nullptr); |
| 45 |
35 BrowserThread::PostTask( | 46 BrowserThread::PostTask( |
36 BrowserThread::IO, FROM_HERE, | 47 BrowserThread::IO, FROM_HERE, |
37 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); | 48 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); |
38 } | 49 } |
39 | 50 |
40 void BackgroundFetchContext::ShutdownOnIO() { | 51 void BackgroundFetchContext::ShutdownOnIO() { |
41 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 52 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
42 active_fetches_.clear(); | 53 active_fetches_.clear(); |
43 } | 54 } |
44 | 55 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 void BackgroundFetchContext::DidFinishFetch( | 105 void BackgroundFetchContext::DidFinishFetch( |
95 const BackgroundFetchRegistrationId& registration_id) { | 106 const BackgroundFetchRegistrationId& registration_id) { |
96 DCHECK_GT(active_fetches_.count(registration_id), 0u); | 107 DCHECK_GT(active_fetches_.count(registration_id), 0u); |
97 | 108 |
98 // TODO(peter): Dispatch the `backgroundfetched` or the `backgroundfetchfail` | 109 // TODO(peter): Dispatch the `backgroundfetched` or the `backgroundfetchfail` |
99 // event to the Service Worker. | 110 // event to the Service Worker. |
100 | 111 |
101 active_fetches_.erase(registration_id); | 112 active_fetches_.erase(registration_id); |
102 } | 113 } |
103 | 114 |
| 115 void BackgroundFetchContext::CancelFetch( |
| 116 const BackgroundFetchRegistrationId& registration_id) { |
| 117 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 118 // TODO(harkness): pass the command to the JobController for the given task. |
| 119 } |
| 120 |
| 121 void BackgroundFetchContext::PauseFetch( |
| 122 const BackgroundFetchRegistrationId& registration_id) { |
| 123 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 124 // TODO(harkness): pass the command to the JobController for the given task. |
| 125 } |
| 126 |
| 127 void BackgroundFetchContext::ResumeFetch( |
| 128 const BackgroundFetchRegistrationId& registration_id) { |
| 129 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 130 // TODO(harkness): pass the command to the JobController for the given task. |
| 131 } |
| 132 |
104 } // namespace content | 133 } // namespace content |
OLD | NEW |