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

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 4 years, 11 months 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
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 <stdint.h> 8 #include <stdint.h>
14 9
15 #include <map> 10 #include <map>
16 11
17 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
19 #include "base/threading/thread_checker.h"
20 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
16 #include "content/common/permission_service.mojom.h"
17 #include "content/public/renderer/render_frame_observer.h"
21 #include "media/base/media_permission.h" 18 #include "media/base/media_permission.h"
22 19
20 namespace base {
21 class SingleThreadTaskRunner;
22 }
23
23 namespace content { 24 namespace content {
24 25
25 class CONTENT_EXPORT MediaPermissionDispatcher : public media::MediaPermission { 26 // MediaPermission implementation.
27 class CONTENT_EXPORT MediaPermissionDispatcher : public media::MediaPermission,
28 public RenderFrameObserver {
26 public: 29 public:
27 MediaPermissionDispatcher(); 30 explicit MediaPermissionDispatcher(RenderFrame* render_frame);
28 ~MediaPermissionDispatcher() override; 31 ~MediaPermissionDispatcher() override;
29 32
30 protected: 33 // media::MediaPermission implementation.
31 // Register callbacks for PermissionService calls. 34 // Note: Can be called on any thread but the caller needs to make sure |this|
perkj_chrome 2016/01/25 21:19:56 |this| must be valid? Yes - it is a public method.
xhwang 2016/01/29 01:01:56 Good point :) Since we are passing a raw pointer t
32 uint32_t RegisterCallback(const PermissionStatusCB& permission_status_cb); 35 // is valid at the time of this call. The |permission_status_cb| will always
33 36 // be fired on the thread where these methods are called.
34 // Deliver the permission status |granted| to the callback identified by 37 void HasPermission(Type type,
35 // |request_id|. 38 const GURL& security_origin,
36 void DeliverResult(uint32_t request_id, bool granted); 39 const PermissionStatusCB& permission_status_cb) override;
37 40 void RequestPermission(
38 base::ThreadChecker& thread_checker() { return thread_checker_; } 41 Type type,
42 const GURL& security_origin,
43 const PermissionStatusCB& permission_status_cb) override;
39 44
40 private: 45 private:
41 // Map of request IDs and pending PermissionStatusCBs. 46 // Map of request IDs and pending PermissionStatusCBs.
42 typedef std::map<uint32_t, PermissionStatusCB> RequestMap; 47 typedef std::map<uint32_t, PermissionStatusCB> RequestMap;
43 48
44 base::ThreadChecker thread_checker_; 49 // Register PermissionStatusCBs. Returns |request_id| that can be used to make
50 // PermissionService calls.
51 uint32_t RegisterCallback(const PermissionStatusCB& permission_status_cb);
45 52
53 // Callback for |permission_service_| calls.
54 void OnPermissionStatus(uint32_t request_id, PermissionStatus status);
55
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
46 uint32_t next_request_id_; 57 uint32_t next_request_id_;
47 RequestMap requests_; 58 RequestMap requests_;
59 PermissionServicePtr permission_service_;
60
61 // Used to safely post MediaPermission calls for execution on |task_runner_|.
62 base::WeakPtr<MediaPermissionDispatcher> weak_ptr_;
63
64 base::WeakPtrFactory<MediaPermissionDispatcher> weak_factory_;
48 65
49 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher); 66 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher);
50 }; 67 };
51 68
52 } // namespace content 69 } // namespace content
53 70
54 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ 71 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698