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

Side by Side Diff: content/browser/service_worker/service_worker_context_wrapper.cc

Issue 1951853004: DevTools: allow devtools to skipWaiting service workers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/service_worker/service_worker_context_wrapper.h" 5 #include "content/browser/service_worker/service_worker_context_wrapper.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // |registration| is 1, it will be deleted after WorkerStarted is called. 63 // |registration| is 1, it will be deleted after WorkerStarted is called.
64 registration->active_version()->StartWorker( 64 registration->active_version()->StartWorker(
65 ServiceWorkerMetrics::EventType::UNKNOWN, 65 ServiceWorkerMetrics::EventType::UNKNOWN,
66 base::Bind(WorkerStarted, callback)); 66 base::Bind(WorkerStarted, callback));
67 return; 67 return;
68 } 68 }
69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
70 base::Bind(callback, SERVICE_WORKER_ERROR_NOT_FOUND)); 70 base::Bind(callback, SERVICE_WORKER_ERROR_NOT_FOUND));
71 } 71 }
72 72
73 void SkipWaitingWorkerOnIO(
74 ServiceWorkerStatusCode status,
75 const scoped_refptr<ServiceWorkerRegistration>& registration) {
76 DCHECK_CURRENTLY_ON(BrowserThread::IO);
77 if (status != SERVICE_WORKER_OK || !registration->waiting_version())
78 return;
79
80 registration->waiting_version()->set_skip_waiting(true);
81 registration->ActivateWaitingVersionWhenReady();
82 }
83
73 } // namespace 84 } // namespace
74 85
75 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( 86 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent(
76 const std::set<std::string>& header_names) { 87 const std::set<std::string>& header_names) {
77 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 88 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
78 tracked_objects::ScopedTracker tracking_profile( 89 tracked_objects::ScopedTracker tracking_profile(
79 FROM_HERE_WITH_EXPLICIT_FUNCTION( 90 FROM_HERE_WITH_EXPLICIT_FUNCTION(
80 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent")); 91 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent"));
81 DCHECK_CURRENTLY_ON(BrowserThread::IO); 92 DCHECK_CURRENTLY_ON(BrowserThread::IO);
82 g_excluded_header_name_set.Get().insert(header_names.begin(), 93 g_excluded_header_name_set.Get().insert(header_names.begin(),
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 if (!context_core_) { 295 if (!context_core_) {
285 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 296 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
286 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); 297 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT));
287 return; 298 return;
288 } 299 }
289 context_core_->storage()->FindRegistrationForPattern( 300 context_core_->storage()->FindRegistrationForPattern(
290 net::SimplifyUrlForRequest(pattern), 301 net::SimplifyUrlForRequest(pattern),
291 base::Bind(&StartActiveWorkerOnIO, callback)); 302 base::Bind(&StartActiveWorkerOnIO, callback));
292 } 303 }
293 304
305 void ServiceWorkerContextWrapper::SkipWaitingWorker(const GURL& pattern) {
306 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
307 BrowserThread::PostTask(
308 BrowserThread::IO, FROM_HERE,
309 base::Bind(&ServiceWorkerContextWrapper::SkipWaitingWorker, this,
310 pattern));
311 return;
312 }
313 if (!context_core_)
314 return;
315 context_core_->storage()->FindRegistrationForPattern(
316 net::SimplifyUrlForRequest(pattern), base::Bind(&SkipWaitingWorkerOnIO));
317 }
318
294 void ServiceWorkerContextWrapper::SetForceUpdateOnPageLoad( 319 void ServiceWorkerContextWrapper::SetForceUpdateOnPageLoad(
295 bool force_update_on_page_load) { 320 bool force_update_on_page_load) {
296 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 321 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
297 BrowserThread::PostTask( 322 BrowserThread::PostTask(
298 BrowserThread::IO, FROM_HERE, 323 BrowserThread::IO, FROM_HERE,
299 base::Bind(&ServiceWorkerContextWrapper::SetForceUpdateOnPageLoad, this, 324 base::Bind(&ServiceWorkerContextWrapper::SetForceUpdateOnPageLoad, this,
300 force_update_on_page_load)); 325 force_update_on_page_load));
301 return; 326 return;
302 } 327 }
303 if (!context_core_) 328 if (!context_core_)
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 observer_list_->Notify(FROM_HERE, 740 observer_list_->Notify(FROM_HERE,
716 &ServiceWorkerContextObserver::OnStorageWiped); 741 &ServiceWorkerContextObserver::OnStorageWiped);
717 } 742 }
718 743
719 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { 744 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
720 DCHECK_CURRENTLY_ON(BrowserThread::IO); 745 DCHECK_CURRENTLY_ON(BrowserThread::IO);
721 return context_core_.get(); 746 return context_core_.get();
722 } 747 }
723 748
724 } // namespace content 749 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698