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

Side by Side Diff: content/renderer/media/media_permission_dispatcher.h

Issue 1464183002: media: Simplify MediaPermissionDispatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 years 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
« no previous file with comments | « content/content_renderer.gypi ('k') | content/renderer/media/media_permission_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
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 // Bound to the |task_runner_|.
Wez 2015/11/25 02:16:20 This doesn't know anything about "the |task_runner
xhwang 2015/11/25 07:06:03 Done.
guoweis_left_chromium 2015/11/25 15:38:54 +tommi to the review. RTCPeerConnection is eventua
58 base::WeakPtr<MediaPermissionDispatcher> weak_this_;
Wez 2015/11/25 02:16:19 nit: Convention elsewhere is to call these |weak_p
xhwang 2015/11/25 07:06:03 Done.
59
60 base::WeakPtrFactory<MediaPermissionDispatcher> weak_factory_;
45 61
46 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher); 62 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher);
47 }; 63 };
48 64
49 } // namespace content 65 } // namespace content
50 66
51 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ 67 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_
OLDNEW
« no previous file with comments | « content/content_renderer.gypi ('k') | content/renderer/media/media_permission_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698