Home | History | Annotate | Download | only in ozone
      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
      3 // found in the LICENSE file.
      4 
      5 #include "ui/events/ozone/event_factory_ozone.h"
      6 
      7 #include "base/command_line.h"
      8 #include "base/message_loop/message_pump_ozone.h"
      9 #include "base/stl_util.h"
     10 #include "base/strings/stringprintf.h"
     11 #include "ui/events/event_switches.h"
     12 
     13 namespace ui {
     14 
     15 // static
     16 EventFactoryOzone* EventFactoryOzone::impl_ = NULL;
     17 
     18 EventFactoryOzone::EventFactoryOzone() {}
     19 
     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_);
     24 }
     25 
     26 EventFactoryOzone* EventFactoryOzone::GetInstance() {
     27   CHECK(impl_) << "No EventFactoryOzone implementation set.";
     28   return impl_;
     29 }
     30 
     31 void EventFactoryOzone::SetInstance(EventFactoryOzone* impl) { impl_ = impl; }
     32 
     33 void EventFactoryOzone::StartProcessingEvents() {}
     34 
     35 void EventFactoryOzone::AddEventConverter(
     36     int fd,
     37     scoped_ptr<EventConverterOzone> converter) {
     38   CHECK(watchers_.count(fd) == 0 && converters_.count(fd) == 0);
     39 
     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();
     50   watchers_[fd] = watcher;
     51 }
     52 
     53 void EventFactoryOzone::RemoveEventConverter(int fd) {
     54   // Always delete watchers before converters to prevent a possible race.
     55   delete watchers_[fd];
     56   delete converters_[fd];
     57   watchers_.erase(fd);
     58   converters_.erase(fd);
     59 }
     60 
     61 }  // namespace ui
     62