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/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "ppapi/c/dev/ppb_device_ref_dev.h"
19 struct HostMessageContext
;
20 struct ReplyMessageContext
;
37 // Resource hosts that support device enumeration can use this class to filter
38 // and process PpapiHostMsg_DeviceEnumeration_* messages.
39 // TODO(yzshen): Refactor ppapi::host::ResourceMessageFilter to support message
40 // handling on the same thread, and then derive this class from the filter
42 class CONTENT_EXPORT PepperDeviceEnumerationHostHelper
{
46 virtual ~Delegate() {}
48 // TODO(yzshen): Move the relevant functionality out of PluginDelegate and
49 // get rid of this method.
50 virtual webkit::ppapi::PluginDelegate
* GetPluginDelegate() = 0;
53 // |resource_host| and |delegate| must outlive this object.
54 PepperDeviceEnumerationHostHelper(ppapi::host::ResourceHost
* resource_host
,
56 PP_DeviceType_Dev device_type
);
57 ~PepperDeviceEnumerationHostHelper();
59 // Returns true if the message has been handled.
60 bool HandleResourceMessage(const IPC::Message
& msg
,
61 ppapi::host::HostMessageContext
* context
,
67 // Has a different signature than HandleResourceMessage() in order to utilize
68 // message dispatching macros.
69 int32_t InternalHandleResourceMessage(
70 const IPC::Message
& msg
,
71 ppapi::host::HostMessageContext
* context
,
74 int32_t OnEnumerateDevices(ppapi::host::HostMessageContext
* context
);
75 int32_t OnMonitorDeviceChange(ppapi::host::HostMessageContext
* context
,
76 uint32_t callback_id
);
77 int32_t OnStopMonitoringDeviceChange(
78 ppapi::host::HostMessageContext
* context
);
80 void OnEnumerateDevicesComplete(
83 const std::vector
<ppapi::DeviceRefData
>& devices
);
84 void OnNotifyDeviceChange(
88 const std::vector
<ppapi::DeviceRefData
>& devices
);
90 // Non-owning pointers.
91 ppapi::host::ResourceHost
* resource_host_
;
94 PP_DeviceType_Dev device_type_
;
96 scoped_ptr
<ScopedRequest
> enumerate_
;
97 scoped_ptr
<ScopedRequest
> monitor_
;
99 scoped_ptr
<ppapi::host::ReplyMessageContext
> enumerate_devices_context_
;
101 DISALLOW_COPY_AND_ASSIGN(PepperDeviceEnumerationHostHelper
);
104 } // namespace content
106 #endif // CONTENT_RENDERER_PEPPER_PEPPER_DEVICE_ENUMERATION_HOST_HELPER_H_