Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_H_ | |
| 6 #define CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "content/browser/message_port_delegate.h" | |
| 11 #include "content/common/service_worker/service_worker_status_code.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 struct CrossOriginServiceWorkerClient; | |
| 16 class ServiceWorkerContextWrapper; | |
| 17 class ServiceWorkerRegistration; | |
| 18 | |
| 19 // Class that keeps track of all active navigator.connect connections. This | |
|
scheib
2014/12/18 00:24:10
Tracks all active navigator.connect connections, w
Marijn Kruisselbrink
2014/12/19 00:09:21
Done.
| |
| 20 // class is also responsible for waking up a service worker when a message | |
| 21 // arrives, and properly routing the messages. | |
| 22 // One instance of this class exists per StoragePartition. | |
| 23 // TODO(mek): Clean up message ports when a service worker is unregistered. | |
| 24 // TODO(mek): Somehow clean up connections when the client side goes away. | |
| 25 class NavigatorConnectContext | |
| 26 : public MessagePortDelegate, | |
| 27 public base::RefCountedThreadSafe<NavigatorConnectContext> { | |
| 28 public: | |
| 29 explicit NavigatorConnectContext( | |
| 30 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); | |
| 31 | |
| 32 // Registers an accepted connection with this class. This method takes care | |
|
scheib
2014/12/18 00:24:10
Registers an accepted connection and updates Messa
Marijn Kruisselbrink
2014/12/19 00:09:21
Done.
| |
| 33 // of updating MessagePortService with the new route/delegate for the message | |
| 34 // port associated with this connection, as well as adding the connection to | |
| 35 // this class' internal bookkeeping. | |
| 36 void RegisterConnection(const CrossOriginServiceWorkerClient& client, | |
| 37 const scoped_refptr<ServiceWorkerRegistration>& | |
| 38 service_worker_registration); | |
| 39 | |
| 40 // MessagePortDelegate implementation. For the implementation of this class, | |
| 41 // the route_id of a message port is always equal to the message_port_id. | |
| 42 void SendMessage(int route_id, | |
| 43 const base::string16& message, | |
| 44 const std::vector<int>& sent_message_port_ids) override; | |
| 45 void SendMessagesAreQueued(int route_id) override; | |
| 46 | |
| 47 private: | |
| 48 friend class base::RefCountedThreadSafe<NavigatorConnectContext>; | |
| 49 ~NavigatorConnectContext() override; | |
| 50 | |
| 51 // Callback called by SendMessage when a ServiceWorkerRegistration for the | |
| 52 // given message port has been located. | |
| 53 void DoSendMessage(const CrossOriginServiceWorkerClient& client, | |
| 54 const base::string16& message, | |
| 55 const std::vector<int>& sent_message_port_ids, | |
| 56 ServiceWorkerStatusCode service_worker_status, | |
| 57 const scoped_refptr<ServiceWorkerRegistration>& | |
| 58 service_worker_registration); | |
| 59 | |
| 60 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | |
| 61 struct Connection; | |
| 62 // Maps route ids to connections. | |
| 63 std::map<int, Connection> connections_; | |
| 64 }; | |
| 65 | |
| 66 } // namespace content | |
| 67 | |
| 68 #endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_CONTEXT_H_ | |
| OLD | NEW |