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

Side by Side Diff: content/browser/navigator_connect/navigator_connect_service_worker_service_factory.h

Issue 861373002: Refactor navigator.connect code to make it more flexible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, and simplify a bit Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_DISPATCHER_HOST_H_ 5 #ifndef CONTENT_BROWSER_NAVIGAOR_CONNECT_NAVIGATOR_CONNECT_SERVICE_WORKER_SERVIC E_FACTORY_H_
6 #define CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_NAVIGAOR_CONNECT_NAVIGATOR_CONNECT_SERVICE_WORKER_SERVIC E_FACTORY_H_
Avi (use Gerrit) 2015/01/27 00:03:36 Fix typo: NAVIGATOR
Marijn Kruisselbrink 2015/01/27 00:09:20 Done.
7 7
8 #include <map>
9
10 #include "base/memory/weak_ptr.h"
8 #include "content/common/service_worker/service_worker_status_code.h" 11 #include "content/common/service_worker/service_worker_status_code.h"
9 #include "content/public/browser/browser_message_filter.h" 12 #include "content/public/browser/navigator_connect_service_factory.h"
10
11 class GURL;
12 13
13 namespace content { 14 namespace content {
14 15
15 struct CrossOriginServiceWorkerClient;
16 class NavigatorConnectContext;
17 class ServiceWorkerContextWrapper; 16 class ServiceWorkerContextWrapper;
18 class ServiceWorkerRegistration; 17 class ServiceWorkerRegistration;
19 18
20 // Receives navigator.connect connection attempts from a child process. 19 // Service worker specific NavigatorConnectServiceFactory implementation. This
21 // Attempts to find a service that serves the URL the connection is made to 20 // class accepts all URLs (and thus has to be the first factory to be added to
22 // and sets up the actual connection. 21 // NavigatorConnectContext or no other factories will ever by used).
23 // Constructed on the UI thread, but all other methods are called on the IO 22 // Tries to find a service worker registration to handle the url being connected
24 // thread. Typically there is one instance of this class for each renderer 23 // to.
25 // process, and this class lives at least as long as the renderer process is 24 class NavigatorConnectServiceWorkerServiceFactory
26 // alive (since this class is refcounted it could outlive the renderer process 25 : public NavigatorConnectServiceFactory {
27 // if it is still handling a connection attempt).
28 class NavigatorConnectDispatcherHost : public BrowserMessageFilter {
29 public: 26 public:
30 NavigatorConnectDispatcherHost( 27 explicit NavigatorConnectServiceWorkerServiceFactory(
31 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, 28 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context);
32 const scoped_refptr<NavigatorConnectContext>& navigator_connect_context); 29 ~NavigatorConnectServiceWorkerServiceFactory() override;
30
31 // NavigatorConnectServiceFactory implementation.
32 bool HandlesUrl(const GURL& target_url) override;
33 void Connect(const NavigatorConnectClient& client,
34 const ConnectCallback& callback) override;
33 35
34 private: 36 private:
35 ~NavigatorConnectDispatcherHost() override;
36
37 // BrowserMessageFilter implementation.
38 bool OnMessageReceived(const IPC::Message& message) override;
39
40 // IPC Message handlers.
41 void OnConnect(int thread_id,
42 int request_id,
43 const CrossOriginServiceWorkerClient& client);
44
45 // Callback called when the Service Worker context found (or didn't find) a 37 // Callback called when the Service Worker context found (or didn't find) a
46 // service worker registration to serve a particular URL. 38 // service worker registration to serve a particular URL.
47 void GotServiceWorkerRegistration( 39 void GotServiceWorkerRegistration(
48 int thread_id, 40 const ConnectCallback& callback,
49 int request_id, 41 const NavigatorConnectClient& client,
50 const CrossOriginServiceWorkerClient& client,
51 ServiceWorkerStatusCode status, 42 ServiceWorkerStatusCode status,
52 const scoped_refptr<ServiceWorkerRegistration>& registration); 43 const scoped_refptr<ServiceWorkerRegistration>& registration);
53 44
54 // Callback called when the service worker finished handling the cross origin 45 // Callback called when the service worker finished handling the cross origin
55 // connection event. 46 // connection event.
56 void OnConnectResult( 47 void OnConnectResult(
57 int thread_id, 48 const ConnectCallback& callback,
58 int request_id, 49 const NavigatorConnectClient& client,
59 const CrossOriginServiceWorkerClient& client,
60 const scoped_refptr<ServiceWorkerRegistration>& registration, 50 const scoped_refptr<ServiceWorkerRegistration>& registration,
61 ServiceWorkerStatusCode status, 51 ServiceWorkerStatusCode status,
62 bool accept_connection); 52 bool accept_connection);
63 53
64 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 54 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
65 scoped_refptr<NavigatorConnectContext> navigator_connect_context_; 55 base::WeakPtrFactory<NavigatorConnectServiceWorkerServiceFactory>
66 56 weak_factory_;
67 DISALLOW_COPY_AND_ASSIGN(NavigatorConnectDispatcherHost);
68 }; 57 };
69 58
70 } // namespace content 59 } // namespace content
71 60
72 #endif // CONTENT_BROWSER_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_DISPATCHER_HOST_H _ 61 #endif // CONTENT_BROWSER_NAVIGAOR_CONNECT_NAVIGATOR_CONNECT_SERVICE_WORKER_SER VICE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698