Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.h

Issue 224733014: Introduce ServiceWorkerHandle for tracking WebServiceWorkerImpl reference (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 45 // The service worker version that corresponds with
40 // navigator.serviceWorker.active for our document. 46 // navigator.serviceWorker.active for our document.
41 ServiceWorkerVersion* active_version() const { 47 ServiceWorkerVersion* active_version() const {
42 return active_version_.get(); 48 return active_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 void set_document_url(const GURL& url) { document_url_ = url; } 57 void set_document_url(const GURL& url) { document_url_ = url; }
52 const GURL& document_url() const { return document_url_; } 58 const GURL& document_url() const { return document_url_; }
53 59
54 // Adds and removes script client thread ID, who is listening events 60 // Adds and removes script client thread ID, who is listening events
55 // dispatched from ServiceWorker to the document (and any of its dedicated 61 // dispatched from ServiceWorker to the document (and any of its dedicated
56 // workers) corresponding to this provider. 62 // workers) corresponding to this provider.
57 void AddScriptClient(int thread_id); 63 void AddScriptClient(int thread_id);
58 void RemoveScriptClient(int thread_id); 64 void RemoveScriptClient(int thread_id);
59 65
60 // Associate |version| to this provider as its '.active' or '.pending' 66 // Associate |version| to this provider as its '.active' or '.pending'.
61 // version.
62 // Giving NULL to this method will unset the corresponding field. 67 // Giving NULL to this method will unset the corresponding field.
63 void SetActiveVersion(ServiceWorkerVersion* version); 68 void SetActiveVersion(ServiceWorkerVersion* version);
64 void SetPendingVersion(ServiceWorkerVersion* version); 69 void SetPendingVersion(ServiceWorkerVersion* version);
65 70
66 // Returns false if the version is not in the expected STARTING in our 71 // Returns false if the version is not in the expected STARTING in our
67 // our process state. That would be indicative of a bad IPC message. 72 // our process state. That would be indicative of a bad IPC message.
68 bool SetHostedVersionId(int64 versions_id); 73 bool SetHostedVersionId(int64 versions_id);
69 74
70 // Returns true if this provider host should handle requests for 75 // Returns true if this provider host should handle requests for
71 // |resource_type|. 76 // |resource_type|.
72 bool ShouldHandleRequest(ResourceType::Type resource_type) const; 77 bool ShouldHandleRequest(ResourceType::Type resource_type) const;
73 78
74 private: 79 private:
75 const int process_id_; 80 const int process_id_;
76 const int provider_id_; 81 const int provider_id_;
77 GURL document_url_; 82 GURL document_url_;
78 std::set<int> script_client_thread_ids_; 83 std::set<int> script_client_thread_ids_;
79 scoped_refptr<ServiceWorkerVersion> active_version_; 84 scoped_refptr<ServiceWorkerVersion> active_version_;
80 scoped_refptr<ServiceWorkerVersion> pending_version_; 85 scoped_refptr<ServiceWorkerVersion> pending_version_;
81 scoped_refptr<ServiceWorkerVersion> hosted_version_; 86 scoped_refptr<ServiceWorkerVersion> hosted_version_;
82 base::WeakPtr<ServiceWorkerContextCore> context_; 87 base::WeakPtr<ServiceWorkerContextCore> context_;
88 ServiceWorkerDispatcherHost* dispatcher_host_;
83 89
84 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); 90 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
85 }; 91 };
86 92
87 } // namespace content 93 } // namespace content
88 94
89 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ 95 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698