Home | History | Annotate | Download | only in notifier
      1 // Copyright 2012 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 #ifndef SYNC_NOTIFIER_PUSH_CLIENT_CHANNEL_H_
      6 #define SYNC_NOTIFIER_PUSH_CLIENT_CHANNEL_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "jingle/notifier/listener/push_client_observer.h"
     14 #include "sync/base/sync_export.h"
     15 #include "sync/notifier/sync_system_resources.h"
     16 
     17 namespace notifier {
     18 class PushClient;
     19 }  // namespace notifier
     20 
     21 namespace syncer {
     22 
     23 // A PushClientChannel is an implementation of NetworkChannel that
     24 // routes messages through a PushClient.
     25 class SYNC_EXPORT_PRIVATE PushClientChannel
     26     : public SyncNetworkChannel,
     27       public NON_EXPORTED_BASE(notifier::PushClientObserver) {
     28  public:
     29   // |push_client| is guaranteed to be destroyed only when this object
     30   // is destroyed.
     31   explicit PushClientChannel(scoped_ptr<notifier::PushClient> push_client);
     32 
     33   virtual ~PushClientChannel();
     34 
     35   // If not connected, connects with the given credentials.  If
     36   // already connected, the next connection attempt will use the given
     37   // credentials.
     38   void UpdateCredentials(const std::string& email, const std::string& token);
     39 
     40   // SyncNetworkChannel implementation.
     41   virtual void SendEncodedMessage(const std::string& encoded_message) OVERRIDE;
     42 
     43   // notifier::PushClient::Observer implementation.
     44   virtual void OnNotificationsEnabled() OVERRIDE;
     45   virtual void OnNotificationsDisabled(
     46       notifier::NotificationsDisabledReason reason) OVERRIDE;
     47   virtual void OnIncomingNotification(
     48       const notifier::Notification& notification) OVERRIDE;
     49 
     50  private:
     51   scoped_ptr<notifier::PushClient> push_client_;
     52 
     53   DISALLOW_COPY_AND_ASSIGN(PushClientChannel);
     54 };
     55 
     56 }  // namespace syncer
     57 
     58 #endif  // SYNC_NOTIFIER_PUSH_CLIENT_CHANNEL_H_
     59