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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/common/content_export.h"
14 #include "ppapi/c/dev/ppb_device_ref_dev.h"
20 struct HostMessageContext;
21 struct ReplyMessageContext;
32 // Resource hosts that support device enumeration can use this class to filter
33 // and process PpapiHostMsg_DeviceEnumeration_* messages.
34 // TODO(yzshen): Refactor ppapi::host::ResourceMessageFilter to support message
35 // handling on the same thread, and then derive this class from the filter
37 class CONTENT_EXPORT PepperDeviceEnumerationHostHelper {
41 virtual ~Delegate() {}
43 typedef base::Callback<
44 void (int /* request_id */,
46 const std::vector<ppapi::DeviceRefData>& /* devices */)>
47 EnumerateDevicesCallback;
49 // Enumerates devices of the specified type. The request ID passed into the
50 // callback will be the same as the return value.
51 virtual int EnumerateDevices(PP_DeviceType_Dev type,
52 const EnumerateDevicesCallback& callback) = 0;
53 // Stop enumerating devices of the specified |request_id|. The |request_id|
54 // is the return value of EnumerateDevicesCallback.
55 virtual void StopEnumerateDevices(int request_id) = 0;
58 // |resource_host| and |delegate| must outlive this object.
59 PepperDeviceEnumerationHostHelper(ppapi::host::ResourceHost* resource_host,
61 PP_DeviceType_Dev device_type);
62 ~PepperDeviceEnumerationHostHelper();
64 // Returns true if the message has been handled.
65 bool HandleResourceMessage(const IPC::Message& msg,
66 ppapi::host::HostMessageContext* context,
72 // Has a different signature than HandleResourceMessage() in order to utilize
73 // message dispatching macros.
74 int32_t InternalHandleResourceMessage(
75 const IPC::Message& msg,
76 ppapi::host::HostMessageContext* context,
79 int32_t OnEnumerateDevices(ppapi::host::HostMessageContext* context);
80 int32_t OnMonitorDeviceChange(ppapi::host::HostMessageContext* context,
81 uint32_t callback_id);
82 int32_t OnStopMonitoringDeviceChange(
83 ppapi::host::HostMessageContext* context);
85 void OnEnumerateDevicesComplete(
88 const std::vector<ppapi::DeviceRefData>& devices);
89 void OnNotifyDeviceChange(
93 const std::vector<ppapi::DeviceRefData>& devices);
95 // Non-owning pointers.
96 ppapi::host::ResourceHost* resource_host_;
99 PP_DeviceType_Dev device_type_;
101 scoped_ptr<ScopedRequest> enumerate_;
102 scoped_ptr<ScopedRequest> monitor_;
104 scoped_ptr<ppapi::host::ReplyMessageContext> enumerate_devices_context_;
106 DISALLOW_COPY_AND_ASSIGN(PepperDeviceEnumerationHostHelper);
109 } // namespace content
111 #endif // CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_