blob: 5c4fe72891e1bf5028ca72c6b586b648f564bdb3 [file] [log] [blame]
[email protected]4f01c762012-12-05 02:44:181// 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
avie029c4132015-12-23 06:45:228#include <stdint.h>
9
dchengced92242016-04-07 00:00:1210#include <memory>
[email protected]4f01c762012-12-05 02:44:1811#include <vector>
12
avie029c4132015-12-23 06:45:2213#include "base/macros.h"
[email protected]4f01c762012-12-05 02:44:1814#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]7ef6b79b2013-01-17 02:38:2418#include "ppapi/shared_impl/thread_aware_callback.h"
[email protected]4f01c762012-12-05 02:44:1819
20namespace IPC {
21class Message;
22}
23
24struct PP_ArrayOutput;
25
26namespace ppapi {
27
28struct DeviceRefData;
29class TrackedCallback;
30
31namespace proxy {
32
33class PluginResource;
34class ResourceMessageReplyParams;
35
36class 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]4f01c762012-12-05 02:44:1843 int32_t EnumerateDevices(const PP_ArrayOutput& output,
44 scoped_refptr<TrackedCallback> callback);
[email protected]33eccce2012-12-10 22:15:1045 int32_t EnumerateDevicesSync(const PP_ArrayOutput& output);
[email protected]4f01c762012-12-05 02:44:1846 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]4f01c762012-12-05 02:44:1856 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]33eccce2012-12-10 22:15:1065 int32_t WriteToArrayOutput(const std::vector<DeviceRefData>& devices,
66 const PP_ArrayOutput& output);
67
[email protected]4f01c762012-12-05 02:44:1868 // Not owned by this object.
69 PluginResource* owner_;
70
71 bool pending_enumerate_devices_;
72
73 uint32_t monitor_callback_id_;
dchengced92242016-04-07 00:00:1274 std::unique_ptr<ThreadAwareCallback<PP_MonitorDeviceChangeCallback>>
[email protected]7ef6b79b2013-01-17 02:38:2475 monitor_callback_;
[email protected]4f01c762012-12-05 02:44:1876 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_