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

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

Issue 2777063008: Connect BackgroundFetch to the OfflineItemCollection
Patch Set: Fixed incognito check and added tests 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_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
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 BackgroundFetchClient* background_fetch_client =
51 browser_context_->GetBackgroundFetchClient();
52 if (background_fetch_client)
53 background_fetch_client->SetDelegate(client_proxy_.get());
47 } 54 }
48 55
49 BackgroundFetchContext::~BackgroundFetchContext() { 56 BackgroundFetchContext::~BackgroundFetchContext() {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI); 57 DCHECK_CURRENTLY_ON(BrowserThread::UI);
51 } 58 }
52 59
53 void BackgroundFetchContext::InitializeOnIOThread( 60 void BackgroundFetchContext::InitializeOnIOThread(
54 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { 61 scoped_refptr<net::URLRequestContextGetter> request_context_getter) {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO); 62 DCHECK_CURRENTLY_ON(BrowserThread::IO);
56 request_context_getter_ = request_context_getter; 63 request_context_getter_ = request_context_getter;
57 } 64 }
58 65
59 void BackgroundFetchContext::Shutdown() { 66 void BackgroundFetchContext::Shutdown() {
60 DCHECK_CURRENTLY_ON(BrowserThread::UI); 67 DCHECK_CURRENTLY_ON(BrowserThread::UI);
68
61 BrowserThread::PostTask( 69 BrowserThread::PostTask(
62 BrowserThread::IO, FROM_HERE, 70 BrowserThread::IO, FROM_HERE,
63 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); 71 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this));
64 } 72 }
65 73
66 void BackgroundFetchContext::ShutdownOnIO() { 74 void BackgroundFetchContext::ShutdownOnIO() {
67 DCHECK_CURRENTLY_ON(BrowserThread::IO); 75 DCHECK_CURRENTLY_ON(BrowserThread::IO);
68 active_fetches_.clear(); 76 active_fetches_.clear();
69 } 77 }
70 78
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 DCHECK_GT(active_fetches_.count(registration_id), 0u); 224 DCHECK_GT(active_fetches_.count(registration_id), 0u);
217 225
218 // Delete all persistent information associated with the |registration_id|. 226 // Delete all persistent information associated with the |registration_id|.
219 data_manager_->DeleteRegistration( 227 data_manager_->DeleteRegistration(
220 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); 228 registration_id, base::BindOnce(&RecordRegistrationDeletedError));
221 229
222 // Delete the local state associated with the |registration_id|. 230 // Delete the local state associated with the |registration_id|.
223 active_fetches_.erase(registration_id); 231 active_fetches_.erase(registration_id);
224 } 232 }
225 233
234 void BackgroundFetchContext::CleanupAllTasks() {
235 DCHECK_CURRENTLY_ON(BrowserThread::IO);
236 // TODO(harkness): Iterate over all tasks and cancel them.
237 }
238
239 void BackgroundFetchContext::CancelFetch(
240 const BackgroundFetchRegistrationId& registration_id) {
241 DCHECK_CURRENTLY_ON(BrowserThread::IO);
242 // TODO(harkness): pass the command to the JobController for the given task.
243 }
244
245 void BackgroundFetchContext::PauseFetch(
246 const BackgroundFetchRegistrationId& registration_id) {
247 DCHECK_CURRENTLY_ON(BrowserThread::IO);
248 // TODO(harkness): pass the command to the JobController for the given task.
249 }
250
251 void BackgroundFetchContext::ResumeFetch(
252 const BackgroundFetchRegistrationId& registration_id) {
253 DCHECK_CURRENTLY_ON(BrowserThread::IO);
254 // TODO(harkness): pass the command to the JobController for the given task.
255 }
256
226 } // namespace content 257 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698