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

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

Issue 1647323002: Move activate event dispatching out of ServiceWorkerVersion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-install-event
Patch Set: Created 4 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_registration.h" 5 #include "content/browser/service_worker/service_worker_registration.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
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_info.h" 10 #include "content/browser/service_worker/service_worker_info.h"
11 #include "content/browser/service_worker/service_worker_metrics.h" 11 #include "content/browser/service_worker/service_worker_metrics.h"
12 #include "content/browser/service_worker/service_worker_register_job.h" 12 #include "content/browser/service_worker/service_worker_register_job.h"
13 #include "content/common/service_worker/service_worker_messages.h"
13 #include "content/common/service_worker/service_worker_utils.h" 14 #include "content/common/service_worker/service_worker_utils.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 namespace { 19 namespace {
19 20
20 ServiceWorkerVersionInfo GetVersionInfo(ServiceWorkerVersion* version) { 21 ServiceWorkerVersionInfo GetVersionInfo(ServiceWorkerVersion* version) {
21 if (!version) 22 if (!version)
22 return ServiceWorkerVersionInfo(); 23 return ServiceWorkerVersionInfo();
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 SetActiveVersion(activating_version); 279 SetActiveVersion(activating_version);
279 280
280 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and 281 // "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and
281 // "activating" as arguments." 282 // "activating" as arguments."
282 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING); 283 activating_version->SetStatus(ServiceWorkerVersion::ACTIVATING);
283 // "9. Fire a simple event named controllerchange..." 284 // "9. Fire a simple event named controllerchange..."
284 if (activating_version->skip_waiting()) 285 if (activating_version->skip_waiting())
285 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this)); 286 FOR_EACH_OBSERVER(Listener, listeners_, OnSkippedWaiting(this));
286 287
287 // "10. Queue a task to fire an event named activate..." 288 // "10. Queue a task to fire an event named activate..."
288 activating_version->DispatchActivateEvent( 289 activating_version->RunAfterStartWorker(
289 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, 290 base::Bind(&ServiceWorkerRegistration::DispatchActivateEvent, this,
290 this, activating_version)); 291 activating_version),
292 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, this,
293 activating_version));
291 } 294 }
292 295
293 void ServiceWorkerRegistration::DeleteVersion( 296 void ServiceWorkerRegistration::DeleteVersion(
294 const scoped_refptr<ServiceWorkerVersion>& version) { 297 const scoped_refptr<ServiceWorkerVersion>& version) {
295 DCHECK_EQ(id(), version->registration_id()); 298 DCHECK_EQ(id(), version->registration_id());
296 299
297 UnsetVersion(version.get()); 300 UnsetVersion(version.get());
298 301
299 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it = 302 for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
300 context_->GetProviderHostIterator(); 303 context_->GetProviderHostIterator();
(...skipping 30 matching lines...) Expand all
331 } 334 }
332 335
333 void ServiceWorkerRegistration::RegisterRegistrationFinishedCallback( 336 void ServiceWorkerRegistration::RegisterRegistrationFinishedCallback(
334 const base::Closure& callback) { 337 const base::Closure& callback) {
335 // This should only be called if the registration is in progress. 338 // This should only be called if the registration is in progress.
336 DCHECK(!active_version() && !waiting_version() && !is_uninstalled() && 339 DCHECK(!active_version() && !waiting_version() && !is_uninstalled() &&
337 !is_uninstalling()); 340 !is_uninstalling());
338 registration_finished_callbacks_.push_back(callback); 341 registration_finished_callbacks_.push_back(callback);
339 } 342 }
340 343
344 void ServiceWorkerRegistration::DispatchActivateEvent(
345 const scoped_refptr<ServiceWorkerVersion>& activating_version) {
346 if (activating_version != active_version()) {
347 OnActivateEventFinished(activating_version, SERVICE_WORKER_ERROR_FAILED);
348 return;
349 }
350
351 DCHECK_EQ(ServiceWorkerVersion::ACTIVATING, activating_version->status())
352 << activating_version->status();
nhiroki 2016/02/01 04:23:19 "<< activating_version->status()" wouldn't be nece
Marijn Kruisselbrink 2016/02/01 19:43:08 Good point. Not sure why the old code in SWVersion
353 DCHECK_EQ(ServiceWorkerVersion::RUNNING, activating_version->running_status())
354 << "Worker stopped too soon after it was started.";
355 int request_id = activating_version->StartRequest(
356 ServiceWorkerMetrics::EventType::ACTIVATE,
357 base::Bind(&ServiceWorkerRegistration::OnActivateEventFinished, this,
358 activating_version));
359 activating_version
360 ->DispatchSimpleEvent<ServiceWorkerHostMsg_ActivateEventFinished>(
361 request_id, ServiceWorkerMsg_ActivateEvent(request_id));
362 }
363
341 void ServiceWorkerRegistration::OnActivateEventFinished( 364 void ServiceWorkerRegistration::OnActivateEventFinished(
342 ServiceWorkerVersion* activating_version, 365 const scoped_refptr<ServiceWorkerVersion>& activating_version,
343 ServiceWorkerStatusCode status) { 366 ServiceWorkerStatusCode status) {
344 if (!context_ || activating_version != active_version() || 367 if (!context_ || activating_version != active_version() ||
345 activating_version->status() != ServiceWorkerVersion::ACTIVATING) 368 activating_version->status() != ServiceWorkerVersion::ACTIVATING)
346 return; 369 return;
347 370
348 // |status| is just for UMA. Once we've attempted to dispatch the activate 371 // |status| is just for UMA. Once we've attempted to dispatch the activate
349 // event to an installed worker, it's committed to becoming active. 372 // event to an installed worker, it's committed to becoming active.
350 ServiceWorkerMetrics::RecordActivateEventStatus(status); 373 ServiceWorkerMetrics::RecordActivateEventStatus(status);
351 374
352 // "Run the Update State algorithm passing registration's active worker and 375 // "Run the Update State algorithm passing registration's active worker and
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 if (!context_) { 431 if (!context_) {
409 callback.Run(SERVICE_WORKER_ERROR_ABORT); 432 callback.Run(SERVICE_WORKER_ERROR_ABORT);
410 return; 433 return;
411 } 434 }
412 context_->storage()->NotifyDoneInstallingRegistration( 435 context_->storage()->NotifyDoneInstallingRegistration(
413 this, version.get(), status); 436 this, version.get(), status);
414 callback.Run(status); 437 callback.Run(status);
415 } 438 }
416 439
417 } // namespace content 440 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698