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"
15 #include "ppapi/host/host_message_context.h"
33 // Resource hosts that support device enumeration can use this class to filter
34 // and process PpapiHostMsg_DeviceEnumeration_* messages.
35 // TODO(yzshen): Refactor ppapi::host::ResourceMessageFilter to support message
36 // handling on the same thread, and then derive this class from the filter
38 class CONTENT_EXPORT PepperDeviceEnumerationHostHelper
{
42 virtual ~Delegate() {}
44 typedef base::Callback
<
45 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 GURL
& document_url
,
53 const EnumerateDevicesCallback
& callback
) = 0;
54 // Stop enumerating devices of the specified |request_id|. The |request_id|
55 // is the return value of EnumerateDevicesCallback.
56 virtual void StopEnumerateDevices(int request_id
) = 0;
59 // |resource_host| and |delegate| must outlive this object.
60 PepperDeviceEnumerationHostHelper(ppapi::host::ResourceHost
* resource_host
,
62 PP_DeviceType_Dev device_type
,
63 const GURL
& document_url
);
64 ~PepperDeviceEnumerationHostHelper();
66 // Returns true if the message has been handled.
67 bool HandleResourceMessage(const IPC::Message
& msg
,
68 ppapi::host::HostMessageContext
* context
,
74 // Has a different signature than HandleResourceMessage() in order to utilize
75 // message dispatching macros.
76 int32_t InternalHandleResourceMessage(
77 const IPC::Message
& msg
,
78 ppapi::host::HostMessageContext
* context
,
81 int32_t OnEnumerateDevices(ppapi::host::HostMessageContext
* context
);
82 int32_t OnMonitorDeviceChange(ppapi::host::HostMessageContext
* context
,
83 uint32_t callback_id
);
84 int32_t OnStopMonitoringDeviceChange(
85 ppapi::host::HostMessageContext
* context
);
87 void OnEnumerateDevicesComplete(
89 const std::vector
<ppapi::DeviceRefData
>& devices
);
90 void OnNotifyDeviceChange(uint32_t callback_id
,
92 const std::vector
<ppapi::DeviceRefData
>& devices
);
94 // Non-owning pointers.
95 ppapi::host::ResourceHost
* resource_host_
;
98 PP_DeviceType_Dev device_type_
;
101 scoped_ptr
<ScopedRequest
> enumerate_
;
102 scoped_ptr
<ScopedRequest
> monitor_
;
104 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_