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_PROVIDER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
7 | 7 |
| 8 #include <set> |
| 9 |
8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
9 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
10 #include "webkit/common/resource_type.h" | 12 #include "webkit/common/resource_type.h" |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
14 class ServiceWorkerVersion; | 16 class ServiceWorkerVersion; |
15 | 17 |
16 // This class is the browser-process representation of a serice worker | 18 // This class is the browser-process representation of a serice worker |
17 // provider. There is a provider per document and the lifetime of this | 19 // provider. There is a provider per document and the lifetime of this |
18 // object is tied to the lifetime of its document in the renderer process. | 20 // object is tied to the lifetime of its document in the renderer process. |
19 // This class holds service worker state this is scoped to an individual | 21 // This class holds service worker state this is scoped to an individual |
20 // document. | 22 // document. |
21 class ServiceWorkerProviderHost | 23 class ServiceWorkerProviderHost |
22 : public base::SupportsWeakPtr<ServiceWorkerProviderHost> { | 24 : public base::SupportsWeakPtr<ServiceWorkerProviderHost> { |
23 public: | 25 public: |
24 ServiceWorkerProviderHost(int process_id, | 26 ServiceWorkerProviderHost(int process_id, |
25 int provider_id); | 27 int provider_id); |
26 ~ServiceWorkerProviderHost(); | 28 ~ServiceWorkerProviderHost(); |
27 | 29 |
28 int process_id() const { return process_id_; } | 30 int process_id() const { return process_id_; } |
29 int provider_id() const { return provider_id_; } | 31 int provider_id() const { return provider_id_; } |
30 | 32 |
| 33 // Adds and removes script client thread ID, who is listening events |
| 34 // dispatched from ServiceWorker to the document (and any of its dedicated |
| 35 // workers) corresponding to this provider. |
| 36 void AddScriptClient(int thread_id); |
| 37 void RemoveScriptClient(int thread_id); |
| 38 |
31 // The service worker version that corresponds with navigator.serviceWorker | 39 // The service worker version that corresponds with navigator.serviceWorker |
32 // for our document. | 40 // for our document. |
33 ServiceWorkerVersion* associated_version() const { | 41 ServiceWorkerVersion* associated_version() const { |
34 return associated_version_.get(); | 42 return associated_version_.get(); |
35 } | 43 } |
36 | 44 |
| 45 const std::set<int>& script_client_thread_ids() const { |
| 46 return script_client_thread_ids_; |
| 47 } |
| 48 |
37 // Returns true if this provider host should handle requests for | 49 // Returns true if this provider host should handle requests for |
38 // |resource_type|. | 50 // |resource_type|. |
39 bool ShouldHandleRequest(ResourceType::Type resource_type) const; | 51 bool ShouldHandleRequest(ResourceType::Type resource_type) const; |
40 | 52 |
41 private: | 53 private: |
42 const int process_id_; | 54 const int process_id_; |
43 const int provider_id_; | 55 const int provider_id_; |
| 56 std::set<int> script_client_thread_ids_; |
44 scoped_refptr<ServiceWorkerVersion> associated_version_; | 57 scoped_refptr<ServiceWorkerVersion> associated_version_; |
45 }; | 58 }; |
46 | 59 |
47 } // namespace content | 60 } // namespace content |
48 | 61 |
49 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 62 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |