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
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_THREAD_PROXY_H_
6 #define CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_THREAD_PROXY_H_
8 #include "base/id_map.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "content/child/permissions/permission_observers_registry.h"
12 #include "content/child/worker_task_runner.h"
13 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionClient.h"
16 class SingleThreadTaskRunner
;
21 class PermissionDispatcher
;
23 // PermissionDispatcherThreadProxy is a a proxy to the PermissionDispatcher for
24 // callers running on a different thread than the main thread. There is one
25 // instance of that class per thread.
26 class PermissionDispatcherThreadProxy
:
27 public blink::WebPermissionClient
,
28 public PermissionObserversRegistry
,
29 public WorkerTaskRunner::Observer
{
31 static PermissionDispatcherThreadProxy
* GetThreadInstance(
32 base::SingleThreadTaskRunner
* main_thread_task_runner
,
33 PermissionDispatcher
* permissions_dispatcher
);
35 // blink::WebPermissionClient implementation.
36 virtual void queryPermission(blink::WebPermissionType type
,
37 const blink::WebURL
& origin
,
38 blink::WebPermissionCallback
* callback
);
39 virtual void requestPermission(blink::WebPermissionType type
,
40 const blink::WebURL
& origin
,
41 blink::WebPermissionCallback
* callback
);
42 virtual void revokePermission(blink::WebPermissionType type
,
43 const blink::WebURL
& origin
,
44 blink::WebPermissionCallback
* callback
);
45 virtual void startListening(blink::WebPermissionType type
,
46 const blink::WebURL
& origin
,
47 blink::WebPermissionObserver
* observer
);
48 virtual void stopListening(blink::WebPermissionObserver
* observer
);
50 // WorkerTaskRunner::Observer implementation.
51 void OnWorkerRunLoopStopped() override
;
54 PermissionDispatcherThreadProxy(
55 base::SingleThreadTaskRunner
* main_thread_task_runner
,
56 PermissionDispatcher
* permissions_dispatcher
);
58 // Callback when an observed permission changes.
59 void OnPermissionChanged(blink::WebPermissionType type
,
60 const std::string
& origin
,
61 blink::WebPermissionObserver
* observer
,
62 blink::WebPermissionStatus status
);
64 virtual ~PermissionDispatcherThreadProxy();
66 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
67 PermissionDispatcher
* permission_dispatcher_
;
69 DISALLOW_COPY_AND_ASSIGN(PermissionDispatcherThreadProxy
);
72 } // namespace content
74 #endif // CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_THREAD_PROXY_H_