Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / device / hid / hid_service_mac.cc
index c32ebb4..7d40cae 100644 (file)
@@ -106,8 +106,11 @@ void GetCollectionInfos(IOHIDDeviceRef device,
       HidCollectionInfo collection_info;
       HidUsageAndPage::Page page = static_cast<HidUsageAndPage::Page>(
           IOHIDElementGetUsagePage(collection));
-      uint16_t usage = IOHIDElementGetUsage(collection);
-      collection_info.usage = HidUsageAndPage(usage, page);
+      uint32_t usage = IOHIDElementGetUsage(collection);
+      if (usage > std::numeric_limits<uint16_t>::max())
+        continue;
+      collection_info.usage =
+          HidUsageAndPage(static_cast<uint16_t>(usage), page);
       // Explore children recursively and retrieve their report IDs
       GetReportIds(collection, &collection_info.report_ids);
       if (collection_info.report_ids.size() > 0) {
@@ -130,6 +133,11 @@ void PopulateDeviceInfo(io_service_t service, HidDeviceInfo* device_info) {
 
   base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device(
       IOHIDDeviceCreate(kCFAllocatorDefault, service));
+  if (!hid_device) {
+    VLOG(1) << "Unable to create IOHIDDevice object.";
+    return;
+  }
+
   device_info->device_id = service_path;
   device_info->vendor_id =
       GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey));
@@ -259,13 +267,14 @@ void HidServiceMac::RemoveDevices() {
   }
 }
 
-scoped_refptr<HidConnection> HidServiceMac::Connect(
-    const HidDeviceId& device_id) {
+void HidServiceMac::Connect(const HidDeviceId& device_id,
+                            const ConnectCallback& callback) {
   DCHECK(thread_checker_.CalledOnValidThread());
 
   const auto& map_entry = devices().find(device_id);
   if (map_entry == devices().end()) {
-    return NULL;
+    task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+    return;
   }
   const HidDeviceInfo& device_info = map_entry->second;
 
@@ -275,20 +284,31 @@ scoped_refptr<HidConnection> HidServiceMac::Connect(
       IORegistryEntryFromPath(kIOMasterPortDefault, service_path));
   if (!service.get()) {
     VLOG(1) << "IOService not found for path: " << device_id;
-    return NULL;
+    task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+    return;
   }
 
   base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device(
       IOHIDDeviceCreate(kCFAllocatorDefault, service));
+  if (!hid_device) {
+    VLOG(1) << "Unable to create IOHIDDevice object.";
+    task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+    return;
+  }
+
   IOReturn result = IOHIDDeviceOpen(hid_device, kIOHIDOptionsTypeNone);
   if (result != kIOReturnSuccess) {
     VLOG(1) << "Failed to open device: "
             << base::StringPrintf("0x%04x", result);
-    return NULL;
+    task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+    return;
   }
 
-  return make_scoped_refptr(new HidConnectionMac(
-      hid_device.release(), device_info, file_task_runner_));
+  task_runner_->PostTask(
+      FROM_HERE,
+      base::Bind(callback,
+                 make_scoped_refptr(new HidConnectionMac(
+                     hid_device.release(), device_info, file_task_runner_))));
 }
 
 }  // namespace device