| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // and process PpapiHostMsg_DeviceEnumeration_* messages. | 37 // and process PpapiHostMsg_DeviceEnumeration_* messages. |
| 38 // TODO(yzshen): Refactor ppapi::host::ResourceMessageFilter to support message | 38 // TODO(yzshen): Refactor ppapi::host::ResourceMessageFilter to support message |
| 39 // handling on the same thread, and then derive this class from the filter | 39 // handling on the same thread, and then derive this class from the filter |
| 40 // class. | 40 // class. |
| 41 class CONTENT_EXPORT PepperDeviceEnumerationHostHelper { | 41 class CONTENT_EXPORT PepperDeviceEnumerationHostHelper { |
| 42 public: | 42 public: |
| 43 class Delegate { | 43 class Delegate { |
| 44 public: | 44 public: |
| 45 virtual ~Delegate() {} | 45 virtual ~Delegate() {} |
| 46 | 46 |
| 47 typedef base::Callback< | 47 using DevicesCallback = base::Callback<void( |
| 48 void(int /* request_id */, | 48 const std::vector<ppapi::DeviceRefData>& /* devices */)>; |
| 49 const std::vector<ppapi::DeviceRefData>& /* devices */)> | |
| 50 EnumerateDevicesCallback; | |
| 51 | 49 |
| 52 // Enumerates devices of the specified type. The request ID passed into the | 50 // Enumerates devices of the specified type. |
| 53 // callback will be the same as the return value. | 51 virtual void EnumerateDevices(PP_DeviceType_Dev type, |
| 54 virtual int EnumerateDevices(PP_DeviceType_Dev type, | 52 const GURL& document_url, |
| 55 const GURL& document_url, | 53 const DevicesCallback& callback) = 0; |
| 56 const EnumerateDevicesCallback& callback) = 0; | 54 |
| 57 // Stop enumerating devices of the specified |request_id|. The |request_id| | 55 // Starts monitoring devices of the specified |type|. Returns a |
| 58 // is the return value of EnumerateDevicesCallback. | 56 // subscription ID that must be used to stop monitoring for the device |
| 59 virtual void StopEnumerateDevices(int request_id) = 0; | 57 // |type|. Does not invoke |callback| synchronously. |callback| is invoked |
| 58 // when device changes of the specified |type| occur. |
| 59 virtual uint32_t StartMonitoringDevices( |
| 60 PP_DeviceType_Dev type, |
| 61 const GURL& document_url, |
| 62 const DevicesCallback& callback) = 0; |
| 63 |
| 64 // Stops monitoring devices of the specified |type|. The |
| 65 // |subscription_id| is the return value of StartMonitoringDevices. |
| 66 virtual void StopMonitoringDevices(PP_DeviceType_Dev type, |
| 67 uint32_t subscription_id) = 0; |
| 60 }; | 68 }; |
| 61 | 69 |
| 62 // |resource_host| and |delegate| must outlive this object. | 70 // |resource_host| and |delegate| must outlive this object. |
| 63 PepperDeviceEnumerationHostHelper(ppapi::host::ResourceHost* resource_host, | 71 PepperDeviceEnumerationHostHelper(ppapi::host::ResourceHost* resource_host, |
| 64 base::WeakPtr<Delegate> delegate, | 72 base::WeakPtr<Delegate> delegate, |
| 65 PP_DeviceType_Dev device_type, | 73 PP_DeviceType_Dev device_type, |
| 66 const GURL& document_url); | 74 const GURL& document_url); |
| 67 ~PepperDeviceEnumerationHostHelper(); | 75 ~PepperDeviceEnumerationHostHelper(); |
| 68 | 76 |
| 69 // Returns true if the message has been handled. | 77 // Returns true if the message has been handled. |
| 70 bool HandleResourceMessage(const IPC::Message& msg, | 78 bool HandleResourceMessage(const IPC::Message& msg, |
| 71 ppapi::host::HostMessageContext* context, | 79 ppapi::host::HostMessageContext* context, |
| 72 int32_t* result); | 80 int32_t* result); |
| 73 | 81 |
| 74 private: | 82 private: |
| 75 class ScopedRequest; | 83 class ScopedEnumerationRequest; |
| 84 class ScopedMonitoringRequest; |
| 76 | 85 |
| 77 // Has a different signature than HandleResourceMessage() in order to utilize | 86 // Has a different signature than HandleResourceMessage() in order to utilize |
| 78 // message dispatching macros. | 87 // message dispatching macros. |
| 79 int32_t InternalHandleResourceMessage( | 88 int32_t InternalHandleResourceMessage( |
| 80 const IPC::Message& msg, | 89 const IPC::Message& msg, |
| 81 ppapi::host::HostMessageContext* context, | 90 ppapi::host::HostMessageContext* context, |
| 82 bool* handled); | 91 bool* handled); |
| 83 | 92 |
| 84 int32_t OnEnumerateDevices(ppapi::host::HostMessageContext* context); | 93 int32_t OnEnumerateDevices(ppapi::host::HostMessageContext* context); |
| 85 int32_t OnMonitorDeviceChange(ppapi::host::HostMessageContext* context, | 94 int32_t OnMonitorDeviceChange(ppapi::host::HostMessageContext* context, |
| 86 uint32_t callback_id); | 95 uint32_t callback_id); |
| 87 int32_t OnStopMonitoringDeviceChange( | 96 int32_t OnStopMonitoringDeviceChange( |
| 88 ppapi::host::HostMessageContext* context); | 97 ppapi::host::HostMessageContext* context); |
| 89 | 98 |
| 90 void OnEnumerateDevicesComplete( | 99 void OnEnumerateDevicesComplete( |
| 91 int request_id, | |
| 92 const std::vector<ppapi::DeviceRefData>& devices); | 100 const std::vector<ppapi::DeviceRefData>& devices); |
| 93 void OnNotifyDeviceChange(uint32_t callback_id, | 101 void OnNotifyDeviceChange(uint32_t callback_id, |
| 94 int request_id, | |
| 95 const std::vector<ppapi::DeviceRefData>& devices); | 102 const std::vector<ppapi::DeviceRefData>& devices); |
| 96 | 103 |
| 97 // Non-owning pointers. | 104 // Non-owning pointers. |
| 98 ppapi::host::ResourceHost* resource_host_; | 105 ppapi::host::ResourceHost* resource_host_; |
| 99 base::WeakPtr<Delegate> delegate_; | 106 base::WeakPtr<Delegate> delegate_; |
| 100 | 107 |
| 101 PP_DeviceType_Dev device_type_; | 108 PP_DeviceType_Dev device_type_; |
| 102 GURL document_url_; | 109 GURL document_url_; |
| 103 | 110 |
| 104 std::unique_ptr<ScopedRequest> enumerate_; | 111 std::unique_ptr<ScopedEnumerationRequest> enumerate_; |
| 105 std::unique_ptr<ScopedRequest> monitor_; | 112 std::unique_ptr<ScopedMonitoringRequest> monitor_; |
| 106 | 113 |
| 107 ppapi::host::ReplyMessageContext enumerate_devices_context_; | 114 ppapi::host::ReplyMessageContext enumerate_devices_context_; |
| 108 | 115 |
| 109 DISALLOW_COPY_AND_ASSIGN(PepperDeviceEnumerationHostHelper); | 116 DISALLOW_COPY_AND_ASSIGN(PepperDeviceEnumerationHostHelper); |
| 110 }; | 117 }; |
| 111 | 118 |
| 112 } // namespace content | 119 } // namespace content |
| 113 | 120 |
| 114 #endif // CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ | 121 #endif // CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_ |
| OLD | NEW |