| OLD | NEW |
| (Empty) |
| 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 // An implementation of SyncNotifier that wraps InvalidationNotifier | |
| 6 // on its own thread. | |
| 7 | |
| 8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | |
| 9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_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/internal_api/public/util/weak_handle.h" | |
| 19 #include "sync/notifier/invalidation_state_tracker.h" | |
| 20 #include "sync/notifier/sync_notifier.h" | |
| 21 #include "sync/notifier/sync_notifier_observer.h" | |
| 22 #include "sync/notifier/sync_notifier_registrar.h" | |
| 23 | |
| 24 namespace base { | |
| 25 class SingleThreadTaskRunner; | |
| 26 } // namespace base | |
| 27 | |
| 28 namespace syncer { | |
| 29 | |
| 30 // TODO(akalin): Generalize to NonBlockingSyncNotifier | |
| 31 // (http://crbug.com/140409). | |
| 32 class NonBlockingInvalidationNotifier | |
| 33 : public SyncNotifier, | |
| 34 // SyncNotifierObserver to "observe" our Core via WeakHandle. | |
| 35 public SyncNotifierObserver { | |
| 36 public: | |
| 37 // |invalidation_state_tracker| must be initialized. | |
| 38 NonBlockingInvalidationNotifier( | |
| 39 const notifier::NotifierOptions& notifier_options, | |
| 40 const InvalidationVersionMap& initial_max_invalidation_versions, | |
| 41 const std::string& initial_invalidation_state, | |
| 42 const WeakHandle<InvalidationStateTracker>& | |
| 43 invalidation_state_tracker, | |
| 44 const std::string& client_info); | |
| 45 | |
| 46 virtual ~NonBlockingInvalidationNotifier(); | |
| 47 | |
| 48 // SyncNotifier implementation. | |
| 49 virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; | |
| 50 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, | |
| 51 const ObjectIdSet& ids) OVERRIDE; | |
| 52 virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; | |
| 53 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | |
| 54 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | |
| 55 virtual void UpdateCredentials( | |
| 56 const std::string& email, const std::string& token) OVERRIDE; | |
| 57 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; | |
| 58 | |
| 59 // SyncNotifierObserver implementation. | |
| 60 virtual void OnNotificationsEnabled() OVERRIDE; | |
| 61 virtual void OnNotificationsDisabled( | |
| 62 NotificationsDisabledReason reason) OVERRIDE; | |
| 63 virtual void OnIncomingNotification( | |
| 64 const ObjectIdStateMap& id_state_map, | |
| 65 IncomingNotificationSource source) OVERRIDE; | |
| 66 | |
| 67 private: | |
| 68 class Core; | |
| 69 | |
| 70 base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_; | |
| 71 | |
| 72 SyncNotifierRegistrar registrar_; | |
| 73 | |
| 74 // The real guts of NonBlockingInvalidationNotifier, which allows | |
| 75 // this class to live completely on the parent thread. | |
| 76 scoped_refptr<Core> core_; | |
| 77 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; | |
| 78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier); | |
| 81 }; | |
| 82 | |
| 83 } // namespace syncer | |
| 84 | |
| 85 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_ | |
| OLD | NEW |