OLD | NEW |
---|---|
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::PushNotificationsListenTaskDelegate, | |
31 public notifier::PushNotificationsSubscribeTaskDelegate { | |
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 |
akalin
2012/01/12 23:06:44
The Chrome style is:
// FooInterface implementati
ghc
2012/01/13 01:23:07
Done.
| |
51 // Sends a message requesting a subscription to the notification channel. | |
52 virtual void SendSubscriptionRequest(); | |
53 | |
54 // Called by subscription task to indicate subscription succeeded. | |
55 virtual void OnSubscribed(); | |
56 | |
57 // Called by subscription task to indicate subscription failed. | |
58 virtual void OnSubscriptionError(); | |
59 | |
60 // Handles an inbound notification. | |
61 virtual void OnNotificationReceived( | |
62 const notifier::Notification& notification); | |
63 | |
47 private: | 64 private: |
48 FRIEND_TEST_ALL_PREFIXES(CacheInvalidationPacketHandlerTest, Basic); | 65 FRIEND_TEST_ALL_PREFIXES(CacheInvalidationPacketHandlerTest, Basic); |
49 | 66 |
50 void HandleInboundPacket(const std::string& packet); | |
51 void HandleChannelContextChange(const std::string& context); | |
52 | |
53 base::NonThreadSafe non_thread_safe_; | 67 base::NonThreadSafe non_thread_safe_; |
54 base::WeakPtrFactory<CacheInvalidationPacketHandler> weak_factory_; | 68 base::WeakPtrFactory<CacheInvalidationPacketHandler> weak_factory_; |
55 | 69 |
56 base::WeakPtr<buzz::XmppTaskParentInterface> base_task_; | 70 base::WeakPtr<buzz::XmppTaskParentInterface> base_task_; |
57 | 71 |
58 scoped_ptr<invalidation::MessageCallback> incoming_receiver_; | 72 scoped_ptr<invalidation::MessageCallback> incoming_receiver_; |
59 | 73 |
60 // Parameters for sent messages. | 74 // Parameters for sent messages. |
61 | 75 |
62 // Monotonically increasing sequence number. | 76 // Monotonically increasing sequence number. |
63 int seq_; | 77 int seq_; |
64 // Unique session token. | 78 // Service context. |
65 const std::string sid_; | 79 std::string service_context_; |
66 // Channel context. | 80 // Scheduling hash. |
67 std::string channel_context_; | 81 int64 scheduling_hash_; |
68 | 82 |
69 DISALLOW_COPY_AND_ASSIGN(CacheInvalidationPacketHandler); | 83 DISALLOW_COPY_AND_ASSIGN(CacheInvalidationPacketHandler); |
70 }; | 84 }; |
71 | 85 |
72 } // namespace sync_notifier | 86 } // namespace sync_notifier |
73 | 87 |
74 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_ | 88 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_ |
OLD | NEW |