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/public/child/worker_thread.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
: public blink::WebPermissionClient
,
27 public PermissionObserversRegistry
,
28 public WorkerThread::Observer
{
30 static PermissionDispatcherThreadProxy
* GetThreadInstance(
31 base::SingleThreadTaskRunner
* main_thread_task_runner
,
32 PermissionDispatcher
* permissions_dispatcher
);
34 // blink::WebPermissionClient implementation.
35 virtual void queryPermission(blink::WebPermissionType type
,
36 const blink::WebURL
& origin
,
37 blink::WebPermissionCallback
* callback
);
38 virtual void requestPermission(blink::WebPermissionType type
,
39 const blink::WebURL
& origin
,
40 blink::WebPermissionCallback
* callback
);
41 virtual void requestPermissions(
42 const blink::WebVector
<blink::WebPermissionType
>& types
,
43 const blink::WebURL
& origin
,
44 blink::WebPermissionsCallback
* callback
);
45 virtual void revokePermission(blink::WebPermissionType type
,
46 const blink::WebURL
& origin
,
47 blink::WebPermissionCallback
* callback
);
48 virtual void startListening(blink::WebPermissionType type
,
49 const blink::WebURL
& origin
,
50 blink::WebPermissionObserver
* observer
);
51 virtual void stopListening(blink::WebPermissionObserver
* observer
);
53 // WorkerThread::Observer implementation.
54 void WillStopCurrentWorkerThread() override
;
57 PermissionDispatcherThreadProxy(
58 base::SingleThreadTaskRunner
* main_thread_task_runner
,
59 PermissionDispatcher
* permissions_dispatcher
);
61 // Callback when an observed permission changes.
62 void OnPermissionChanged(blink::WebPermissionType type
,
63 const std::string
& origin
,
64 blink::WebPermissionObserver
* observer
,
65 blink::WebPermissionStatus status
);
67 virtual ~PermissionDispatcherThreadProxy();
69 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
70 PermissionDispatcher
* permission_dispatcher_
;
72 DISALLOW_COPY_AND_ASSIGN(PermissionDispatcherThreadProxy
);
75 } // namespace content
77 #endif // CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_THREAD_PROXY_H_