Home | History | Annotate | Download | only in push_messaging
      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 #ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_INVALIDATION_HANDLER_H_
      6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_INVALIDATION_HANDLER_H_
      7 
      8 #include <map>
      9 #include <set>
     10 #include <string>
     11 
     12 #include "base/basictypes.h"
     13 #include "base/compiler_specific.h"
     14 #include "base/threading/thread_checker.h"
     15 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_mapper.h"
     16 #include "components/invalidation/invalidation_handler.h"
     17 #include "components/invalidation/invalidation_util.h"
     18 
     19 namespace invalidation {
     20 class InvalidationService;
     21 }
     22 
     23 namespace extensions {
     24 
     25 class PushMessagingInvalidationHandlerDelegate;
     26 
     27 // This class maps extension IDs to the corresponding object IDs, manages
     28 // invalidation registrations, and dispatches callbacks for any invalidations
     29 // received.
     30 class PushMessagingInvalidationHandler : public PushMessagingInvalidationMapper,
     31                                          public syncer::InvalidationHandler {
     32  public:
     33   // |service| and |delegate| must remain valid for the lifetime of this object.
     34   // |extension_ids| is the set of extension IDs for which push messaging is
     35   // enabled.
     36   PushMessagingInvalidationHandler(
     37       invalidation::InvalidationService* service,
     38       PushMessagingInvalidationHandlerDelegate* delegate);
     39   virtual ~PushMessagingInvalidationHandler();
     40 
     41   // PushMessagingInvalidationMapper implementation.
     42   virtual void SuppressInitialInvalidationsForExtension(
     43       const std::string& extension_id) OVERRIDE;
     44   virtual void RegisterExtension(const std::string& extension_id) OVERRIDE;
     45   virtual void UnregisterExtension(const std::string& extension_id) OVERRIDE;
     46 
     47   // InvalidationHandler implementation.
     48   virtual void OnInvalidatorStateChange(
     49       syncer::InvalidatorState state) OVERRIDE;
     50   virtual void OnIncomingInvalidation(
     51       const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
     52   virtual std::string GetOwnerName() const OVERRIDE;
     53 
     54   const std::set<std::string>& GetRegisteredExtensionsForTest() const {
     55     return registered_extensions_;
     56   }
     57 
     58  private:
     59   void UpdateRegistrations();
     60 
     61   base::ThreadChecker thread_checker_;
     62   invalidation::InvalidationService* const service_;
     63   std::set<std::string> registered_extensions_;
     64   syncer::ObjectIdSet suppressed_ids_;
     65   PushMessagingInvalidationHandlerDelegate* const delegate_;
     66   std::map<invalidation::ObjectId,
     67            int64,
     68            syncer::ObjectIdLessThan> max_object_version_map_;
     69 
     70   DISALLOW_COPY_AND_ASSIGN(PushMessagingInvalidationHandler);
     71 };
     72 
     73 }  // namespace extensions
     74 
     75 #endif  // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_INVALIDATION_HANDLER_H_
     76