Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_device_enumeration_host_helper.h
blob5773845561bb6f3b2cf550e07adfc08814ca555f
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_
8 #include <vector>
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"
16 namespace ppapi {
17 struct DeviceRefData;
19 namespace host {
20 struct HostMessageContext;
21 struct ReplyMessageContext;
22 class ResourceHost;
26 namespace IPC {
27 class Message;
30 namespace content {
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
36 // class.
37 class CONTENT_EXPORT PepperDeviceEnumerationHostHelper {
38 public:
39 class Delegate {
40 public:
41 virtual ~Delegate() {}
43 typedef base::Callback<
44 void (int /* request_id */,
45 bool /* succeeded */,
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,
60 Delegate* delegate,
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,
67 int32_t* result);
69 private:
70 class ScopedRequest;
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,
77 bool* handled);
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(
86 int request_id,
87 bool succeeded,
88 const std::vector<ppapi::DeviceRefData>& devices);
89 void OnNotifyDeviceChange(
90 uint32_t callback_id,
91 int request_id,
92 bool succeeded,
93 const std::vector<ppapi::DeviceRefData>& devices);
95 // Non-owning pointers.
96 ppapi::host::ResourceHost* resource_host_;
97 Delegate* delegate_;
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_