Home | History | Annotate | Download | only in notifier
      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
      3 // found in the LICENSE file.
      4 //
      5 // Class that handles the details of sending and receiving client
      6 // invalidation packets.
      7 
      8 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_
      9 #define CHROME_BROWSER_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_callback_factory.h"
     17 #include "base/memory/weak_ptr.h"
     18 #include "base/threading/non_thread_safe.h"
     19 
     20 namespace invalidation {
     21 class InvalidationClient;
     22 class NetworkEndpoint;
     23 }  // namespace invalidation
     24 
     25 namespace talk_base {
     26 class Task;
     27 }  // namespace
     28 
     29 namespace sync_notifier {
     30 
     31 class CacheInvalidationPacketHandler {
     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<talk_base::Task> base_task,
     39       invalidation::InvalidationClient* invalidation_client);
     40 
     41   // Makes the invalidation client passed into the constructor not
     42   // route packets through the XMPP client passed into the constructor
     43   // anymore.
     44   ~CacheInvalidationPacketHandler();
     45 
     46   // If |base_task| is non-NULL, sends any existing pending outbound
     47   // packets.
     48   void HandleOutboundPacket(invalidation::NetworkEndpoint* network_endpoint);
     49 
     50  private:
     51   FRIEND_TEST(CacheInvalidationPacketHandlerTest, Basic);
     52 
     53   void HandleInboundPacket(const std::string& packet);
     54 
     55   base::NonThreadSafe non_thread_safe_;
     56   base::ScopedCallbackFactory<CacheInvalidationPacketHandler>
     57       scoped_callback_factory_;
     58 
     59   base::WeakPtr<talk_base::Task> base_task_;
     60   invalidation::InvalidationClient* invalidation_client_;
     61 
     62   // Parameters for sent messages.
     63 
     64   // Monotonically increasing sequence number.
     65   int seq_;
     66   // Unique session token.
     67   const std::string sid_;
     68 
     69   DISALLOW_COPY_AND_ASSIGN(CacheInvalidationPacketHandler);
     70 };
     71 
     72 }  // namespace sync_notifier
     73 
     74 #endif  // CHROME_BROWSER_SYNC_NOTIFIER_CACHE_INVALIDATION_PACKET_HANDLER_H_
     75