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> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "webkit/common/resource_type.h" | 13 #include "webkit/common/resource_type.h" |
14 | 14 |
| 15 namespace ipc { |
| 16 class Sender; |
| 17 } |
| 18 |
15 namespace content { | 19 namespace content { |
16 | 20 |
17 class ServiceWorkerContextCore; | 21 class ServiceWorkerContextCore; |
| 22 class ServiceWorkerDispatcherHost; |
18 class ServiceWorkerVersion; | 23 class ServiceWorkerVersion; |
19 | 24 |
20 // This class is the browser-process representation of a serice worker | 25 // This class is the browser-process representation of a serice worker |
21 // provider. There is a provider per document and the lifetime of this | 26 // provider. There is a provider per document and the lifetime of this |
22 // object is tied to the lifetime of its document in the renderer process. | 27 // object is tied to the lifetime of its document in the renderer process. |
23 // This class holds service worker state this is scoped to an individual | 28 // This class holds service worker state this is scoped to an individual |
24 // document. | 29 // document. |
25 class CONTENT_EXPORT ServiceWorkerProviderHost | 30 class CONTENT_EXPORT ServiceWorkerProviderHost |
26 : public base::SupportsWeakPtr<ServiceWorkerProviderHost> { | 31 : public base::SupportsWeakPtr<ServiceWorkerProviderHost> { |
27 public: | 32 public: |
28 ServiceWorkerProviderHost(int process_id, | 33 ServiceWorkerProviderHost(int process_id, |
29 int provider_id, | 34 int provider_id, |
30 base::WeakPtr<ServiceWorkerContextCore> context); | 35 base::WeakPtr<ServiceWorkerContextCore> context, |
| 36 ServiceWorkerDispatcherHost* dispatcher_host); |
31 ~ServiceWorkerProviderHost(); | 37 ~ServiceWorkerProviderHost(); |
32 | 38 |
33 int process_id() const { return process_id_; } | 39 int process_id() const { return process_id_; } |
34 int provider_id() const { return provider_id_; } | 40 int provider_id() const { return provider_id_; } |
35 const std::set<int>& script_client_thread_ids() const { | 41 const std::set<int>& script_client_thread_ids() const { |
36 return script_client_thread_ids_; | 42 return script_client_thread_ids_; |
37 } | 43 } |
38 | 44 |
39 // The service worker version that corresponds with navigator.serviceWorker | 45 // The service worker version that corresponds with navigator.serviceWorker |
40 // for our document. | 46 // for our document. |
41 ServiceWorkerVersion* associated_version() const { | 47 ServiceWorkerVersion* associated_version() const { |
42 return associated_version_.get(); | 48 return associated_version_.get(); |
43 } | 49 } |
44 | 50 |
45 // The version, if any, that this provider is providing resource loads for. | 51 // The version, if any, that this provider is providing resource loads for. |
46 // This host observes resource loads made by the serviceworker itself. | 52 // This host observes resource loads made by the serviceworker itself. |
47 ServiceWorkerVersion* hosted_version() const { | 53 ServiceWorkerVersion* hosted_version() const { |
48 return hosted_version_.get(); | 54 return hosted_version_.get(); |
49 } | 55 } |
50 | 56 |
51 // Adds and removes script client thread ID, who is listening events | 57 // Adds and removes script client thread ID, who is listening events |
52 // dispatched from ServiceWorker to the document (and any of its dedicated | 58 // dispatched from ServiceWorker to the document (and any of its dedicated |
53 // workers) corresponding to this provider. | 59 // workers) corresponding to this provider. |
54 void AddScriptClient(int thread_id); | 60 void AddScriptClient(int thread_id); |
55 void RemoveScriptClient(int thread_id); | 61 void RemoveScriptClient(int thread_id); |
56 | 62 |
| 63 // TODO(kinuko): Change this into two set methods for .active and .pending. |
57 // Associate |version| to this provider host. Giving NULL to this method | 64 // Associate |version| to this provider host. Giving NULL to this method |
58 // will unset the associated version. | 65 // will unset the associated version. |
59 void AssociateVersion(ServiceWorkerVersion* version); | 66 void AssociateVersion(ServiceWorkerVersion* version); |
60 | 67 |
61 // Returns false if the version is not in the expected STARTING in our | 68 // Returns false if the version is not in the expected STARTING in our |
62 // our process state. That would be indicative of a bad IPC message. | 69 // our process state. That would be indicative of a bad IPC message. |
63 bool SetHostedVersionId(int64 versions_id); | 70 bool SetHostedVersionId(int64 versions_id); |
64 | 71 |
65 // Returns true if this provider host should handle requests for | 72 // Returns true if this provider host should handle requests for |
66 // |resource_type|. | 73 // |resource_type|. |
67 bool ShouldHandleRequest(ResourceType::Type resource_type) const; | 74 bool ShouldHandleRequest(ResourceType::Type resource_type) const; |
68 | 75 |
69 private: | 76 private: |
70 const int process_id_; | 77 const int process_id_; |
71 const int provider_id_; | 78 const int provider_id_; |
72 std::set<int> script_client_thread_ids_; | 79 std::set<int> script_client_thread_ids_; |
73 scoped_refptr<ServiceWorkerVersion> associated_version_; | 80 scoped_refptr<ServiceWorkerVersion> associated_version_; |
74 scoped_refptr<ServiceWorkerVersion> hosted_version_; | 81 scoped_refptr<ServiceWorkerVersion> hosted_version_; |
75 base::WeakPtr<ServiceWorkerContextCore> context_; | 82 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 83 ServiceWorkerDispatcherHost* dispatcher_host_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
76 }; | 86 }; |
77 | 87 |
78 } // namespace content | 88 } // namespace content |
79 | 89 |
80 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 90 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |