[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PPAPI_PROXY_DEVICE_ENUMERATION_RESOURCE_HELPER_H_ |
| 6 | #define PPAPI_PROXY_DEVICE_ENUMERATION_RESOURCE_HELPER_H_ |
| 7 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
dcheng | ced9224 | 2016-04-07 00:00:12 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
| 15 | #include "base/memory/weak_ptr.h" |
| 16 | #include "ppapi/c/dev/ppb_device_ref_dev.h" |
| 17 | #include "ppapi/proxy/ppapi_proxy_export.h" |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 18 | #include "ppapi/shared_impl/thread_aware_callback.h" |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 19 | |
| 20 | namespace IPC { |
| 21 | class Message; |
| 22 | } |
| 23 | |
| 24 | struct PP_ArrayOutput; |
| 25 | |
| 26 | namespace ppapi { |
| 27 | |
| 28 | struct DeviceRefData; |
| 29 | class TrackedCallback; |
| 30 | |
| 31 | namespace proxy { |
| 32 | |
| 33 | class PluginResource; |
| 34 | class ResourceMessageReplyParams; |
| 35 | |
| 36 | class PPAPI_PROXY_EXPORT DeviceEnumerationResourceHelper |
| 37 | : public base::SupportsWeakPtr<DeviceEnumerationResourceHelper> { |
| 38 | public: |
| 39 | // |owner| must outlive this object. |
| 40 | explicit DeviceEnumerationResourceHelper(PluginResource* owner); |
| 41 | ~DeviceEnumerationResourceHelper(); |
| 42 | |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 43 | int32_t EnumerateDevices(const PP_ArrayOutput& output, |
| 44 | scoped_refptr<TrackedCallback> callback); |
[email protected] | 33eccce | 2012-12-10 22:15:10 | [diff] [blame] | 45 | int32_t EnumerateDevicesSync(const PP_ArrayOutput& output); |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 46 | int32_t MonitorDeviceChange(PP_MonitorDeviceChangeCallback callback, |
| 47 | void* user_data); |
| 48 | |
| 49 | // Returns true if the message has been handled. |
| 50 | bool HandleReply(const ResourceMessageReplyParams& params, |
| 51 | const IPC::Message& msg); |
| 52 | |
| 53 | void LastPluginRefWasDeleted(); |
| 54 | |
| 55 | private: |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 56 | void OnPluginMsgEnumerateDevicesReply( |
| 57 | const PP_ArrayOutput& output, |
| 58 | scoped_refptr<TrackedCallback> callback, |
| 59 | const ResourceMessageReplyParams& params, |
| 60 | const std::vector<DeviceRefData>& devices); |
| 61 | void OnPluginMsgNotifyDeviceChange(const ResourceMessageReplyParams& params, |
| 62 | uint32_t callback_id, |
| 63 | const std::vector<DeviceRefData>& devices); |
| 64 | |
[email protected] | 33eccce | 2012-12-10 22:15:10 | [diff] [blame] | 65 | int32_t WriteToArrayOutput(const std::vector<DeviceRefData>& devices, |
| 66 | const PP_ArrayOutput& output); |
| 67 | |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 68 | // Not owned by this object. |
| 69 | PluginResource* owner_; |
| 70 | |
| 71 | bool pending_enumerate_devices_; |
| 72 | |
| 73 | uint32_t monitor_callback_id_; |
dcheng | ced9224 | 2016-04-07 00:00:12 | [diff] [blame] | 74 | std::unique_ptr<ThreadAwareCallback<PP_MonitorDeviceChangeCallback>> |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 75 | monitor_callback_; |
[email protected] | 4f01c76 | 2012-12-05 02:44:18 | [diff] [blame] | 76 | void* monitor_user_data_; |
| 77 | |
| 78 | DISALLOW_COPY_AND_ASSIGN(DeviceEnumerationResourceHelper); |
| 79 | }; |
| 80 | |
| 81 | } // namespace proxy |
| 82 | } // namespace ppapi |
| 83 | |
| 84 | #endif // PPAPI_PROXY_DEVICE_ENUMERATION_RESOURCE_HELPER_H_ |