Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: content/browser/background_fetch/background_fetch_context.cc

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Added BackgroundFetchClientProxy to proxy calls to and from the Context. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
37
38 BackgroundFetchClient* client = browser_context_->GetBackgroundFetchClient();
39 if (client)
40 client->SetDelegate(nullptr);
Peter Beverloo 2017/03/31 01:32:23 Thinking more about this, we should probably do th
harkness 2017/03/31 10:11:44 Excellent point. Done.
31 } 41 }
32 42
33 void BackgroundFetchContext::Shutdown() { 43 void BackgroundFetchContext::Shutdown() {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI); 44 DCHECK_CURRENTLY_ON(BrowserThread::UI);
35 BrowserThread::PostTask( 45 BrowserThread::PostTask(
36 BrowserThread::IO, FROM_HERE, 46 BrowserThread::IO, FROM_HERE,
37 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); 47 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this));
38 } 48 }
39 49
40 void BackgroundFetchContext::ShutdownOnIO() { 50 void BackgroundFetchContext::ShutdownOnIO() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void BackgroundFetchContext::DidFinishFetch( 104 void BackgroundFetchContext::DidFinishFetch(
95 const BackgroundFetchRegistrationId& registration_id) { 105 const BackgroundFetchRegistrationId& registration_id) {
96 DCHECK_GT(active_fetches_.count(registration_id), 0u); 106 DCHECK_GT(active_fetches_.count(registration_id), 0u);
97 107
98 // TODO(peter): Dispatch the `backgroundfetched` or the `backgroundfetchfail` 108 // TODO(peter): Dispatch the `backgroundfetched` or the `backgroundfetchfail`
99 // event to the Service Worker. 109 // event to the Service Worker.
100 110
101 active_fetches_.erase(registration_id); 111 active_fetches_.erase(registration_id);
102 } 112 }
103 113
114 void BackgroundFetchContext::CancelFetch(
115 const BackgroundFetchRegistrationId& registration_id) {
116 // TODO(harkness): pass the command to the JobController for the given task.
Peter Beverloo 2017/03/31 01:32:23 DCHECK_CURRENTLY_ON(BrowserThread::IO);
harkness 2017/03/31 10:11:44 Done.
117 }
118
119 void BackgroundFetchContext::PauseFetch(
120 const BackgroundFetchRegistrationId& registration_id) {
121 // TODO(harkness): pass the command to the JobController for the given task.
122 }
123
124 void BackgroundFetchContext::ResumeFetch(
125 const BackgroundFetchRegistrationId& registration_id) {
126 // TODO(harkness): pass the command to the JobController for the given task.
127 }
128
104 } // namespace content 129 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698