Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / child / navigator_connect / navigator_connect_provider.h
blobf21b0c4a97eee1fb8e9c62a204f43621dad2b3c6
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.
5 #ifndef CONTENT_CHILD_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_PROVIDER_H_
6 #define CONTENT_CHILD_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_PROVIDER_H_
8 #include "base/compiler_specific.h"
9 #include "base/id_map.h"
10 #include "base/memory/ref_counted.h"
11 #include "content/child/worker_task_runner.h"
12 #include "third_party/WebKit/public/platform/WebNavigatorConnectProvider.h"
14 class GURL;
16 namespace base {
17 class SingleThreadTaskRunner;
20 namespace blink {
21 class WebMessagePortChannel;
22 class WebString;
25 namespace IPC {
26 class Message;
29 namespace content {
30 class ThreadSafeSender;
31 struct TransferredMessagePort;
33 // Main entry point for the navigator.connect API in a child process. This
34 // implements the blink API and passes connect calls on to the browser process.
35 // NavigatorConnectDispatcher receives IPCs from the browser process and passes
36 // them on to the correct thread specific instance of this class.
37 // The ThreadSpecificInstance method will return an instance of this class for
38 // the current thread, or create one if no instance exists yet for this thread.
39 // This class deletes itself if the worker thread it belongs to quits.
40 class NavigatorConnectProvider : public blink::WebNavigatorConnectProvider,
41 public WorkerTaskRunner::Observer {
42 public:
43 NavigatorConnectProvider(
44 ThreadSafeSender* thread_safe_sender,
45 const scoped_refptr<base::SingleThreadTaskRunner>& main_loop);
46 ~NavigatorConnectProvider();
48 // WebNavigatorConnectProvider implementation.
49 virtual void connect(const blink::WebURL& target_url,
50 const blink::WebString& origin,
51 blink::WebNavigatorConnectPortCallbacks* callbacks);
53 void OnMessageReceived(const IPC::Message& msg);
55 // |thread_safe_sender| and |main_loop| need to be passed in because if the
56 // call leads to construction they will be needed.
57 static NavigatorConnectProvider* ThreadSpecificInstance(
58 ThreadSafeSender* thread_safe_sender,
59 const scoped_refptr<base::SingleThreadTaskRunner>& main_loop);
61 private:
62 void OnConnectResult(int thread_id,
63 int request_id,
64 const TransferredMessagePort& message_port,
65 int message_port_route_id,
66 bool allow_connect);
68 // WorkerTaskRunner::Observer implementation.
69 void OnWorkerRunLoopStopped() override;
71 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
72 scoped_refptr<base::SingleThreadTaskRunner> main_loop_;
73 IDMap<blink::WebNavigatorConnectPortCallbacks, IDMapOwnPointer> requests_;
75 DISALLOW_COPY_AND_ASSIGN(NavigatorConnectProvider);
78 } // namespace content
80 #endif // CONTENT_CHILD_NAVIGATOR_CONNECT_NAVIGATOR_CONNECT_PROVIDER_H_