Home | History | Annotate | Download | only in extensions
      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 "ppapi/cpp/extensions/event_base.h"
      6 
      7 #include "ppapi/cpp/extensions/dev/events_dev.h"
      8 
      9 namespace pp {
     10 namespace ext {
     11 namespace internal {
     12 
     13 GenericEventBase::GenericEventBase(
     14     const InstanceHandle& instance,
     15     const PP_Ext_EventListener& pp_listener)
     16     : instance_(instance),
     17       listener_id_(0),
     18       pp_listener_(pp_listener) {
     19 }
     20 
     21 GenericEventBase::~GenericEventBase() {
     22   StopListening();
     23 }
     24 
     25 bool GenericEventBase::StartListening() {
     26   if (IsListening())
     27     return true;
     28 
     29   listener_id_ = events::Events_Dev::AddListener(instance_.pp_instance(),
     30                                                  pp_listener_);
     31   return IsListening();
     32 }
     33 
     34 void GenericEventBase::StopListening() {
     35   if (!IsListening())
     36     return;
     37 
     38   events::Events_Dev::RemoveListener(instance_.pp_instance(), listener_id_);
     39   listener_id_ = 0;
     40 }
     41 
     42 }  // namespace internal
     43 }  // namespace ext
     44 }  // namespace pp
     45