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

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

Issue 2781623009: Migrate part of the BackgroundFetchJobController to the UI thread (Closed)
Patch Set: Migrate part of the BackgroundFetchJobController to the UI thread 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_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"
11 #include "content/browser/service_worker/service_worker_context_wrapper.h" 11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
12 #include "content/browser/storage_partition_impl.h" 12 #include "content/browser/storage_partition_impl.h"
13 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
14 #include "net/url_request/url_request_context_getter.h"
14 #include "url/origin.h" 15 #include "url/origin.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 BackgroundFetchContext::BackgroundFetchContext( 19 BackgroundFetchContext::BackgroundFetchContext(
19 BrowserContext* browser_context, 20 BrowserContext* browser_context,
20 StoragePartitionImpl* storage_partition, 21 StoragePartitionImpl* storage_partition,
21 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) 22 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context)
22 : browser_context_(browser_context), 23 : browser_context_(browser_context),
23 storage_partition_(storage_partition),
24 service_worker_context_(service_worker_context), 24 service_worker_context_(service_worker_context),
25 background_fetch_data_manager_( 25 background_fetch_data_manager_(
26 base::MakeUnique<BackgroundFetchDataManager>(browser_context)) { 26 base::MakeUnique<BackgroundFetchDataManager>(browser_context)) {
27 DCHECK_CURRENTLY_ON(BrowserThread::UI); 27 DCHECK_CURRENTLY_ON(BrowserThread::UI);
28 request_context_ =
29 make_scoped_refptr(storage_partition->GetURLRequestContext());
28 } 30 }
29 31
30 BackgroundFetchContext::~BackgroundFetchContext() { 32 BackgroundFetchContext::~BackgroundFetchContext() {
31 DCHECK_CURRENTLY_ON(BrowserThread::UI); 33 DCHECK_CURRENTLY_ON(BrowserThread::UI);
32 } 34 }
33 35
34 void BackgroundFetchContext::Shutdown() { 36 void BackgroundFetchContext::Shutdown() {
35 DCHECK_CURRENTLY_ON(BrowserThread::UI); 37 DCHECK_CURRENTLY_ON(BrowserThread::UI);
36 BrowserThread::PostTask( 38 BrowserThread::PostTask(
37 BrowserThread::IO, FROM_HERE, 39 BrowserThread::IO, FROM_HERE,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 118
117 return controller; 119 return controller;
118 } 120 }
119 121
120 void BackgroundFetchContext::CreateController( 122 void BackgroundFetchContext::CreateController(
121 const BackgroundFetchRegistrationId& registration_id, 123 const BackgroundFetchRegistrationId& registration_id,
122 const BackgroundFetchOptions& options, 124 const BackgroundFetchOptions& options,
123 std::vector<BackgroundFetchRequestInfo> initial_requests) { 125 std::vector<BackgroundFetchRequestInfo> initial_requests) {
124 std::unique_ptr<BackgroundFetchJobController> controller = 126 std::unique_ptr<BackgroundFetchJobController> controller =
125 base::MakeUnique<BackgroundFetchJobController>( 127 base::MakeUnique<BackgroundFetchJobController>(
126 registration_id, options, browser_context_, storage_partition_, 128 registration_id, options, background_fetch_data_manager_.get(),
127 background_fetch_data_manager_.get(), 129 browser_context_, request_context_,
128 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this)); 130 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this));
129 131
130 // TODO(peter): Start actually fetching the files. 132 // TODO(peter): We should actually be able to use Background Fetch in layout
133 // tests. That requires a download manager and a request context.
134 if (request_context_) {
135 // Start fetching the |initial_requests| immediately. At some point in the
136 // future we may want a more elaborate scheduling mechanism here.
137 controller->Start(std::move(initial_requests));
138 }
131 139
132 active_fetches_.insert( 140 active_fetches_.insert(
133 std::make_pair(registration_id, std::move(controller))); 141 std::make_pair(registration_id, std::move(controller)));
134 } 142 }
135 143
136 void BackgroundFetchContext::DidCompleteJob( 144 void BackgroundFetchContext::DidCompleteJob(
137 BackgroundFetchJobController* controller) { 145 BackgroundFetchJobController* controller) {
138 const BackgroundFetchRegistrationId& registration_id = 146 const BackgroundFetchRegistrationId& registration_id =
139 controller->registration_id(); 147 controller->registration_id();
140 148
141 DCHECK_GT(active_fetches_.count(registration_id), 0u); 149 DCHECK_GT(active_fetches_.count(registration_id), 0u);
142 150
143 if (controller->state() == BackgroundFetchJobController::State::COMPLETED) { 151 if (controller->state() == BackgroundFetchJobController::State::COMPLETED) {
144 // TODO(peter): Dispatch the `backgroundfetched` or `backgroundfetchfail` 152 // TODO(peter): Dispatch the `backgroundfetched` or `backgroundfetchfail`
145 // event to the Service Worker to inform the developer. 153 // event to the Service Worker to inform the developer.
146 } 154 }
147 155
148 active_fetches_.erase(registration_id); 156 active_fetches_.erase(registration_id);
149 } 157 }
150 158
151 } // namespace content 159 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698