Chromium Code Reviews| 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 | |
| 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ | 10 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ | 11 #define CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ |
| 7 | 12 |
| 8 #include <map> | 13 #include <map> |
| 9 | 14 |
| 10 #include "base/threading/thread_checker.h" | 15 #include "base/memory/weak_ptr.h" |
| 11 #include "content/common/content_export.h" | |
| 12 #include "content/common/permission_service.mojom.h" | |
| 13 #include "content/public/renderer/render_frame_observer.h" | |
| 14 #include "media/base/media_permission.h" | 16 #include "media/base/media_permission.h" |
| 15 | 17 |
| 16 namespace content { | 18 namespace content { |
| 17 | 19 |
| 18 // MediaPermission implementation in content. This class is not thread safe | 20 class MediaPermissionDispatcher |
| 19 // and should only be used on one thread. | 21 : public media::MediaPermission, |
| 20 class CONTENT_EXPORT MediaPermissionDispatcher : public media::MediaPermission, | 22 public base::SupportsWeakPtr<MediaPermissionDispatcher> { |
| 21 public RenderFrameObserver { | |
| 22 public: | 23 public: |
| 23 explicit MediaPermissionDispatcher(RenderFrame* render_frame); | 24 MediaPermissionDispatcher(); |
| 24 ~MediaPermissionDispatcher() override; | 25 ~MediaPermissionDispatcher() override; |
| 25 | 26 |
| 26 // media::MediaPermission implementation. | 27 protected: |
| 27 void HasPermission(Type type, | 28 // Register callbacks for PermissionService calls. |
| 28 const GURL& security_origin, | 29 uint32_t RegisterCallback(const PermissionStatusCB& permission_status_cb); |
| 29 const PermissionStatusCB& permission_status_cb) override; | 30 |
| 30 void RequestPermission( | 31 // Deliver the permission status |granted| to the callback identified by |
| 31 Type type, | 32 // |request_id|. |
| 32 const GURL& security_origin, | 33 void DeliverResult(uint32_t request_id, bool granted); |
| 33 const PermissionStatusCB& permission_status_cb) override; | |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // Map of request IDs and pending PermissionStatusCBs. | 36 // Map of request IDs and pending PermissionStatusCBs. |
| 37 typedef std::map<uint32_t, PermissionStatusCB> RequestMap; | 37 typedef std::map<uint32_t, PermissionStatusCB> RequestMap; |
| 38 | 38 |
|
perkj_chrome
2015/09/22 08:24:16
Please re-add thread checker to enforce that this
guoweis_left_chromium
2015/09/22 18:48:48
Done.
| |
| 39 // Callback for |permission_service_| calls. | |
| 40 void OnPermissionStatus(uint32_t request_id, PermissionStatus status); | |
| 41 | |
| 42 uint32_t next_request_id_; | 39 uint32_t next_request_id_; |
| 43 RequestMap requests_; | 40 RequestMap requests_; |
| 44 PermissionServicePtr permission_service_; | |
| 45 | |
| 46 base::ThreadChecker thread_checker_; | |
| 47 | 41 |
| 48 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher); | 42 DISALLOW_COPY_AND_ASSIGN(MediaPermissionDispatcher); |
| 49 }; | 43 }; |
| 50 | 44 |
| 51 } // namespace content | 45 } // namespace content |
| 52 | 46 |
| 53 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ | 47 #endif // CONTENT_RENDERER_MEDIA_MEDIA_PERMISSION_DISPATCHER_H_ |
| OLD | NEW |