| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/event_factory_ozone.h" | 5 #include "ui/events/ozone/event_factory_ozone.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_pump_ozone.h" | 8 #include "base/message_loop/message_pump_ozone.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "ui/events/event_switches.h" | 11 #include "ui/events/event_switches.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 EventFactoryOzone* EventFactoryOzone::impl_ = NULL; | 16 EventFactoryOzone* EventFactoryOzone::impl_ = NULL; |
| 17 | 17 |
| 18 EventFactoryOzone::EventFactoryOzone() {} | 18 EventFactoryOzone::EventFactoryOzone() {} |
| 19 | 19 |
| 20 EventFactoryOzone::~EventFactoryOzone() { | 20 EventFactoryOzone::~EventFactoryOzone() { |
| 21 // Always delete watchers before converters to prevent a possible race. | |
| 22 STLDeleteValues<std::map<int, FDWatcher> >(&watchers_); | |
| 23 STLDeleteValues<std::map<int, Converter> >(&converters_); | 21 STLDeleteValues<std::map<int, Converter> >(&converters_); |
| 24 } | 22 } |
| 25 | 23 |
| 26 EventFactoryOzone* EventFactoryOzone::GetInstance() { | 24 EventFactoryOzone* EventFactoryOzone::GetInstance() { |
| 27 CHECK(impl_) << "No EventFactoryOzone implementation set."; | 25 CHECK(impl_) << "No EventFactoryOzone implementation set."; |
| 28 return impl_; | 26 return impl_; |
| 29 } | 27 } |
| 30 | 28 |
| 31 void EventFactoryOzone::SetInstance(EventFactoryOzone* impl) { impl_ = impl; } | 29 void EventFactoryOzone::SetInstance(EventFactoryOzone* impl) { impl_ = impl; } |
| 32 | 30 |
| 33 void EventFactoryOzone::StartProcessingEvents() {} | 31 void EventFactoryOzone::StartProcessingEvents() {} |
| 34 | 32 |
| 35 void EventFactoryOzone::AddEventConverter( | 33 void EventFactoryOzone::AddEventConverter( |
| 36 int fd, | 34 int fd, |
| 37 scoped_ptr<EventConverterOzone> converter) { | 35 scoped_ptr<EventConverterOzone> converter) { |
| 38 CHECK(watchers_.count(fd) == 0 && converters_.count(fd) == 0); | 36 CHECK_EQ(converters_.count(fd), 0); |
| 39 | 37 converter->Start(); |
| 40 FDWatcher watcher = new base::MessagePumpLibevent::FileDescriptorWatcher(); | |
| 41 | |
| 42 base::MessagePumpOzone::Current()->WatchFileDescriptor( | |
| 43 fd, | |
| 44 true, | |
| 45 base::MessagePumpLibevent::WATCH_READ, | |
| 46 watcher, | |
| 47 converter.get()); | |
| 48 | |
| 49 converters_[fd] = converter.release(); | 38 converters_[fd] = converter.release(); |
| 50 watchers_[fd] = watcher; | |
| 51 } | 39 } |
| 52 | 40 |
| 53 void EventFactoryOzone::RemoveEventConverter(int fd) { | 41 void EventFactoryOzone::RemoveEventConverter(int fd) { |
| 54 // Always delete watchers before converters to prevent a possible race. | |
| 55 delete watchers_[fd]; | |
| 56 delete converters_[fd]; | 42 delete converters_[fd]; |
| 57 watchers_.erase(fd); | |
| 58 converters_.erase(fd); | 43 converters_.erase(fd); |
| 59 } | 44 } |
| 60 | 45 |
| 61 } // namespace ui | 46 } // namespace ui |
| OLD | NEW |