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

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

Issue 2575523002: Prerender: Confirm ServiceWorkers are invoked for NoState Prefetch (Closed)
Patch Set: comments Created 3 years, 11 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/barrier_closure.h" 13 #include "base/barrier_closure.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h"
15 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
16 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
17 #include "base/location.h" 18 #include "base/location.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
19 #include "base/profiler/scoped_tracker.h" 20 #include "base/profiler/scoped_tracker.h"
20 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
21 #include "base/stl_util.h" 22 #include "base/stl_util.h"
22 #include "base/threading/sequenced_worker_pool.h" 23 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
24 #include "content/browser/renderer_host/render_process_host_impl.h" 25 #include "content/browser/renderer_host/render_process_host_impl.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 case blink::WebNavigationHintType::LinkTapUnconfirmed: 95 case blink::WebNavigationHintType::LinkTapUnconfirmed:
95 return ServiceWorkerMetrics::EventType:: 96 return ServiceWorkerMetrics::EventType::
96 NAVIGATION_HINT_LINK_TAP_UNCONFIRMED; 97 NAVIGATION_HINT_LINK_TAP_UNCONFIRMED;
97 case blink::WebNavigationHintType::LinkTapDown: 98 case blink::WebNavigationHintType::LinkTapDown:
98 return ServiceWorkerMetrics::EventType::NAVIGATION_HINT_LINK_TAP_DOWN; 99 return ServiceWorkerMetrics::EventType::NAVIGATION_HINT_LINK_TAP_DOWN;
99 } 100 }
100 NOTREACHED() << "Unexpected navigation hint" << static_cast<int>(type); 101 NOTREACHED() << "Unexpected navigation hint" << static_cast<int>(type);
101 return ServiceWorkerMetrics::EventType::UNKNOWN; 102 return ServiceWorkerMetrics::EventType::UNKNOWN;
102 } 103 }
103 104
105 void StatusCallbackRunner(const base::Closure& callback,
106 ServiceWorkerStatusCode status) {
107 callback.Run();
108 }
109
104 } // namespace 110 } // namespace
105 111
106 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( 112 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent(
107 const std::set<std::string>& header_names) { 113 const std::set<std::string>& header_names) {
108 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 114 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
109 tracked_objects::ScopedTracker tracking_profile( 115 tracked_objects::ScopedTracker tracking_profile(
110 FROM_HERE_WITH_EXPLICIT_FUNCTION( 116 FROM_HERE_WITH_EXPLICIT_FUNCTION(
111 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent")); 117 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent"));
112 DCHECK_CURRENTLY_ON(BrowserThread::IO); 118 DCHECK_CURRENTLY_ON(BrowserThread::IO);
113 g_excluded_header_name_set.Get().insert(header_names.begin(), 119 g_excluded_header_name_set.Get().insert(header_names.begin(),
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 const CheckHasServiceWorkerCallback& callback, 489 const CheckHasServiceWorkerCallback& callback,
484 bool has_service_worker) { 490 bool has_service_worker) {
485 DCHECK_CURRENTLY_ON(BrowserThread::IO); 491 DCHECK_CURRENTLY_ON(BrowserThread::IO);
486 492
487 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 493 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
488 base::Bind(callback, has_service_worker)); 494 base::Bind(callback, has_service_worker));
489 } 495 }
490 496
491 void ServiceWorkerContextWrapper::StopAllServiceWorkersForOrigin( 497 void ServiceWorkerContextWrapper::StopAllServiceWorkersForOrigin(
492 const GURL& origin) { 498 const GURL& origin) {
499 StopAllServiceWorkersForOriginWithCallback(origin,
500 base::Bind(&base::DoNothing));
501 }
502
503 void ServiceWorkerContextWrapper::StopAllServiceWorkersForOriginWithCallback(
504 const GURL& origin,
505 const base::Closure& callback) {
493 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 506 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
494 BrowserThread::PostTask( 507 BrowserThread::PostTask(
495 BrowserThread::IO, FROM_HERE, 508 BrowserThread::IO, FROM_HERE,
496 base::Bind(&ServiceWorkerContextWrapper::StopAllServiceWorkersForOrigin, 509 base::Bind(&ServiceWorkerContextWrapper::
497 this, origin)); 510 StopAllServiceWorkersForOriginWithCallback,
511 this, origin, callback));
498 return; 512 return;
499 } 513 }
500 if (!context_core_.get()) { 514 if (!context_core_.get()) {
501 return; 515 return;
502 } 516 }
503 std::vector<ServiceWorkerVersionInfo> live_versions = GetAllLiveVersionInfo(); 517 std::vector<ServiceWorkerVersionInfo> live_versions = GetAllLiveVersionInfo();
518 std::vector<ServiceWorkerVersion*> versions_to_stop;
504 for (const ServiceWorkerVersionInfo& info : live_versions) { 519 for (const ServiceWorkerVersionInfo& info : live_versions) {
505 ServiceWorkerVersion* version = GetLiveVersion(info.version_id); 520 ServiceWorkerVersion* version = GetLiveVersion(info.version_id);
506 if (version && version->scope().GetOrigin() == origin) 521 if (version && version->scope().GetOrigin() == origin)
507 version->StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 522 versions_to_stop.push_back(version);
523 }
524 if (!versions_to_stop.empty()) {
525 base::Closure barrier_closure =
526 BarrierClosure(versions_to_stop.size(), callback);
527 for (ServiceWorkerVersion* version : versions_to_stop)
528 version->StopWorker(base::Bind(&StatusCallbackRunner, barrier_closure));
529 } else {
530 RunSoon(callback);
508 } 531 }
509 } 532 }
510 533
511 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( 534 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate(
512 ServiceWorkerStatusCode status, 535 ServiceWorkerStatusCode status,
513 scoped_refptr<ServiceWorkerRegistration> registration) { 536 scoped_refptr<ServiceWorkerRegistration> registration) {
514 DCHECK_CURRENTLY_ON(BrowserThread::IO); 537 DCHECK_CURRENTLY_ON(BrowserThread::IO);
515 538
516 if (status != SERVICE_WORKER_OK) 539 if (status != SERVICE_WORKER_OK)
517 return; 540 return;
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 observer_list_->Notify(FROM_HERE, 931 observer_list_->Notify(FROM_HERE,
909 &ServiceWorkerContextObserver::OnStorageWiped); 932 &ServiceWorkerContextObserver::OnStorageWiped);
910 } 933 }
911 934
912 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { 935 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
913 DCHECK_CURRENTLY_ON(BrowserThread::IO); 936 DCHECK_CURRENTLY_ON(BrowserThread::IO);
914 return context_core_.get(); 937 return context_core_.get();
915 } 938 }
916 939
917 } // namespace content 940 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698