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_provider_host.cc

Issue 871853002: ServiceWorker: add ServiceWorkerClients.claim() support (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fetch registrations from DB Created 5 years, 10 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_provider_host.h" 5 #include "content/browser/service_worker/service_worker_provider_host.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "content/browser/message_port_message_filter.h" 8 #include "content/browser/message_port_message_filter.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_context_request_handler. h" 10 #include "content/browser/service_worker/service_worker_context_request_handler. h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 48 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
49 int render_process_id, int render_frame_id, int provider_id, 49 int render_process_id, int render_frame_id, int provider_id,
50 base::WeakPtr<ServiceWorkerContextCore> context, 50 base::WeakPtr<ServiceWorkerContextCore> context,
51 ServiceWorkerDispatcherHost* dispatcher_host) 51 ServiceWorkerDispatcherHost* dispatcher_host)
52 : render_process_id_(render_process_id), 52 : render_process_id_(render_process_id),
53 render_frame_id_(render_frame_id), 53 render_frame_id_(render_frame_id),
54 provider_id_(provider_id), 54 provider_id_(provider_id),
55 context_(context), 55 context_(context),
56 dispatcher_host_(dispatcher_host), 56 dispatcher_host_(dispatcher_host),
57 allow_association_(true) { 57 allow_association_(true),
58 is_claiming_(false) {
58 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); 59 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_);
59 } 60 }
60 61
61 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { 62 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() {
62 // Clear docurl so the deferred activation of a waiting worker 63 // Clear docurl so the deferred activation of a waiting worker
63 // won't associate the new version with a provider being destroyed. 64 // won't associate the new version with a provider being destroyed.
64 document_url_ = GURL(); 65 document_url_ = GURL();
65 if (controlling_version_.get()) 66 if (controlling_version_.get())
66 controlling_version_->RemoveControllee(this); 67 controlling_version_->RemoveControllee(this);
67 if (associated_registration_.get()) { 68 if (associated_registration_.get()) {
(...skipping 17 matching lines...) Expand all
85 // A client is "using" a registration if it is controlled by the active 86 // A client is "using" a registration if it is controlled by the active
86 // worker of the registration. skipWaiting doesn't cause a client to start 87 // worker of the registration. skipWaiting doesn't cause a client to start
87 // using the registration. 88 // using the registration.
88 if (!controlling_version_) 89 if (!controlling_version_)
89 return; 90 return;
90 ServiceWorkerVersion* active_version = registration->active_version(); 91 ServiceWorkerVersion* active_version = registration->active_version();
91 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); 92 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING);
92 SetControllerVersionAttribute(active_version); 93 SetControllerVersionAttribute(active_version);
93 } 94 }
94 95
96 void ServiceWorkerProviderHost::ClaimedByRegistration(
97 ServiceWorkerRegistration* registration) {
98 DCHECK(registration->active_version());
99 is_claiming_ = true;
xiang 2015/01/30 07:18:57 A flag is needed here because AssociateRegistratio
100 if (registration == associated_registration_) {
101 SetControllerVersionAttribute(registration->active_version());
102 } else {
103 DisassociateRegistration();
falken 2015/01/30 10:24:02 As mentioned before, it looks wrong to Disassociat
michaeln 2015/01/30 23:43:07 +1 if (allow_registration_) prior to calling Disas
xiang 2015/02/02 04:24:58 Done.
104 if (CanAssociateRegistration(registration))
105 AssociateRegistration(registration);
106 }
107 is_claiming_ = false;
108 }
109
95 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { 110 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) {
96 DCHECK(!url.has_ref()); 111 DCHECK(!url.has_ref());
97 document_url_ = url; 112 document_url_ = url;
98 } 113 }
99 114
100 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { 115 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) {
101 topmost_frame_url_ = url; 116 topmost_frame_url_ = url;
102 } 117 }
103 118
104 void ServiceWorkerProviderHost::SetControllerVersionAttribute( 119 void ServiceWorkerProviderHost::SetControllerVersionAttribute(
105 ServiceWorkerVersion* version) { 120 ServiceWorkerVersion* version) {
106 if (version == controlling_version_.get()) 121 if (version == controlling_version_.get())
107 return; 122 return;
108 123
109 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; 124 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_;
110 controlling_version_ = version; 125 controlling_version_ = version;
111 if (version) 126 if (version)
112 version->AddControllee(this); 127 version->AddControllee(this);
113 if (previous_version.get()) 128 if (previous_version.get())
114 previous_version->RemoveControllee(this); 129 previous_version->RemoveControllee(this);
115 130
116 if (!dispatcher_host_) 131 if (!dispatcher_host_)
117 return; // Could be NULL in some tests. 132 return; // Could be NULL in some tests.
118 133
119 bool should_notify_controllerchange = 134 bool should_notify_controllerchange =
120 previous_version && version && version->skip_waiting(); 135 is_claiming_ || (previous_version && version && version->skip_waiting());
121 136
122 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( 137 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker(
123 kDocumentMainThreadId, provider_id(), 138 kDocumentMainThreadId, provider_id(),
124 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version), 139 dispatcher_host_->CreateAndRegisterServiceWorkerHandle(version),
125 should_notify_controllerchange)); 140 should_notify_controllerchange));
126 } 141 }
127 142
128 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { 143 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) {
129 if (!context_) 144 if (!context_)
130 return true; // System is shutting down. 145 return true; // System is shutting down.
(...skipping 12 matching lines...) Expand all
143 return false; 158 return false;
144 } 159 }
145 160
146 running_hosted_version_ = live_version; 161 running_hosted_version_ = live_version;
147 return true; 162 return true;
148 } 163 }
149 164
150 void ServiceWorkerProviderHost::AssociateRegistration( 165 void ServiceWorkerProviderHost::AssociateRegistration(
151 ServiceWorkerRegistration* registration) { 166 ServiceWorkerRegistration* registration) {
152 DCHECK(CanAssociateRegistration(registration)); 167 DCHECK(CanAssociateRegistration(registration));
153 if (associated_registration_.get())
154 DecreaseProcessReference(associated_registration_->pattern());
155 IncreaseProcessReference(registration->pattern()); 168 IncreaseProcessReference(registration->pattern());
156
157 associated_registration_ = registration; 169 associated_registration_ = registration;
158 associated_registration_->AddListener(this); 170 associated_registration_->AddListener(this);
159 SendAssociateRegistrationMessage(); 171 SendAssociateRegistrationMessage();
160 SetControllerVersionAttribute(registration->active_version()); 172 SetControllerVersionAttribute(registration->active_version());
161 } 173 }
162 174
163 void ServiceWorkerProviderHost::DisassociateRegistration() { 175 void ServiceWorkerProviderHost::DisassociateRegistration() {
164 if (!associated_registration_.get()) 176 if (!associated_registration_.get())
165 return; 177 return;
166 DecreaseProcessReference(associated_registration_->pattern()); 178 DecreaseProcessReference(associated_registration_->pattern());
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 context_->process_manager()->RemoveProcessReferenceFromPattern( 351 context_->process_manager()->RemoveProcessReferenceFromPattern(
340 pattern, render_process_id_); 352 pattern, render_process_id_);
341 } 353 }
342 } 354 }
343 355
344 bool ServiceWorkerProviderHost::IsContextAlive() { 356 bool ServiceWorkerProviderHost::IsContextAlive() {
345 return context_ != NULL; 357 return context_ != NULL;
346 } 358 }
347 359
348 } // namespace content 360 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698