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

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: 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
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 {
nasko 2015/11/25 15:08:30 How is this related to https://codereview.chromium
xhwang 2015/11/25 17:30:23 In this CL I am simplifying MediaPermissionDispatc
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 but the caller needs to make sure |this|
29 uint32_t RegisterCallback(const PermissionStatusCB& permission_status_cb); 32 // is valid at the time of this call. The |permission_status_cb| will always
30 33 // be fired on the thread where these methods are called.
31 // Deliver the permission status |granted| to the callback identified by 34 void HasPermission(Type type,
32 // |request_id|. 35 const GURL& security_origin,
33 void DeliverResult(uint32_t request_id, bool granted); 36 const PermissionStatusCB& permission_status_cb) override;
34 37 void RequestPermission(
35 base::ThreadChecker& thread_checker() { return thread_checker_; } 38 Type type,
39 const GURL& security_origin,
40 const PermissionStatusCB& permission_status_cb) override;
36 41
37 private: 42 private:
38 // Map of request IDs and pending PermissionStatusCBs. 43 // Map of request IDs and pending PermissionStatusCBs.
39 typedef std::map<uint32_t, PermissionStatusCB> RequestMap; 44 typedef std::map<uint32_t, PermissionStatusCB> RequestMap;
40 45
41 base::ThreadChecker thread_checker_; 46 // Register PermissionStatusCBs. Returns |request_id| that can be used to make
47 // PermissionService calls.
48 uint32_t RegisterCallback(const PermissionStatusCB& permission_status_cb);
42 49
50 // Callback for |permission_service_| calls.
51 void OnPermissionStatus(uint32_t request_id, PermissionStatus status);
52
53 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
43 uint32_t next_request_id_; 54 uint32_t next_request_id_;
44 RequestMap requests_; 55 RequestMap requests_;
56 PermissionServicePtr permission_service_;
57
58 // Used to safely post MediaPermission calls for execution on |task_runner_|.
59 base::WeakPtr<MediaPermissionDispatcher> weak_ptr_;
60
61 base::WeakPtrFactory<MediaPermissionDispatcher> weak_factory_;
45 62
46 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher); 63 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher);
47 }; 64 };
48 65
49 } // namespace content 66 } // namespace content
50 67
51 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ 68 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698