| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 CHROME_BROWSER_EXTENSIONS_API_HID_HID_API_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_HID_HID_API_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "chrome/browser/extensions/api/hid/hid_connection_resource.h" | |
| 13 #include "chrome/browser/extensions/api/hid/hid_device_manager.h" | |
| 14 #include "chrome/common/extensions/api/hid.h" | |
| 15 #include "extensions/browser/api/api_resource_manager.h" | |
| 16 #include "extensions/browser/api/async_api_function.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 class IOBufferWithSize; | |
| 21 | |
| 22 } // namespace net | |
| 23 | |
| 24 namespace extensions { | |
| 25 | |
| 26 class HidAsyncApiFunction : public AsyncApiFunction { | |
| 27 public: | |
| 28 HidAsyncApiFunction(); | |
| 29 | |
| 30 virtual bool PrePrepare() OVERRIDE; | |
| 31 virtual bool Respond() OVERRIDE; | |
| 32 | |
| 33 protected: | |
| 34 virtual ~HidAsyncApiFunction(); | |
| 35 | |
| 36 HidConnectionResource* GetHidConnectionResource(int api_resource_id); | |
| 37 void RemoveHidConnectionResource(int api_resource_id); | |
| 38 | |
| 39 void CompleteWithError(const std::string& error); | |
| 40 | |
| 41 HidDeviceManager* device_manager_; | |
| 42 ApiResourceManager<HidConnectionResource>* connection_manager_; | |
| 43 | |
| 44 private: | |
| 45 DISALLOW_COPY_AND_ASSIGN(HidAsyncApiFunction); | |
| 46 }; | |
| 47 | |
| 48 class HidGetDevicesFunction : public HidAsyncApiFunction { | |
| 49 public: | |
| 50 DECLARE_EXTENSION_FUNCTION("hid.getDevices", HID_GETDEVICES); | |
| 51 | |
| 52 HidGetDevicesFunction(); | |
| 53 | |
| 54 protected: | |
| 55 virtual bool Prepare() OVERRIDE; | |
| 56 virtual void AsyncWorkStart() OVERRIDE; | |
| 57 | |
| 58 virtual ~HidGetDevicesFunction(); | |
| 59 | |
| 60 scoped_ptr<base::ListValue> result_; | |
| 61 scoped_ptr<extensions::api::hid::GetDevices::Params> parameters_; | |
| 62 | |
| 63 private: | |
| 64 DISALLOW_COPY_AND_ASSIGN(HidGetDevicesFunction); | |
| 65 }; | |
| 66 | |
| 67 class HidConnectFunction : public HidAsyncApiFunction { | |
| 68 public: | |
| 69 DECLARE_EXTENSION_FUNCTION("hid.connect", HID_CONNECT); | |
| 70 | |
| 71 HidConnectFunction(); | |
| 72 | |
| 73 protected: | |
| 74 virtual bool Prepare() OVERRIDE; | |
| 75 virtual void AsyncWorkStart() OVERRIDE; | |
| 76 | |
| 77 private: | |
| 78 virtual ~HidConnectFunction(); | |
| 79 | |
| 80 scoped_ptr<base::ListValue> result_; | |
| 81 scoped_ptr<extensions::api::hid::Connect::Params> parameters_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(HidConnectFunction); | |
| 84 }; | |
| 85 | |
| 86 class HidDisconnectFunction : public HidAsyncApiFunction { | |
| 87 public: | |
| 88 DECLARE_EXTENSION_FUNCTION("hid.disconnect", HID_DISCONNECT); | |
| 89 | |
| 90 HidDisconnectFunction(); | |
| 91 | |
| 92 protected: | |
| 93 virtual bool Prepare() OVERRIDE; | |
| 94 virtual void AsyncWorkStart() OVERRIDE; | |
| 95 | |
| 96 private: | |
| 97 virtual ~HidDisconnectFunction(); | |
| 98 | |
| 99 scoped_ptr<base::ListValue> result_; | |
| 100 scoped_ptr<extensions::api::hid::Disconnect::Params> parameters_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(HidDisconnectFunction); | |
| 103 }; | |
| 104 | |
| 105 class HidReceiveFunction : public HidAsyncApiFunction { | |
| 106 public: | |
| 107 DECLARE_EXTENSION_FUNCTION("hid.receive", HID_RECEIVE); | |
| 108 | |
| 109 HidReceiveFunction(); | |
| 110 | |
| 111 protected: | |
| 112 virtual bool Prepare() OVERRIDE; | |
| 113 virtual void AsyncWorkStart() OVERRIDE; | |
| 114 | |
| 115 private: | |
| 116 virtual ~HidReceiveFunction(); | |
| 117 | |
| 118 void OnFinished(bool success, size_t bytes); | |
| 119 | |
| 120 scoped_refptr<net::IOBufferWithSize> buffer_; | |
| 121 scoped_ptr<base::ListValue> result_; | |
| 122 scoped_ptr<extensions::api::hid::Receive::Params> parameters_; | |
| 123 | |
| 124 DISALLOW_COPY_AND_ASSIGN(HidReceiveFunction); | |
| 125 }; | |
| 126 | |
| 127 class HidSendFunction : public HidAsyncApiFunction { | |
| 128 public: | |
| 129 DECLARE_EXTENSION_FUNCTION("hid.send", HID_SEND); | |
| 130 | |
| 131 HidSendFunction(); | |
| 132 | |
| 133 protected: | |
| 134 virtual bool Prepare() OVERRIDE; | |
| 135 virtual void AsyncWorkStart() OVERRIDE; | |
| 136 | |
| 137 private: | |
| 138 virtual ~HidSendFunction(); | |
| 139 | |
| 140 void OnFinished(bool success, size_t bytes); | |
| 141 | |
| 142 scoped_ptr<base::ListValue> result_; | |
| 143 scoped_ptr<extensions::api::hid::Send::Params> parameters_; | |
| 144 | |
| 145 DISALLOW_COPY_AND_ASSIGN(HidSendFunction); | |
| 146 }; | |
| 147 | |
| 148 class HidReceiveFeatureReportFunction : public HidAsyncApiFunction { | |
| 149 public: | |
| 150 DECLARE_EXTENSION_FUNCTION("hid.receiveFeatureReport", | |
| 151 HID_RECEIVEFEATUREREPORT); | |
| 152 | |
| 153 HidReceiveFeatureReportFunction(); | |
| 154 | |
| 155 protected: | |
| 156 virtual bool Prepare() OVERRIDE; | |
| 157 virtual void AsyncWorkStart() OVERRIDE; | |
| 158 | |
| 159 private: | |
| 160 virtual ~HidReceiveFeatureReportFunction(); | |
| 161 | |
| 162 void OnFinished(bool success, size_t bytes); | |
| 163 | |
| 164 scoped_refptr<net::IOBufferWithSize> buffer_; | |
| 165 scoped_ptr<base::ListValue> result_; | |
| 166 scoped_ptr<extensions::api::hid::ReceiveFeatureReport::Params> parameters_; | |
| 167 | |
| 168 DISALLOW_COPY_AND_ASSIGN(HidReceiveFeatureReportFunction); | |
| 169 }; | |
| 170 | |
| 171 class HidSendFeatureReportFunction : public HidAsyncApiFunction { | |
| 172 public: | |
| 173 DECLARE_EXTENSION_FUNCTION("hid.sendFeatureReport", HID_SENDFEATUREREPORT); | |
| 174 | |
| 175 HidSendFeatureReportFunction(); | |
| 176 | |
| 177 protected: | |
| 178 virtual bool Prepare() OVERRIDE; | |
| 179 virtual void AsyncWorkStart() OVERRIDE; | |
| 180 | |
| 181 private: | |
| 182 virtual ~HidSendFeatureReportFunction(); | |
| 183 | |
| 184 void OnFinished(bool success, size_t bytes); | |
| 185 | |
| 186 scoped_ptr<base::ListValue> result_; | |
| 187 scoped_ptr<extensions::api::hid::SendFeatureReport::Params> parameters_; | |
| 188 | |
| 189 DISALLOW_COPY_AND_ASSIGN(HidSendFeatureReportFunction); | |
| 190 }; | |
| 191 | |
| 192 } // namespace extensions | |
| 193 | |
| 194 #endif // CHROME_BROWSER_EXTENSIONS_API_HID_HID_API_H_ | |
| OLD | NEW |