roll skia to 4057
[chromium-blink-merge.git] / sync / notifier / cache_invalidation_packet_handler.h
blob655933d13696cda7865139c944c960c1cb2ed0f8
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.
8 #ifndef SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_
9 #define SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_
10 #pragma once
12 #include <string>
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"
23 namespace buzz {
24 class XmppTaskParentInterface;
25 } // namespace buzz
27 namespace sync_notifier {
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);
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();
45 // If |base_task| is non-NULL, sends the outgoing message.
46 virtual void SendMessage(const std::string& outgoing_message);
48 virtual void SetMessageReceiver(
49 invalidation::MessageCallback* incoming_receiver);
51 // Sends a message requesting a subscription to the notification channel.
52 virtual void SendSubscriptionRequest();
54 // PushNotificationsSubscribeTaskDelegate implementation.
55 virtual void OnSubscribed() OVERRIDE;
56 virtual void OnSubscriptionError() OVERRIDE;
58 // PushNotificationsListenTaskDelegate implementation.
59 virtual void OnNotificationReceived(
60 const notifier::Notification& notification) OVERRIDE;
62 private:
63 FRIEND_TEST_ALL_PREFIXES(CacheInvalidationPacketHandlerTest, Basic);
65 base::NonThreadSafe non_thread_safe_;
66 base::WeakPtrFactory<CacheInvalidationPacketHandler> weak_factory_;
68 base::WeakPtr<buzz::XmppTaskParentInterface> base_task_;
70 scoped_ptr<invalidation::MessageCallback> incoming_receiver_;
72 // Parameters for sent messages.
74 // Monotonically increasing sequence number.
75 int seq_;
76 // Service context.
77 std::string service_context_;
78 // Scheduling hash.
79 int64 scheduling_hash_;
81 DISALLOW_COPY_AND_ASSIGN(CacheInvalidationPacketHandler);
84 } // namespace sync_notifier
86 #endif // SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_