OLD | NEW |
---|---|
1 // Copyright 2015 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 // Base class for MediaPermission implementations in content. This class allows | |
6 // multiple pending PermissionService calls by managing callbacks for its | |
7 // subclasses. This class is not thread safe and should only be used on one | |
8 // thread. | |
9 | |
10 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ |
11 #define CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ |
12 | 7 |
13 #include <map> | 8 #include <map> |
14 | 9 |
10 #include "base/memory/ref_counted.h" | |
15 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/thread_checker.h" | |
17 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "content/common/permission_service.mojom.h" | |
14 #include "content/public/renderer/render_frame_observer.h" | |
18 #include "media/base/media_permission.h" | 15 #include "media/base/media_permission.h" |
19 | 16 |
17 namespace base { | |
18 class SingleThreadTaskRunner; | |
19 } | |
20 | |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 class CONTENT_EXPORT MediaPermissionDispatcher : public media::MediaPermission { | 23 // MediaPermission implementation. |
24 class CONTENT_EXPORT MediaPermissionDispatcher : public media::MediaPermission, | |
25 public RenderFrameObserver { | |
23 public: | 26 public: |
24 MediaPermissionDispatcher(); | 27 explicit MediaPermissionDispatcher(RenderFrame* render_frame); |
25 ~MediaPermissionDispatcher() override; | 28 ~MediaPermissionDispatcher() override; |
26 | 29 |
27 protected: | 30 // media::MediaPermission implementation. |
28 // Register callbacks for PermissionService calls. | 31 // Note: Can be called on any thread. The |permission_status_cb| will always |
29 uint32_t RegisterCallback(const PermissionStatusCB& permission_status_cb); | 32 // be fired on the thread where these methods are called. |
Wez
2015/11/25 00:44:48
How is it safe to call "on any thread"? The dispat
xhwang
2015/11/25 01:18:02
|this| shouldn't worry about how it's owned, right
| |
30 | 33 void HasPermission(Type type, |
31 // Deliver the permission status |granted| to the callback identified by | 34 const GURL& security_origin, |
32 // |request_id|. | 35 const PermissionStatusCB& permission_status_cb) override; |
33 void DeliverResult(uint32_t request_id, bool granted); | 36 void RequestPermission( |
34 | 37 Type type, |
35 base::ThreadChecker& thread_checker() { return thread_checker_; } | 38 const GURL& security_origin, |
39 const PermissionStatusCB& permission_status_cb) override; | |
36 | 40 |
37 private: | 41 private: |
38 // Map of request IDs and pending PermissionStatusCBs. | 42 // Map of request IDs and pending PermissionStatusCBs. |
39 typedef std::map<uint32_t, PermissionStatusCB> RequestMap; | 43 typedef std::map<uint32_t, PermissionStatusCB> RequestMap; |
40 | 44 |
41 base::ThreadChecker thread_checker_; | 45 // Register PermissionStatusCBs. Returns |request_id| that can be used to make |
46 // PermissionService calls. | |
47 uint32_t RegisterCallback(const PermissionStatusCB& permission_status_cb); | |
42 | 48 |
49 // Callback for |permission_service_| calls. | |
50 void OnPermissionStatus(uint32_t request_id, PermissionStatus status); | |
51 | |
52 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
43 uint32_t next_request_id_; | 53 uint32_t next_request_id_; |
44 RequestMap requests_; | 54 RequestMap requests_; |
55 PermissionServicePtr permission_service_; | |
56 | |
57 base::WeakPtrFactory<MediaPermissionDispatcher> weak_factory_; | |
45 | 58 |
46 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher); | 59 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher); |
47 }; | 60 }; |
48 | 61 |
49 } // namespace content | 62 } // namespace content |
50 | 63 |
51 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ | 64 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ |
OLD | NEW |