| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "google/cacheinvalidation/include/system-resources.h" |
| 16 #include "jingle/notifier/listener/push_client_observer.h" |
| 17 |
| 18 namespace notifier { |
| 19 class PushClient; |
| 20 } // namespace notifier |
| 21 |
| 22 namespace sync_notifier { |
| 23 |
| 24 // A PushClientChannel is an implementation of NetworkChannel that |
| 25 // routes messages through a PushClient. |
| 26 class PushClientChannel |
| 27 : public invalidation::NetworkChannel, |
| 28 public notifier::PushClientObserver { |
| 29 public: |
| 30 explicit PushClientChannel(scoped_ptr<notifier::PushClient> push_client); |
| 31 |
| 32 virtual ~PushClientChannel(); |
| 33 |
| 34 // If not connected, connects with the given credentials. If |
| 35 // already connected, the next connection attempt will use the given |
| 36 // credentials. |
| 37 void UpdateCredentials(const std::string& email, const std::string& token); |
| 38 |
| 39 // invalidation::NetworkChannel implementation. |
| 40 virtual void SendMessage(const std::string& outgoing_message) OVERRIDE; |
| 41 virtual void SetMessageReceiver( |
| 42 invalidation::MessageCallback* incoming_receiver) OVERRIDE; |
| 43 virtual void AddNetworkStatusReceiver( |
| 44 invalidation::NetworkStatusCallback* network_status_receiver) OVERRIDE; |
| 45 virtual void SetSystemResources( |
| 46 invalidation::SystemResources* resources) OVERRIDE; |
| 47 |
| 48 // notifier::PushClient::Observer implementation. |
| 49 virtual void OnNotificationStateChange(bool notifications_enabled) OVERRIDE; |
| 50 virtual void OnIncomingNotification( |
| 51 const notifier::Notification& notification) OVERRIDE; |
| 52 |
| 53 const std::string& GetServiceContextForTest() const; |
| 54 |
| 55 int64 GetSchedulingHashForTest() const; |
| 56 |
| 57 static notifier::Notification EncodeMessageForTest( |
| 58 const std::string& message, |
| 59 const std::string& service_context, |
| 60 int64 scheduling_hash); |
| 61 |
| 62 static bool DecodeMessageForTest( |
| 63 const notifier::Notification& notification, |
| 64 std::string* message, |
| 65 std::string* service_context, |
| 66 int64* scheduling_hash); |
| 67 |
| 68 private: |
| 69 typedef std::vector<invalidation::NetworkStatusCallback*> |
| 70 NetworkStatusReceiverList; |
| 71 |
| 72 static notifier::Notification EncodeMessage( |
| 73 const std::string& message, |
| 74 const std::string& service_context, |
| 75 int64 scheduling_hash); |
| 76 |
| 77 static bool DecodeMessage( |
| 78 const notifier::Notification& notification, |
| 79 std::string* message, |
| 80 std::string* service_context, |
| 81 int64* scheduling_hash); |
| 82 |
| 83 scoped_ptr<notifier::PushClient> push_client_; |
| 84 scoped_ptr<invalidation::MessageCallback> incoming_receiver_; |
| 85 NetworkStatusReceiverList network_status_receivers_; |
| 86 |
| 87 bool notifications_enabled_; |
| 88 |
| 89 // Service context. |
| 90 std::string service_context_; |
| 91 |
| 92 // Scheduling hash. |
| 93 int64 scheduling_hash_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(PushClientChannel); |
| 96 }; |
| 97 |
| 98 } // namespace sync_notifier |
| 99 |
| 100 #endif // SYNC_NOTIFIER_PUSH_CLIENT_CHANNEL_H_ |
| OLD | NEW |