1 // Copyright 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 // An implementation of SyncNotifier that wraps InvalidationNotifier 6 // on its own thread. 7 8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ 9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ 10 11 #include <string> 12 13 #include "base/basictypes.h" 14 #include "base/compiler_specific.h" 15 #include "base/memory/ref_counted.h" 16 #include "base/memory/weak_ptr.h" 17 #include "jingle/notifier/base/notifier_options.h" 18 #include "sync/base/sync_export.h" 19 #include "sync/internal_api/public/util/weak_handle.h" 20 #include "sync/notifier/invalidation_handler.h" 21 #include "sync/notifier/invalidation_state_tracker.h" 22 #include "sync/notifier/invalidator.h" 23 #include "sync/notifier/invalidator_registrar.h" 24 25 namespace base { 26 class SingleThreadTaskRunner; 27 } // namespace base 28 29 namespace syncer { 30 31 class SYNC_EXPORT_PRIVATE NonBlockingInvalidator 32 : public Invalidator, 33 // InvalidationHandler to "observe" our Core via WeakHandle. 34 public InvalidationHandler { 35 public: 36 // |invalidation_state_tracker| must be initialized. 37 NonBlockingInvalidator( 38 const notifier::NotifierOptions& notifier_options, 39 const std::string& invalidator_client_id, 40 const UnackedInvalidationsMap& saved_invalidations, 41 const std::string& invalidation_bootstrap_data, 42 const WeakHandle<InvalidationStateTracker>& 43 invalidation_state_tracker, 44 const std::string& client_info); 45 46 virtual ~NonBlockingInvalidator(); 47 48 // Invalidator implementation. 49 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; 50 virtual void UpdateRegisteredIds(InvalidationHandler* handler, 51 const ObjectIdSet& ids) OVERRIDE; 52 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; 53 virtual InvalidatorState GetInvalidatorState() const OVERRIDE; 54 virtual void UpdateCredentials( 55 const std::string& email, const std::string& token) OVERRIDE; 56 57 // InvalidationHandler implementation. 58 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; 59 virtual void OnIncomingInvalidation( 60 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; 61 62 private: 63 class Core; 64 65 InvalidatorRegistrar registrar_; 66 67 // The real guts of NonBlockingInvalidator, which allows this class to live 68 // completely on the parent thread. 69 scoped_refptr<Core> core_; 70 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; 71 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 72 73 base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_; 74 75 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator); 76 }; 77 78 } // namespace syncer 79 80 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ 81