Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: chrome/browser/sync/notifier/cache_invalidation_packet_handler.h

Issue 9190029: use push messaging in cache invalidation xmpp channel (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Class that handles the details of sending and receiving client 5 // Class that handles the details of sending and receiving client
6 // invalidation packets. 6 // invalidation packets.
7 7
8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_ 8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_
9 #define CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_ 9 #define CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_
10 #pragma once 10 #pragma once
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/threading/non_thread_safe.h" 18 #include "base/threading/non_thread_safe.h"
19 #include "google/cacheinvalidation/v2/system-resources.h" 19 #include "google/cacheinvalidation/v2/system-resources.h"
20 #include "jingle/notifier/listener/push_notifications_listen_task.h"
21 #include "jingle/notifier/listener/push_notifications_subscribe_task.h"
20 22
21 namespace buzz { 23 namespace buzz {
22 class XmppTaskParentInterface; 24 class XmppTaskParentInterface;
23 } // namespace buzz 25 } // namespace buzz
24 26
25 namespace sync_notifier { 27 namespace sync_notifier {
26 28
27 class CacheInvalidationPacketHandler { 29 class CacheInvalidationPacketHandler
30 : public notifier::PushNotificationsSubscribeTaskDelegate,
31 public notifier::PushNotificationsListenTaskDelegate {
28 public: 32 public:
29 // Starts routing packets from |invalidation_client| using 33 // Starts routing packets from |invalidation_client| using
30 // |base_task|. |base_task.get()| must still be non-NULL. 34 // |base_task|. |base_task.get()| must still be non-NULL.
31 // |invalidation_client| must not already be routing packets through 35 // |invalidation_client| must not already be routing packets through
32 // something. Does not take ownership of |invalidation_client|. 36 // something. Does not take ownership of |invalidation_client|.
33 CacheInvalidationPacketHandler( 37 CacheInvalidationPacketHandler(
34 base::WeakPtr<buzz::XmppTaskParentInterface> base_task); 38 base::WeakPtr<buzz::XmppTaskParentInterface> base_task);
35 39
36 // Makes the invalidation client passed into the constructor not 40 // Makes the invalidation client passed into the constructor not
37 // route packets through the XMPP client passed into the constructor 41 // route packets through the XMPP client passed into the constructor
38 // anymore. 42 // anymore.
39 virtual ~CacheInvalidationPacketHandler(); 43 virtual ~CacheInvalidationPacketHandler();
40 44
41 // If |base_task| is non-NULL, sends the outgoing message. 45 // If |base_task| is non-NULL, sends the outgoing message.
42 virtual void SendMessage(const std::string& outgoing_message); 46 virtual void SendMessage(const std::string& outgoing_message);
43 47
44 virtual void SetMessageReceiver( 48 virtual void SetMessageReceiver(
45 invalidation::MessageCallback* incoming_receiver); 49 invalidation::MessageCallback* incoming_receiver);
46 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
47 private: 62 private:
48 FRIEND_TEST_ALL_PREFIXES(CacheInvalidationPacketHandlerTest, Basic); 63 FRIEND_TEST_ALL_PREFIXES(CacheInvalidationPacketHandlerTest, Basic);
49 64
50 void HandleInboundPacket(const std::string& packet);
51 void HandleChannelContextChange(const std::string& context);
52
53 base::NonThreadSafe non_thread_safe_; 65 base::NonThreadSafe non_thread_safe_;
54 base::WeakPtrFactory<CacheInvalidationPacketHandler> weak_factory_; 66 base::WeakPtrFactory<CacheInvalidationPacketHandler> weak_factory_;
55 67
56 base::WeakPtr<buzz::XmppTaskParentInterface> base_task_; 68 base::WeakPtr<buzz::XmppTaskParentInterface> base_task_;
57 69
58 scoped_ptr<invalidation::MessageCallback> incoming_receiver_; 70 scoped_ptr<invalidation::MessageCallback> incoming_receiver_;
59 71
60 // Parameters for sent messages. 72 // Parameters for sent messages.
61 73
62 // Monotonically increasing sequence number. 74 // Monotonically increasing sequence number.
63 int seq_; 75 int seq_;
64 // Unique session token. 76 // Service context.
65 const std::string sid_; 77 std::string service_context_;
66 // Channel context. 78 // Scheduling hash.
67 std::string channel_context_; 79 int64 scheduling_hash_;
68 80
69 DISALLOW_COPY_AND_ASSIGN(CacheInvalidationPacketHandler); 81 DISALLOW_COPY_AND_ASSIGN(CacheInvalidationPacketHandler);
70 }; 82 };
71 83
72 } // namespace sync_notifier 84 } // namespace sync_notifier
73 85
74 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_ 86 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698