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.
5 #ifndef SYNC_NOTIFIER_PUSH_CLIENT_CHANNEL_H_
6 #define SYNC_NOTIFIER_PUSH_CLIENT_CHANNEL_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "google/cacheinvalidation/include/system-resources.h"
15 #include "jingle/notifier/listener/push_client_observer.h"
16 #include "sync/base/sync_export.h"
20 } // namespace notifier
24 // A PushClientChannel is an implementation of NetworkChannel that
25 // routes messages through a PushClient.
26 class SYNC_EXPORT_PRIVATE PushClientChannel
27 : public NON_EXPORTED_BASE(invalidation::NetworkChannel),
28 public NON_EXPORTED_BASE(notifier::PushClientObserver) {
30 // |push_client| is guaranteed to be destroyed only when this object
32 explicit PushClientChannel(scoped_ptr<notifier::PushClient> push_client);
34 virtual ~PushClientChannel();
36 // If not connected, connects with the given credentials. If
37 // already connected, the next connection attempt will use the given
39 void UpdateCredentials(const std::string& email, const std::string& token);
41 // invalidation::NetworkChannel implementation.
42 virtual void SendMessage(const std::string& outgoing_message) OVERRIDE;
43 virtual void SetMessageReceiver(
44 invalidation::MessageCallback* incoming_receiver) OVERRIDE;
45 virtual void AddNetworkStatusReceiver(
46 invalidation::NetworkStatusCallback* network_status_receiver) OVERRIDE;
47 virtual void SetSystemResources(
48 invalidation::SystemResources* resources) OVERRIDE;
50 // notifier::PushClient::Observer implementation.
51 virtual void OnNotificationsEnabled() OVERRIDE;
52 virtual void OnNotificationsDisabled(
53 notifier::NotificationsDisabledReason reason) OVERRIDE;
54 virtual void OnIncomingNotification(
55 const notifier::Notification& notification) OVERRIDE;
57 const std::string& GetServiceContextForTest() const;
59 int64 GetSchedulingHashForTest() const;
61 static notifier::Notification EncodeMessageForTest(
62 const std::string& message,
63 const std::string& service_context,
64 int64 scheduling_hash);
66 static bool DecodeMessageForTest(
67 const notifier::Notification& notification,
69 std::string* service_context,
70 int64* scheduling_hash);
73 typedef std::vector<invalidation::NetworkStatusCallback*>
74 NetworkStatusReceiverList;
76 static notifier::Notification EncodeMessage(
77 const std::string& message,
78 const std::string& service_context,
79 int64 scheduling_hash);
81 static bool DecodeMessage(
82 const notifier::Notification& notification,
84 std::string* service_context,
85 int64* scheduling_hash);
87 scoped_ptr<notifier::PushClient> push_client_;
88 scoped_ptr<invalidation::MessageCallback> incoming_receiver_;
89 NetworkStatusReceiverList network_status_receivers_;
91 bool notifications_enabled_;
94 std::string service_context_;
97 int64 scheduling_hash_;
99 DISALLOW_COPY_AND_ASSIGN(PushClientChannel);
102 } // namespace syncer
104 #endif // SYNC_NOTIFIER_PUSH_CLIENT_CHANNEL_H_