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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <functional> | 10 #include <functional> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // unregistration or replace. | 83 // unregistration or replace. |
84 }; | 84 }; |
85 | 85 |
86 // Behavior when a request times out. | 86 // Behavior when a request times out. |
87 enum TimeoutBehavior { | 87 enum TimeoutBehavior { |
88 KILL_ON_TIMEOUT, // Kill the worker if this request times out. | 88 KILL_ON_TIMEOUT, // Kill the worker if this request times out. |
89 CONTINUE_ON_TIMEOUT // Keep the worker alive, only abandon the request that | 89 CONTINUE_ON_TIMEOUT // Keep the worker alive, only abandon the request that |
90 // timed out. | 90 // timed out. |
91 }; | 91 }; |
92 | 92 |
| 93 // Whether the version has fetch handlers or not. |
| 94 enum class FetchHandlerExistence { |
| 95 UNKNOWN, // This version is a new version and not installed yet. |
| 96 EXISTS, |
| 97 DOES_NOT_EXIST, |
| 98 }; |
| 99 |
93 class Listener { | 100 class Listener { |
94 public: | 101 public: |
95 virtual void OnRunningStateChanged(ServiceWorkerVersion* version) {} | 102 virtual void OnRunningStateChanged(ServiceWorkerVersion* version) {} |
96 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) {} | 103 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) {} |
97 virtual void OnMainScriptHttpResponseInfoSet( | 104 virtual void OnMainScriptHttpResponseInfoSet( |
98 ServiceWorkerVersion* version) {} | 105 ServiceWorkerVersion* version) {} |
99 virtual void OnErrorReported(ServiceWorkerVersion* version, | 106 virtual void OnErrorReported(ServiceWorkerVersion* version, |
100 const base::string16& error_message, | 107 const base::string16& error_message, |
101 int line_number, | 108 int line_number, |
102 int column_number, | 109 int column_number, |
(...skipping 24 matching lines...) Expand all Loading... |
127 | 134 |
128 int64_t version_id() const { return version_id_; } | 135 int64_t version_id() const { return version_id_; } |
129 int64_t registration_id() const { return registration_id_; } | 136 int64_t registration_id() const { return registration_id_; } |
130 const GURL& script_url() const { return script_url_; } | 137 const GURL& script_url() const { return script_url_; } |
131 const GURL& scope() const { return scope_; } | 138 const GURL& scope() const { return scope_; } |
132 EmbeddedWorkerStatus running_status() const { | 139 EmbeddedWorkerStatus running_status() const { |
133 return embedded_worker_->status(); | 140 return embedded_worker_->status(); |
134 } | 141 } |
135 ServiceWorkerVersionInfo GetInfo(); | 142 ServiceWorkerVersionInfo GetInfo(); |
136 Status status() const { return status_; } | 143 Status status() const { return status_; } |
137 bool has_fetch_handler() const { return has_fetch_handler_; } | 144 |
138 void set_has_fetch_handler(bool has_fetch_handler) { | 145 // This status is set to EXISTS or DOES_NOT_EXIST when the install event has |
139 has_fetch_handler_ = has_fetch_handler; | 146 // been executed in a new version or when an installed version is loaded from |
| 147 // the storage. When a new version is not installed yet, it is UNKNOW. |
| 148 FetchHandlerExistence fetch_handler_existence() const { |
| 149 return fetch_handler_existence_; |
| 150 } |
| 151 void set_fetch_handler_existence(FetchHandlerExistence existence) { |
| 152 DCHECK_EQ(fetch_handler_existence_, FetchHandlerExistence::UNKNOWN); |
| 153 DCHECK_NE(existence, FetchHandlerExistence::UNKNOWN); |
| 154 fetch_handler_existence_ = existence; |
140 } | 155 } |
141 | 156 |
142 const std::vector<GURL>& foreign_fetch_scopes() const { | 157 const std::vector<GURL>& foreign_fetch_scopes() const { |
143 return foreign_fetch_scopes_; | 158 return foreign_fetch_scopes_; |
144 } | 159 } |
145 void set_foreign_fetch_scopes(const std::vector<GURL>& scopes) { | 160 void set_foreign_fetch_scopes(const std::vector<GURL>& scopes) { |
146 foreign_fetch_scopes_ = scopes; | 161 foreign_fetch_scopes_ = scopes; |
147 } | 162 } |
148 | 163 |
149 const std::vector<url::Origin>& foreign_fetch_origins() const { | 164 const std::vector<url::Origin>& foreign_fetch_origins() const { |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 // Resets |start_worker_first_purpose_| and fires and clears all start | 671 // Resets |start_worker_first_purpose_| and fires and clears all start |
657 // callbacks. | 672 // callbacks. |
658 void FinishStartWorker(ServiceWorkerStatusCode status); | 673 void FinishStartWorker(ServiceWorkerStatusCode status); |
659 | 674 |
660 const int64_t version_id_; | 675 const int64_t version_id_; |
661 const int64_t registration_id_; | 676 const int64_t registration_id_; |
662 const GURL script_url_; | 677 const GURL script_url_; |
663 const GURL scope_; | 678 const GURL scope_; |
664 std::vector<GURL> foreign_fetch_scopes_; | 679 std::vector<GURL> foreign_fetch_scopes_; |
665 std::vector<url::Origin> foreign_fetch_origins_; | 680 std::vector<url::Origin> foreign_fetch_origins_; |
666 bool has_fetch_handler_ = true; | 681 FetchHandlerExistence fetch_handler_existence_; |
667 | 682 |
668 Status status_ = NEW; | 683 Status status_ = NEW; |
669 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_; | 684 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_; |
670 std::vector<StatusCallback> start_callbacks_; | 685 std::vector<StatusCallback> start_callbacks_; |
671 std::vector<StatusCallback> stop_callbacks_; | 686 std::vector<StatusCallback> stop_callbacks_; |
672 std::vector<base::Closure> status_change_callbacks_; | 687 std::vector<base::Closure> status_change_callbacks_; |
673 | 688 |
674 // Holds in-flight requests, including requests due to outstanding push, | 689 // Holds in-flight requests, including requests due to outstanding push, |
675 // fetch, sync, etc. events. | 690 // fetch, sync, etc. events. |
676 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_; | 691 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 | 828 |
814 // At this point |this| can have been deleted, so don't do anything other | 829 // At this point |this| can have been deleted, so don't do anything other |
815 // than returning. | 830 // than returning. |
816 | 831 |
817 return true; | 832 return true; |
818 } | 833 } |
819 | 834 |
820 } // namespace content | 835 } // namespace content |
821 | 836 |
822 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 837 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |