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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/timer/timer.h" |
17 #include "content/browser/service_worker/embedded_worker_instance.h" | 18 #include "content/browser/service_worker/embedded_worker_instance.h" |
18 #include "content/browser/service_worker/service_worker_script_cache_map.h" | 19 #include "content/browser/service_worker/service_worker_script_cache_map.h" |
19 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
20 #include "content/common/service_worker/service_worker_status_code.h" | 21 #include "content/common/service_worker/service_worker_status_code.h" |
21 #include "content/common/service_worker/service_worker_types.h" | 22 #include "content/common/service_worker/service_worker_types.h" |
22 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" | 23 #include "third_party/WebKit/public/platform/WebServiceWorkerEventResult.h" |
23 | 24 |
24 class GURL; | 25 class GURL; |
25 | 26 |
26 namespace content { | 27 namespace content { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 182 |
182 // Returns true if this has at least one process to run. | 183 // Returns true if this has at least one process to run. |
183 bool HasProcessToRun() const; | 184 bool HasProcessToRun() const; |
184 | 185 |
185 // Adds and removes |provider_host| as a controllee of this ServiceWorker. | 186 // Adds and removes |provider_host| as a controllee of this ServiceWorker. |
186 void AddControllee(ServiceWorkerProviderHost* provider_host); | 187 void AddControllee(ServiceWorkerProviderHost* provider_host); |
187 void RemoveControllee(ServiceWorkerProviderHost* provider_host); | 188 void RemoveControllee(ServiceWorkerProviderHost* provider_host); |
188 void AddPendingControllee(ServiceWorkerProviderHost* provider_host); | 189 void AddPendingControllee(ServiceWorkerProviderHost* provider_host); |
189 void RemovePendingControllee(ServiceWorkerProviderHost* provider_host); | 190 void RemovePendingControllee(ServiceWorkerProviderHost* provider_host); |
190 | 191 |
191 // Returns if it has (non-pending) controllee. | 192 // Returns if it has controllee. |
192 bool HasControllee() const { return !controllee_map_.empty(); } | 193 bool HasControllee() const { return !controllee_map_.empty(); } |
193 | 194 |
194 // Adds and removes Listeners. | 195 // Adds and removes Listeners. |
195 void AddListener(Listener* listener); | 196 void AddListener(Listener* listener); |
196 void RemoveListener(Listener* listener); | 197 void RemoveListener(Listener* listener); |
197 | 198 |
198 ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; } | 199 ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; } |
199 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } | 200 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } |
200 | 201 |
201 private: | 202 private: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 void OnInstallEventFinished(int request_id, | 234 void OnInstallEventFinished(int request_id, |
234 blink::WebServiceWorkerEventResult result); | 235 blink::WebServiceWorkerEventResult result); |
235 void OnFetchEventFinished(int request_id, | 236 void OnFetchEventFinished(int request_id, |
236 ServiceWorkerFetchEventResult result, | 237 ServiceWorkerFetchEventResult result, |
237 const ServiceWorkerResponse& response); | 238 const ServiceWorkerResponse& response); |
238 void OnSyncEventFinished(int request_id); | 239 void OnSyncEventFinished(int request_id); |
239 void OnPostMessageToDocument(int client_id, | 240 void OnPostMessageToDocument(int client_id, |
240 const base::string16& message, | 241 const base::string16& message, |
241 const std::vector<int>& sent_message_port_ids); | 242 const std::vector<int>& sent_message_port_ids); |
242 | 243 |
| 244 void ScheduleStopWorker(); |
| 245 |
243 const int64 version_id_; | 246 const int64 version_id_; |
244 int64 registration_id_; | 247 int64 registration_id_; |
245 GURL script_url_; | 248 GURL script_url_; |
246 GURL scope_; | 249 GURL scope_; |
247 Status status_; | 250 Status status_; |
248 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; | 251 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; |
249 std::vector<StatusCallback> start_callbacks_; | 252 std::vector<StatusCallback> start_callbacks_; |
250 std::vector<StatusCallback> stop_callbacks_; | 253 std::vector<StatusCallback> stop_callbacks_; |
251 std::vector<base::Closure> status_change_callbacks_; | 254 std::vector<base::Closure> status_change_callbacks_; |
252 | 255 |
253 // Message callbacks. | 256 // Message callbacks. |
254 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; | 257 IDMap<StatusCallback, IDMapOwnPointer> activate_callbacks_; |
255 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; | 258 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; |
256 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; | 259 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; |
257 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; | 260 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; |
258 | 261 |
259 ControlleeMap controllee_map_; | 262 ControlleeMap controllee_map_; |
260 ControlleeByIDMap controllee_by_id_; | 263 ControlleeByIDMap controllee_by_id_; |
261 base::WeakPtr<ServiceWorkerContextCore> context_; | 264 base::WeakPtr<ServiceWorkerContextCore> context_; |
262 ObserverList<Listener> listeners_; | 265 ObserverList<Listener> listeners_; |
263 ServiceWorkerScriptCacheMap script_cache_map_; | 266 ServiceWorkerScriptCacheMap script_cache_map_; |
| 267 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; |
264 | 268 |
265 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 269 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
266 | 270 |
267 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 271 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
268 }; | 272 }; |
269 | 273 |
270 } // namespace content | 274 } // namespace content |
271 | 275 |
272 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 276 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |