Home | History | Annotate | Download | only in notifier
      1 // Copyright (c) 2011 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 // A notifier that uses p2p notifications based on XMPP push
      6 // notifications.  Used only for sync integration tests.
      7 
      8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_
      9 #define CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_
     10 
     11 #include <string>
     12 
     13 #include "base/memory/ref_counted.h"
     14 #include "base/memory/scoped_ptr.h"
     15 #include "base/observer_list.h"
     16 #include "chrome/browser/sync/notifier/sync_notifier.h"
     17 #include "chrome/browser/sync/syncable/model_type.h"
     18 #include "jingle/notifier/listener/talk_mediator.h"
     19 
     20 namespace base {
     21 class MessageLoopProxy;
     22 }
     23 
     24 
     25 namespace notifier {
     26 struct NotifierOptions;
     27 }  // namespace
     28 
     29 namespace sync_notifier {
     30 
     31 class P2PNotifier
     32     : public SyncNotifier,
     33       public notifier::TalkMediator::Delegate {
     34  public:
     35   explicit P2PNotifier(const notifier::NotifierOptions& notifier_options);
     36 
     37   virtual ~P2PNotifier();
     38 
     39   // SyncNotifier implementation
     40   virtual void AddObserver(SyncNotifierObserver* observer);
     41   virtual void RemoveObserver(SyncNotifierObserver* observer);
     42   virtual void SetState(const std::string& state);
     43   virtual void UpdateCredentials(
     44       const std::string& email, const std::string& token);
     45   virtual void UpdateEnabledTypes(const syncable::ModelTypeSet& types);
     46   virtual void SendNotification();
     47 
     48   // TalkMediator::Delegate implementation.
     49   virtual void OnNotificationStateChange(bool notifications_enabled);
     50   virtual void OnIncomingNotification(
     51       const notifier::Notification& notification);
     52   virtual void OnOutgoingNotification();
     53 
     54  private:
     55   // Call OnIncomingNotification() on observers if we have a non-empty
     56   // set of enabled types.
     57   void MaybeEmitNotification();
     58   void CheckOrSetValidThread();
     59 
     60   ObserverList<SyncNotifierObserver> observer_list_;
     61 
     62   // The actual notification listener.
     63   scoped_ptr<notifier::TalkMediator> talk_mediator_;
     64   // Whether we called Login() on |talk_mediator_| yet.
     65   bool logged_in_;
     66   // Whether |talk_mediator_| has notified us that notifications are
     67   // enabled.
     68   bool notifications_enabled_;
     69 
     70   syncable::ModelTypeSet enabled_types_;
     71   scoped_refptr<base::MessageLoopProxy> construction_message_loop_proxy_;
     72   scoped_refptr<base::MessageLoopProxy> method_message_loop_proxy_;
     73 };
     74 
     75 }  // namespace sync_notifier
     76 #endif  // CHROME_BROWSER_SYNC_NOTIFIER_P2P_NOTIFIER_H_
     77