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

Side by Side Diff: content/child/service_worker/service_worker_provider_context.h

Issue 477593007: ServiceWorker: Make '.ready' return a promise to be resolved with ServiceWorkerRegistration (2/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_
6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/sequenced_task_runner_helpers.h" 12 #include "base/sequenced_task_runner_helpers.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "content/common/service_worker/service_worker_types.h" 14 #include "content/common/service_worker/service_worker_types.h"
15 15
16 namespace base { 16 namespace base {
17 class MessageLoopProxy; 17 class MessageLoopProxy;
18 } 18 }
19 19
20 namespace IPC { 20 namespace IPC {
21 class Message; 21 class Message;
22 } 22 }
23 23
24 namespace content { 24 namespace content {
25 25
26 class ServiceWorkerHandleReference; 26 class ServiceWorkerHandleReference;
27 class ServiceWorkerRegistrationHandleReference;
27 struct ServiceWorkerProviderContextDeleter; 28 struct ServiceWorkerProviderContextDeleter;
28 class ThreadSafeSender; 29 class ThreadSafeSender;
29 30
30 // An instance of this class holds document-related information (e.g. 31 // An instance of this class holds document-related information (e.g.
31 // .controller). Created and destructed on the main thread. 32 // .controller). Created and destructed on the main thread.
32 // TODO(kinuko): To support navigator.serviceWorker in dedicated workers 33 // TODO(kinuko): To support navigator.serviceWorker in dedicated workers
33 // this needs to be RefCountedThreadSafe and .controller info needs to be 34 // this needs to be RefCountedThreadSafe and .controller info needs to be
34 // handled in a thread-safe manner (e.g. by a lock etc). 35 // handled in a thread-safe manner (e.g. by a lock etc).
35 class ServiceWorkerProviderContext 36 class ServiceWorkerProviderContext
36 : public base::RefCounted<ServiceWorkerProviderContext> { 37 : public base::RefCounted<ServiceWorkerProviderContext> {
37 public: 38 public:
38 explicit ServiceWorkerProviderContext(int provider_id); 39 explicit ServiceWorkerProviderContext(int provider_id);
39 40
40 // Called from ServiceWorkerDispatcher. 41 // Called from ServiceWorkerDispatcher.
42 void OnAssociateRegistration(const ServiceWorkerRegistrationObjectInfo& info,
43 const ServiceWorkerVersionAttributes& attrs);
44 void OnDisassociateRegistration();
41 void OnServiceWorkerStateChanged(int handle_id, 45 void OnServiceWorkerStateChanged(int handle_id,
42 blink::WebServiceWorkerState state); 46 blink::WebServiceWorkerState state);
43 void OnSetInstallingServiceWorker(int provider_id, 47 void OnSetInstallingServiceWorker(int registration_handle_id,
44 const ServiceWorkerObjectInfo& info); 48 const ServiceWorkerObjectInfo& info);
45 void OnSetWaitingServiceWorker(int provider_id, 49 void OnSetWaitingServiceWorker(int registration_handle_id,
46 const ServiceWorkerObjectInfo& info); 50 const ServiceWorkerObjectInfo& info);
47 void OnSetActiveServiceWorker(int provider_id, 51 void OnSetActiveServiceWorker(int registration_handle_id,
48 const ServiceWorkerObjectInfo& info); 52 const ServiceWorkerObjectInfo& info);
49 void OnSetControllerServiceWorker(int provider_id, 53 void OnSetControllerServiceWorker(int registration_handle_id,
50 const ServiceWorkerObjectInfo& info); 54 const ServiceWorkerObjectInfo& info);
51 55
52 int provider_id() const { return provider_id_; } 56 int provider_id() const { return provider_id_; }
53 57
54 ServiceWorkerHandleReference* installing(); 58 ServiceWorkerHandleReference* installing();
55 ServiceWorkerHandleReference* waiting(); 59 ServiceWorkerHandleReference* waiting();
56 ServiceWorkerHandleReference* active(); 60 ServiceWorkerHandleReference* active();
57 ServiceWorkerHandleReference* controller(); 61 ServiceWorkerHandleReference* controller();
62 ServiceWorkerRegistrationHandleReference* registration();
63
64 ServiceWorkerVersionAttributes GetVersionAttributes();
58 65
59 // Gets the handle ID of the installing Service Worker, or 66 // Gets the handle ID of the installing Service Worker, or
60 // kInvalidServiceWorkerHandleId if the provider does not have a 67 // kInvalidServiceWorkerHandleId if the provider does not have a
61 // installing Service Worker. 68 // installing Service Worker.
62 int installing_handle_id() const; 69 int installing_handle_id() const;
63 70
64 // Gets the handle ID of the waiting Service Worker, or 71 // Gets the handle ID of the waiting Service Worker, or
65 // kInvalidServiceWorkerHandleId if the provider does not have a 72 // kInvalidServiceWorkerHandleId if the provider does not have a
66 // waiting Service Worker. 73 // waiting Service Worker.
67 int waiting_handle_id() const; 74 int waiting_handle_id() const;
68 75
69 // Gets the handle ID of the active Service Worker, or 76 // Gets the handle ID of the active Service Worker, or
70 // kInvalidServiceWorkerHandleId if the provider does not have an active 77 // kInvalidServiceWorkerHandleId if the provider does not have an active
71 // Service Worker. 78 // Service Worker.
72 int active_handle_id() const; 79 int active_handle_id() const;
73 80
74 // Gets the handle ID of the controller Service Worker, or 81 // Gets the handle ID of the controller Service Worker, or
75 // kInvalidServiceWorkerHandleId if the provider is not controlled 82 // kInvalidServiceWorkerHandleId if the provider is not controlled
76 // by a Service Worker. 83 // by a Service Worker.
77 int controller_handle_id() const; 84 int controller_handle_id() const;
78 85
86 // Gets the handle ID of the associated registration, or
87 // kInvalidRegistrationHandleId if the provider is not associated with any
88 // registration.
89 int registration_handle_id() const;
90
79 private: 91 private:
80 friend class base::RefCounted<ServiceWorkerProviderContext>; 92 friend class base::RefCounted<ServiceWorkerProviderContext>;
81 ~ServiceWorkerProviderContext(); 93 ~ServiceWorkerProviderContext();
82 94
95 bool IsAssociatedWithRegistration(int registration_handle_id) const;
96
83 const int provider_id_; 97 const int provider_id_;
84 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; 98 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_;
85 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 99 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
86 scoped_ptr<ServiceWorkerHandleReference> installing_; 100 scoped_ptr<ServiceWorkerHandleReference> installing_;
87 scoped_ptr<ServiceWorkerHandleReference> waiting_; 101 scoped_ptr<ServiceWorkerHandleReference> waiting_;
88 scoped_ptr<ServiceWorkerHandleReference> active_; 102 scoped_ptr<ServiceWorkerHandleReference> active_;
89 scoped_ptr<ServiceWorkerHandleReference> controller_; 103 scoped_ptr<ServiceWorkerHandleReference> controller_;
104 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_;
90 105
91 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); 106 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext);
92 }; 107 };
93 108
94 } // namespace content 109 } // namespace content
95 110
96 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ 111 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698