OLD | NEW |
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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 298 |
299 ServiceWorkerVersion::ServiceWorkerVersion( | 299 ServiceWorkerVersion::ServiceWorkerVersion( |
300 ServiceWorkerRegistration* registration, | 300 ServiceWorkerRegistration* registration, |
301 const GURL& script_url, | 301 const GURL& script_url, |
302 int64_t version_id, | 302 int64_t version_id, |
303 base::WeakPtr<ServiceWorkerContextCore> context) | 303 base::WeakPtr<ServiceWorkerContextCore> context) |
304 : version_id_(version_id), | 304 : version_id_(version_id), |
305 registration_id_(registration->id()), | 305 registration_id_(registration->id()), |
306 script_url_(script_url), | 306 script_url_(script_url), |
307 scope_(registration->pattern()), | 307 scope_(registration->pattern()), |
| 308 fetch_handler_existence_(FetchHandlerExistence::UNKNOWN), |
308 context_(context), | 309 context_(context), |
309 script_cache_map_(this, context), | 310 script_cache_map_(this, context), |
310 ping_controller_(new PingController(this)), | 311 ping_controller_(new PingController(this)), |
311 should_exclude_from_uma_( | 312 should_exclude_from_uma_( |
312 ServiceWorkerMetrics::ShouldExcludeURLFromHistogram(scope_)), | 313 ServiceWorkerMetrics::ShouldExcludeURLFromHistogram(scope_)), |
313 weak_factory_(this) { | 314 weak_factory_(this) { |
314 DCHECK_NE(kInvalidServiceWorkerVersionId, version_id); | 315 DCHECK_NE(kInvalidServiceWorkerVersionId, version_id); |
315 DCHECK(context_); | 316 DCHECK(context_); |
316 DCHECK(registration); | 317 DCHECK(registration); |
317 DCHECK(script_url_.is_valid()); | 318 DCHECK(script_url_.is_valid()); |
(...skipping 24 matching lines...) Expand all Loading... |
342 embedded_worker_->RemoveListener(this); | 343 embedded_worker_->RemoveListener(this); |
343 } | 344 } |
344 | 345 |
345 void ServiceWorkerVersion::SetStatus(Status status) { | 346 void ServiceWorkerVersion::SetStatus(Status status) { |
346 if (status_ == status) | 347 if (status_ == status) |
347 return; | 348 return; |
348 | 349 |
349 TRACE_EVENT2("ServiceWorker", "ServiceWorkerVersion::SetStatus", "Script URL", | 350 TRACE_EVENT2("ServiceWorker", "ServiceWorkerVersion::SetStatus", "Script URL", |
350 script_url_.spec(), "New Status", VersionStatusToString(status)); | 351 script_url_.spec(), "New Status", VersionStatusToString(status)); |
351 | 352 |
| 353 // |fetch_handler_existence_| must be set before setting the status to |
| 354 // INSTALLED, |
| 355 // ACTIVATING or ACTIVATED. |
| 356 DCHECK(fetch_handler_existence_ != FetchHandlerExistence::UNKNOWN || |
| 357 !(status == INSTALLED || status == ACTIVATING || status == ACTIVATED)); |
| 358 |
352 status_ = status; | 359 status_ = status; |
353 if (skip_waiting_ && status_ == ACTIVATED) { | 360 if (skip_waiting_ && status_ == ACTIVATED) { |
354 for (int request_id : pending_skip_waiting_requests_) | 361 for (int request_id : pending_skip_waiting_requests_) |
355 DidSkipWaiting(request_id); | 362 DidSkipWaiting(request_id); |
356 pending_skip_waiting_requests_.clear(); | 363 pending_skip_waiting_requests_.clear(); |
357 } | 364 } |
358 | 365 |
359 // OnVersionStateChanged() invokes updates of the status using state | 366 // OnVersionStateChanged() invokes updates of the status using state |
360 // change IPC at ServiceWorkerHandle (for JS-land on renderer process) and | 367 // change IPC at ServiceWorkerHandle (for JS-land on renderer process) and |
361 // ServiceWorkerContextCore (for devtools and serviceworker-internals). | 368 // ServiceWorkerContextCore (for devtools and serviceworker-internals). |
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1757 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1764 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
1758 idle_time_); | 1765 idle_time_); |
1759 } | 1766 } |
1760 | 1767 |
1761 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { | 1768 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { |
1762 start_worker_first_purpose_ = base::nullopt; | 1769 start_worker_first_purpose_ = base::nullopt; |
1763 RunCallbacks(this, &start_callbacks_, status); | 1770 RunCallbacks(this, &start_callbacks_, status); |
1764 } | 1771 } |
1765 | 1772 |
1766 } // namespace content | 1773 } // namespace content |
OLD | NEW |