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

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

Issue 2943583002: [extension SW] Support lazy events from extension service workers. (Closed)
Patch Set: Address comments from falken@ Created 3 years, 6 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 ServiceWorkerStatusCode status, 76 ServiceWorkerStatusCode status,
77 scoped_refptr<ServiceWorkerRegistration> registration) { 77 scoped_refptr<ServiceWorkerRegistration> registration) {
78 DCHECK_CURRENTLY_ON(BrowserThread::IO); 78 DCHECK_CURRENTLY_ON(BrowserThread::IO);
79 if (status != SERVICE_WORKER_OK || !registration->waiting_version()) 79 if (status != SERVICE_WORKER_OK || !registration->waiting_version())
80 return; 80 return;
81 81
82 registration->waiting_version()->set_skip_waiting(true); 82 registration->waiting_version()->set_skip_waiting(true);
83 registration->ActivateWaitingVersionWhenReady(); 83 registration->ActivateWaitingVersionWhenReady();
84 } 84 }
85 85
86 void DidStartWorker(
87 scoped_refptr<ServiceWorkerVersion> active_version,
88 ServiceWorkerContext::StartActiveWorkerCallback info_callback) {
89 EmbeddedWorkerInstance* instance = active_version->embedded_worker();
falken 2017/06/23 03:45:46 nit: Since this function doesn't care about the ve
lazyboy 2017/06/23 07:44:56 Done.
90 std::move(info_callback).Run(instance->process_id(), instance->thread_id());
91 }
92
93 void DidFailStartWorker(base::OnceClosure error_callback,
94 ServiceWorkerStatusCode code) {
95 std::move(error_callback).Run();
96 }
97
98 void FoundReadyRegistrationForStartActiveWorker(
99 ServiceWorkerContext::StartActiveWorkerCallback info_callback,
100 base::OnceClosure failure_callback,
101 ServiceWorkerStatusCode service_worker_status,
102 scoped_refptr<ServiceWorkerRegistration> service_worker_registration) {
103 DCHECK_CURRENTLY_ON(BrowserThread::IO);
104 if (service_worker_status == SERVICE_WORKER_OK) {
105 // Note: There might be a remote possibility that
106 // |service_worker_registration|'s active version might change between here
107 // and OnServiceWorkerStartedForStartActiveWorker, so use |active_version|.
falken 2017/06/23 03:45:46 This comment is a little confusing because at firs
lazyboy 2017/06/23 07:44:56 Done.
108 scoped_refptr<ServiceWorkerVersion> active_version =
109 service_worker_registration->active_version();
110 DCHECK(active_version.get());
111 active_version->RunAfterStartWorker(
112 ServiceWorkerMetrics::EventType::EXTERNAL_REQUEST,
113 base::Bind(&DidStartWorker, active_version,
114 base::Passed(&info_callback)),
115 base::Bind(&DidFailStartWorker, base::Passed(&failure_callback)));
116 } else {
117 std::move(failure_callback).Run();
118 }
119 }
120
86 } // namespace 121 } // namespace
87 122
88 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent( 123 void ServiceWorkerContext::AddExcludedHeadersForFetchEvent(
89 const std::set<std::string>& header_names) { 124 const std::set<std::string>& header_names) {
90 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 125 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
91 tracked_objects::ScopedTracker tracking_profile( 126 tracked_objects::ScopedTracker tracking_profile(
92 FROM_HERE_WITH_EXPLICIT_FUNCTION( 127 FROM_HERE_WITH_EXPLICIT_FUNCTION(
93 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent")); 128 "477117 ServiceWorkerContext::AddExcludedHeadersForFetchEvent"));
94 DCHECK_CURRENTLY_ON(BrowserThread::IO); 129 DCHECK_CURRENTLY_ON(BrowserThread::IO);
95 g_excluded_header_name_set.Get().insert(header_names.begin(), 130 g_excluded_header_name_set.Get().insert(header_names.begin(),
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 int64_t service_worker_version_id, 882 int64_t service_worker_version_id,
848 const std::string& request_uuid) { 883 const std::string& request_uuid) {
849 DCHECK_CURRENTLY_ON(BrowserThread::IO); 884 DCHECK_CURRENTLY_ON(BrowserThread::IO);
850 ServiceWorkerVersion* version = 885 ServiceWorkerVersion* version =
851 context()->GetLiveVersion(service_worker_version_id); 886 context()->GetLiveVersion(service_worker_version_id);
852 if (!version) 887 if (!version)
853 return false; 888 return false;
854 return version->FinishExternalRequest(request_uuid); 889 return version->FinishExternalRequest(request_uuid);
855 } 890 }
856 891
892 void ServiceWorkerContextWrapper::StartActiveWorkerForPattern(
893 const GURL& pattern,
894 StartActiveWorkerCallback info_callback,
895 base::OnceClosure failure_callback) {
896 DCHECK_CURRENTLY_ON(BrowserThread::IO);
897 FindReadyRegistrationForPattern(
898 pattern, base::Bind(&FoundReadyRegistrationForStartActiveWorker,
899 base::Passed(&info_callback),
900 base::Passed(&failure_callback)));
901 }
902
857 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( 903 void ServiceWorkerContextWrapper::DidDeleteAndStartOver(
858 ServiceWorkerStatusCode status) { 904 ServiceWorkerStatusCode status) {
859 DCHECK_CURRENTLY_ON(BrowserThread::IO); 905 DCHECK_CURRENTLY_ON(BrowserThread::IO);
860 if (status != SERVICE_WORKER_OK) { 906 if (status != SERVICE_WORKER_OK) {
861 context_core_.reset(); 907 context_core_.reset();
862 return; 908 return;
863 } 909 }
864 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); 910 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this));
865 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; 911 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully.";
866 context_core_->OnStorageWiped(); 912 context_core_->OnStorageWiped();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 service_worker_provider_id, 1018 service_worker_provider_id,
973 std::move(client_ptr_info)); 1019 std::move(client_ptr_info));
974 } 1020 }
975 1021
976 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { 1022 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() {
977 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1023 DCHECK_CURRENTLY_ON(BrowserThread::IO);
978 return context_core_.get(); 1024 return context_core_.get();
979 } 1025 }
980 1026
981 } // namespace content 1027 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698