| OLD | NEW | 
|   1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |   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 |   2 // Use of this source code is governed by a BSD-style license that can be | 
|   3 // found in the LICENSE file. |   3 // found in the LICENSE file. | 
|   4  |   4  | 
|   5 #include "ui/events/devices/x11/device_list_cache_x11.h" |   5 #include "ui/events/devices/x11/device_list_cache_x11.h" | 
|   6  |   6  | 
|   7 #include <algorithm> |   7 #include <algorithm> | 
|   8  |   8  | 
|   9 #include "base/memory/singleton.h" |   9 #include "base/memory/singleton.h" | 
|  10 #include "base/message_loop/message_loop.h" |  10 #include "base/message_loop/message_loop.h" | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  21 } |  21 } | 
|  22  |  22  | 
|  23 } |  23 } | 
|  24  |  24  | 
|  25 namespace ui { |  25 namespace ui { | 
|  26  |  26  | 
|  27 DeviceListCacheX11::DeviceListCacheX11() { |  27 DeviceListCacheX11::DeviceListCacheX11() { | 
|  28 } |  28 } | 
|  29  |  29  | 
|  30 DeviceListCacheX11::~DeviceListCacheX11() { |  30 DeviceListCacheX11::~DeviceListCacheX11() { | 
|  31   std::map<Display*, XDeviceList>::iterator xp; |  | 
|  32   for (xp = x_dev_list_map_.begin(); xp != x_dev_list_map_.end(); xp++) { |  | 
|  33     if (xp->second.devices) |  | 
|  34       XFreeDeviceList(xp->second.devices); |  | 
|  35   } |  | 
|  36   std::map<Display*, XIDeviceList>::iterator xip; |  | 
|  37   for (xip = xi_dev_list_map_.begin(); xip != xi_dev_list_map_.end(); xip++) { |  | 
|  38     if (xip->second.devices) |  | 
|  39       XIFreeDeviceInfo(xip->second.devices); |  | 
|  40   } |  | 
|  41 } |  31 } | 
|  42  |  32  | 
|  43 DeviceListCacheX11* DeviceListCacheX11::GetInstance() { |  33 DeviceListCacheX11* DeviceListCacheX11::GetInstance() { | 
|  44   return Singleton<DeviceListCacheX11>::get(); |  34   return Singleton<DeviceListCacheX11>::get(); | 
|  45 } |  35 } | 
|  46  |  36  | 
|  47 void DeviceListCacheX11::UpdateDeviceList(Display* display) { |  37 void DeviceListCacheX11::UpdateDeviceList(Display* display) { | 
|  48   XDeviceList& new_x_dev_list = x_dev_list_map_[display]; |  38   XDeviceList& new_x_dev_list = x_dev_list_; | 
|  49   if (new_x_dev_list.devices) |  39   new_x_dev_list.devices.reset( | 
|  50     XFreeDeviceList(new_x_dev_list.devices); |  40       XListInputDevices(display, &new_x_dev_list.count)); | 
|  51   new_x_dev_list.devices = XListInputDevices(display, &new_x_dev_list.count); |  | 
|  52  |  41  | 
|  53   XIDeviceList& new_xi_dev_list = xi_dev_list_map_[display]; |  42   XIDeviceList& new_xi_dev_list = xi_dev_list_; | 
|  54   if (new_xi_dev_list.devices) |  43   new_xi_dev_list.devices.reset( | 
|  55     XIFreeDeviceInfo(new_xi_dev_list.devices); |  44       IsXI2Available() | 
|  56   new_xi_dev_list.devices = IsXI2Available() ? |  45           ? XIQueryDevice(display, XIAllDevices, &new_xi_dev_list.count) | 
|  57       XIQueryDevice(display, XIAllDevices, &new_xi_dev_list.count) : NULL; |  46           : nullptr); | 
|  58 } |  47 } | 
|  59  |  48  | 
|  60 const XDeviceList& DeviceListCacheX11::GetXDeviceList(Display* display) { |  49 const XDeviceList& DeviceListCacheX11::GetXDeviceList(Display* display) { | 
|  61   XDeviceList& x_dev_list = x_dev_list_map_[display]; |  50   XDeviceList& x_dev_list = x_dev_list_; | 
|  62   // Note that the function can be called before any update has taken place. |  51   // Note that the function can be called before any update has taken place. | 
|  63   if (!x_dev_list.devices && !x_dev_list.count) |  52   if (!x_dev_list.devices && !x_dev_list.count) | 
|  64     x_dev_list.devices = XListInputDevices(display, &x_dev_list.count); |  53     x_dev_list.devices.reset(XListInputDevices(display, &x_dev_list.count)); | 
|  65   return x_dev_list; |  54   return x_dev_list; | 
|  66 } |  55 } | 
|  67  |  56  | 
|  68 const XIDeviceList& DeviceListCacheX11::GetXI2DeviceList(Display* display) { |  57 const XIDeviceList& DeviceListCacheX11::GetXI2DeviceList(Display* display) { | 
|  69   XIDeviceList& xi_dev_list = xi_dev_list_map_[display]; |  58   XIDeviceList& xi_dev_list = xi_dev_list_; | 
|  70   if (!xi_dev_list.devices && !xi_dev_list.count) { |  59   if (!xi_dev_list.devices && !xi_dev_list.count) { | 
|  71     xi_dev_list.devices = XIQueryDevice(display, XIAllDevices, |  60     xi_dev_list.devices.reset( | 
|  72                                        &xi_dev_list.count); |  61         XIQueryDevice(display, XIAllDevices, &xi_dev_list.count)); | 
|  73   } |  62   } | 
|  74   return xi_dev_list; |  63   return xi_dev_list; | 
|  75 } |  64 } | 
|  76  |  65  | 
|  77 }  // namespace ui |  66 }  // namespace ui | 
|  78  |  67  | 
| OLD | NEW |