| 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 // Class that handles the details of sending and receiving client | |
| 6 // invalidation packets. | |
| 7 | |
| 8 #ifndef SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_ | |
| 9 #define SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_ | |
| 10 #pragma once | |
| 11 | |
| 12 #include <string> | |
| 13 | |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/gtest_prod_util.h" | |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/memory/weak_ptr.h" | |
| 18 #include "base/threading/non_thread_safe.h" | |
| 19 #include "google/cacheinvalidation/include/system-resources.h" | |
| 20 #include "jingle/notifier/listener/push_notifications_listen_task.h" | |
| 21 #include "jingle/notifier/listener/push_notifications_subscribe_task.h" | |
| 22 | |
| 23 namespace buzz { | |
| 24 class XmppTaskParentInterface; | |
| 25 } // namespace buzz | |
| 26 | |
| 27 namespace sync_notifier { | |
| 28 | |
| 29 class CacheInvalidationPacketHandler | |
| 30 : public notifier::PushNotificationsSubscribeTaskDelegate, | |
| 31 public notifier::PushNotificationsListenTaskDelegate { | |
| 32 public: | |
| 33 // Starts routing packets from |invalidation_client| using | |
| 34 // |base_task|. |base_task.get()| must still be non-NULL. | |
| 35 // |invalidation_client| must not already be routing packets through | |
| 36 // something. Does not take ownership of |invalidation_client|. | |
| 37 CacheInvalidationPacketHandler( | |
| 38 base::WeakPtr<buzz::XmppTaskParentInterface> base_task); | |
| 39 | |
| 40 // Makes the invalidation client passed into the constructor not | |
| 41 // route packets through the XMPP client passed into the constructor | |
| 42 // anymore. | |
| 43 virtual ~CacheInvalidationPacketHandler(); | |
| 44 | |
| 45 // If |base_task| is non-NULL, sends the outgoing message. | |
| 46 virtual void SendMessage(const std::string& outgoing_message); | |
| 47 | |
| 48 virtual void SetMessageReceiver( | |
| 49 invalidation::MessageCallback* incoming_receiver); | |
| 50 | |
| 51 // Sends a message requesting a subscription to the notification channel. | |
| 52 virtual void SendSubscriptionRequest(); | |
| 53 | |
| 54 // PushNotificationsSubscribeTaskDelegate implementation. | |
| 55 virtual void OnSubscribed() OVERRIDE; | |
| 56 virtual void OnSubscriptionError() OVERRIDE; | |
| 57 | |
| 58 // PushNotificationsListenTaskDelegate implementation. | |
| 59 virtual void OnNotificationReceived( | |
| 60 const notifier::Notification& notification) OVERRIDE; | |
| 61 | |
| 62 private: | |
| 63 FRIEND_TEST_ALL_PREFIXES(CacheInvalidationPacketHandlerTest, Basic); | |
| 64 | |
| 65 base::NonThreadSafe non_thread_safe_; | |
| 66 base::WeakPtrFactory<CacheInvalidationPacketHandler> weak_factory_; | |
| 67 | |
| 68 base::WeakPtr<buzz::XmppTaskParentInterface> base_task_; | |
| 69 | |
| 70 scoped_ptr<invalidation::MessageCallback> incoming_receiver_; | |
| 71 | |
| 72 // Parameters for sent messages. | |
| 73 | |
| 74 // Monotonically increasing sequence number. | |
| 75 int seq_; | |
| 76 // Service context. | |
| 77 std::string service_context_; | |
| 78 // Scheduling hash. | |
| 79 int64 scheduling_hash_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(CacheInvalidationPacketHandler); | |
| 82 }; | |
| 83 | |
| 84 } // namespace sync_notifier | |
| 85 | |
| 86 #endif // SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_ | |
| OLD | NEW |