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

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

Issue 2806713002: Some minor fixes for Background Fetch (Closed)
Patch Set: 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_event_dispatcher.h" 9 #include "content/browser/background_fetch/background_fetch_event_dispatcher.h"
10 #include "content/browser/background_fetch/background_fetch_job_controller.h" 10 #include "content/browser/background_fetch/background_fetch_job_controller.h"
(...skipping 26 matching lines...) Expand all
37 BackgroundFetchContext::BackgroundFetchContext( 37 BackgroundFetchContext::BackgroundFetchContext(
38 BrowserContext* browser_context, 38 BrowserContext* browser_context,
39 StoragePartitionImpl* storage_partition, 39 StoragePartitionImpl* storage_partition,
40 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) 40 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
41 : browser_context_(browser_context), 41 : browser_context_(browser_context),
42 data_manager_( 42 data_manager_(
43 base::MakeUnique<BackgroundFetchDataManager>(browser_context)), 43 base::MakeUnique<BackgroundFetchDataManager>(browser_context)),
44 event_dispatcher_(base::MakeUnique<BackgroundFetchEventDispatcher>( 44 event_dispatcher_(base::MakeUnique<BackgroundFetchEventDispatcher>(
45 std::move(service_worker_context))) { 45 std::move(service_worker_context))) {
46 DCHECK_CURRENTLY_ON(BrowserThread::UI); 46 DCHECK_CURRENTLY_ON(BrowserThread::UI);
47 request_context_ =
48 make_scoped_refptr(storage_partition->GetURLRequestContext());
49 } 47 }
50 48
51 BackgroundFetchContext::~BackgroundFetchContext() { 49 BackgroundFetchContext::~BackgroundFetchContext() {
52 DCHECK_CURRENTLY_ON(BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
53 } 51 }
54 52
53 void BackgroundFetchContext::InitializeOnIOThread(
54 scoped_refptr<net::URLRequestContextGetter> request_context_getter) {
55 DCHECK_CURRENTLY_ON(BrowserThread::IO);
56 request_context_getter_ = request_context_getter;
57 }
58
55 void BackgroundFetchContext::Shutdown() { 59 void BackgroundFetchContext::Shutdown() {
56 DCHECK_CURRENTLY_ON(BrowserThread::UI); 60 DCHECK_CURRENTLY_ON(BrowserThread::UI);
57 BrowserThread::PostTask( 61 BrowserThread::PostTask(
58 BrowserThread::IO, FROM_HERE, 62 BrowserThread::IO, FROM_HERE,
59 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this)); 63 base::Bind(&BackgroundFetchContext::ShutdownOnIO, this));
60 } 64 }
61 65
62 void BackgroundFetchContext::ShutdownOnIO() { 66 void BackgroundFetchContext::ShutdownOnIO() {
63 DCHECK_CURRENTLY_ON(BrowserThread::IO); 67 DCHECK_CURRENTLY_ON(BrowserThread::IO);
64 active_fetches_.clear(); 68 active_fetches_.clear();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return controller; 143 return controller;
140 } 144 }
141 145
142 void BackgroundFetchContext::CreateController( 146 void BackgroundFetchContext::CreateController(
143 const BackgroundFetchRegistrationId& registration_id, 147 const BackgroundFetchRegistrationId& registration_id,
144 const BackgroundFetchOptions& options, 148 const BackgroundFetchOptions& options,
145 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) { 149 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) {
146 std::unique_ptr<BackgroundFetchJobController> controller = 150 std::unique_ptr<BackgroundFetchJobController> controller =
147 base::MakeUnique<BackgroundFetchJobController>( 151 base::MakeUnique<BackgroundFetchJobController>(
148 registration_id, options, data_manager_.get(), browser_context_, 152 registration_id, options, data_manager_.get(), browser_context_,
149 request_context_, 153 request_context_getter_,
150 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this)); 154 base::BindOnce(&BackgroundFetchContext::DidCompleteJob, this));
151 155
152 // TODO(peter): We should actually be able to use Background Fetch in layout 156 // TODO(peter): We should actually be able to use Background Fetch in layout
153 // tests. That requires a download manager and a request context. 157 // tests. That requires a download manager and a request context.
154 if (request_context_) { 158 if (request_context_getter_) {
155 // Start fetching the |initial_requests| immediately. At some point in the 159 // Start fetching the |initial_requests| immediately. At some point in the
156 // future we may want a more elaborate scheduling mechanism here. 160 // future we may want a more elaborate scheduling mechanism here.
157 controller->Start(std::move(initial_requests)); 161 controller->Start(std::move(initial_requests));
158 } 162 }
159 163
160 active_fetches_.insert( 164 active_fetches_.insert(
161 std::make_pair(registration_id, std::move(controller))); 165 std::make_pair(registration_id, std::move(controller)));
162 } 166 }
163 167
164 void BackgroundFetchContext::DidCompleteJob( 168 void BackgroundFetchContext::DidCompleteJob(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 217
214 // Delete all persistent information associated with the |registration_id|. 218 // Delete all persistent information associated with the |registration_id|.
215 data_manager_->DeleteRegistration( 219 data_manager_->DeleteRegistration(
216 registration_id, base::BindOnce(&RecordRegistrationDeletedError)); 220 registration_id, base::BindOnce(&RecordRegistrationDeletedError));
217 221
218 // Delete the local state associated with the |registration_id|. 222 // Delete the local state associated with the |registration_id|.
219 active_fetches_.erase(registration_id); 223 active_fetches_.erase(registration_id);
220 } 224 }
221 225
222 } // namespace content 226 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698