Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: ui/events/ozone/device/udev/device_manager_udev.cc

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/ozone/device/udev/device_manager_udev.h" 5 #include "ui/events/ozone/device/udev/device_manager_udev.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
12 #include "ui/events/ozone/device/device_event.h" 13 #include "ui/events/ozone/device/device_event.h"
13 #include "ui/events/ozone/device/device_event_observer.h" 14 #include "ui/events/ozone/device/device_event_observer.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 namespace { 18 namespace {
18 19
19 const char* const kSubsystems[] = { 20 const char* const kSubsystems[] = {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 struct udev_list_entry* devices = 114 struct udev_list_entry* devices =
114 device::udev_enumerate_get_list_entry(enumerate.get()); 115 device::udev_enumerate_get_list_entry(enumerate.get());
115 struct udev_list_entry* entry; 116 struct udev_list_entry* entry;
116 117
117 udev_list_entry_foreach(entry, devices) { 118 udev_list_entry_foreach(entry, devices) {
118 device::ScopedUdevDevicePtr device(device::udev_device_new_from_syspath( 119 device::ScopedUdevDevicePtr device(device::udev_device_new_from_syspath(
119 udev_.get(), device::udev_list_entry_get_name(entry))); 120 udev_.get(), device::udev_list_entry_get_name(entry)));
120 if (!device) 121 if (!device)
121 continue; 122 continue;
122 123
123 scoped_ptr<DeviceEvent> event = ProcessMessage(device.get()); 124 std::unique_ptr<DeviceEvent> event = ProcessMessage(device.get());
124 if (event) 125 if (event)
125 observer->OnDeviceEvent(*event.get()); 126 observer->OnDeviceEvent(*event.get());
126 } 127 }
127 } 128 }
128 129
129 void DeviceManagerUdev::AddObserver(DeviceEventObserver* observer) { 130 void DeviceManagerUdev::AddObserver(DeviceEventObserver* observer) {
130 observers_.AddObserver(observer); 131 observers_.AddObserver(observer);
131 } 132 }
132 133
133 void DeviceManagerUdev::RemoveObserver(DeviceEventObserver* observer) { 134 void DeviceManagerUdev::RemoveObserver(DeviceEventObserver* observer) {
134 observers_.RemoveObserver(observer); 135 observers_.RemoveObserver(observer);
135 } 136 }
136 137
137 void DeviceManagerUdev::OnFileCanReadWithoutBlocking(int fd) { 138 void DeviceManagerUdev::OnFileCanReadWithoutBlocking(int fd) {
138 // The netlink socket should never become disconnected. There's no need 139 // The netlink socket should never become disconnected. There's no need
139 // to handle broken connections here. 140 // to handle broken connections here.
140 TRACE_EVENT1("evdev", "UdevDeviceChange", "socket", fd); 141 TRACE_EVENT1("evdev", "UdevDeviceChange", "socket", fd);
141 142
142 device::ScopedUdevDevicePtr device( 143 device::ScopedUdevDevicePtr device(
143 device::udev_monitor_receive_device(monitor_.get())); 144 device::udev_monitor_receive_device(monitor_.get()));
144 if (!device) 145 if (!device)
145 return; 146 return;
146 147
147 scoped_ptr<DeviceEvent> event = ProcessMessage(device.get()); 148 std::unique_ptr<DeviceEvent> event = ProcessMessage(device.get());
148 if (event) 149 if (event)
149 FOR_EACH_OBSERVER( 150 FOR_EACH_OBSERVER(
150 DeviceEventObserver, observers_, OnDeviceEvent(*event.get())); 151 DeviceEventObserver, observers_, OnDeviceEvent(*event.get()));
151 } 152 }
152 153
153 void DeviceManagerUdev::OnFileCanWriteWithoutBlocking(int fd) { 154 void DeviceManagerUdev::OnFileCanWriteWithoutBlocking(int fd) {
154 NOTREACHED(); 155 NOTREACHED();
155 } 156 }
156 157
157 scoped_ptr<DeviceEvent> DeviceManagerUdev::ProcessMessage(udev_device* device) { 158 std::unique_ptr<DeviceEvent> DeviceManagerUdev::ProcessMessage(
159 udev_device* device) {
158 const char* path = device::udev_device_get_devnode(device); 160 const char* path = device::udev_device_get_devnode(device);
159 const char* action = device::udev_device_get_action(device); 161 const char* action = device::udev_device_get_action(device);
160 const char* subsystem = 162 const char* subsystem =
161 device::udev_device_get_property_value(device, "SUBSYSTEM"); 163 device::udev_device_get_property_value(device, "SUBSYSTEM");
162 164
163 if (!path || !subsystem) 165 if (!path || !subsystem)
164 return nullptr; 166 return nullptr;
165 167
166 DeviceEvent::DeviceType device_type; 168 DeviceEvent::DeviceType device_type;
167 if (!strcmp(subsystem, "input") && 169 if (!strcmp(subsystem, "input") &&
168 base::StartsWith(path, "/dev/input/event", base::CompareCase::SENSITIVE)) 170 base::StartsWith(path, "/dev/input/event", base::CompareCase::SENSITIVE))
169 device_type = DeviceEvent::INPUT; 171 device_type = DeviceEvent::INPUT;
170 else if (!strcmp(subsystem, "drm") && 172 else if (!strcmp(subsystem, "drm") &&
171 base::StartsWith(path, "/dev/dri/card", 173 base::StartsWith(path, "/dev/dri/card",
172 base::CompareCase::SENSITIVE)) 174 base::CompareCase::SENSITIVE))
173 device_type = DeviceEvent::DISPLAY; 175 device_type = DeviceEvent::DISPLAY;
174 else 176 else
175 return nullptr; 177 return nullptr;
176 178
177 DeviceEvent::ActionType action_type; 179 DeviceEvent::ActionType action_type;
178 if (!action || !strcmp(action, "add")) 180 if (!action || !strcmp(action, "add"))
179 action_type = DeviceEvent::ADD; 181 action_type = DeviceEvent::ADD;
180 else if (!strcmp(action, "remove")) 182 else if (!strcmp(action, "remove"))
181 action_type = DeviceEvent::REMOVE; 183 action_type = DeviceEvent::REMOVE;
182 else if (!strcmp(action, "change")) 184 else if (!strcmp(action, "change"))
183 action_type = DeviceEvent::CHANGE; 185 action_type = DeviceEvent::CHANGE;
184 else 186 else
185 return nullptr; 187 return nullptr;
186 188
187 return make_scoped_ptr( 189 return base::WrapUnique(
188 new DeviceEvent(device_type, action_type, base::FilePath(path))); 190 new DeviceEvent(device_type, action_type, base::FilePath(path)));
189 } 191 }
190 192
191 } // namespace ui 193 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/device/udev/device_manager_udev.h ('k') | ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698