| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 Invalidator that wraps an invalidation | |
| 6 // client. Handles the details of connecting to XMPP and hooking it | |
| 7 // up to the invalidation client. | |
| 8 // | |
| 9 // You probably don't want to use this directly; use | |
| 10 // NonBlockingInvalidator. | |
| 11 | |
| 12 #ifndef COMPONENTS_INVALIDATION_INVALIDATION_NOTIFIER_H_ | |
| 13 #define COMPONENTS_INVALIDATION_INVALIDATION_NOTIFIER_H_ | |
| 14 | |
| 15 #include <string> | |
| 16 | |
| 17 #include "base/basictypes.h" | |
| 18 #include "base/compiler_specific.h" | |
| 19 #include "base/memory/ref_counted.h" | |
| 20 #include "base/memory/scoped_ptr.h" | |
| 21 #include "base/memory/weak_ptr.h" | |
| 22 #include "base/sequenced_task_runner.h" | |
| 23 #include "base/threading/non_thread_safe.h" | |
| 24 #include "components/invalidation/invalidation_export.h" | |
| 25 #include "components/invalidation/invalidation_state_tracker.h" | |
| 26 #include "components/invalidation/invalidator.h" | |
| 27 #include "components/invalidation/invalidator_registrar.h" | |
| 28 #include "components/invalidation/sync_invalidation_listener.h" | |
| 29 | |
| 30 namespace notifier { | |
| 31 class PushClient; | |
| 32 } // namespace notifier | |
| 33 | |
| 34 namespace syncer { | |
| 35 | |
| 36 // This class must live on the IO thread. | |
| 37 class INVALIDATION_EXPORT_PRIVATE InvalidationNotifier | |
| 38 : public Invalidator, | |
| 39 public SyncInvalidationListener::Delegate, | |
| 40 public base::NonThreadSafe { | |
| 41 public: | |
| 42 // |invalidation_state_tracker| must be initialized. | |
| 43 InvalidationNotifier( | |
| 44 scoped_ptr<SyncNetworkChannel> network_channel, | |
| 45 const std::string& invalidator_client_id, | |
| 46 const UnackedInvalidationsMap& saved_invalidations, | |
| 47 const std::string& invalidation_bootstrap_data, | |
| 48 const base::WeakPtr<InvalidationStateTracker>& invalidation_state_tracker, | |
| 49 scoped_refptr<base::SingleThreadTaskRunner> | |
| 50 invalidation_state_tracker_task_runner, | |
| 51 const std::string& client_info); | |
| 52 | |
| 53 ~InvalidationNotifier() override; | |
| 54 | |
| 55 // Invalidator implementation. | |
| 56 void RegisterHandler(InvalidationHandler* handler) override; | |
| 57 bool UpdateRegisteredIds(InvalidationHandler* handler, | |
| 58 const ObjectIdSet& ids) override; | |
| 59 void UnregisterHandler(InvalidationHandler* handler) override; | |
| 60 InvalidatorState GetInvalidatorState() const override; | |
| 61 void UpdateCredentials(const std::string& email, | |
| 62 const std::string& token) override; | |
| 63 void RequestDetailedStatus(base::Callback<void(const base::DictionaryValue&)> | |
| 64 callback) const override; | |
| 65 | |
| 66 // SyncInvalidationListener::Delegate implementation. | |
| 67 void OnInvalidate(const ObjectIdInvalidationMap& invalidation_map) override; | |
| 68 void OnInvalidatorStateChange(InvalidatorState state) override; | |
| 69 | |
| 70 private: | |
| 71 // We start off in the STOPPED state. When we get our initial | |
| 72 // credentials, we connect and move to the CONNECTING state. When | |
| 73 // we're connected we start the invalidation client and move to the | |
| 74 // STARTED state. We never go back to a previous state. | |
| 75 enum State { | |
| 76 STOPPED, | |
| 77 CONNECTING, | |
| 78 STARTED | |
| 79 }; | |
| 80 State state_; | |
| 81 | |
| 82 InvalidatorRegistrar registrar_; | |
| 83 | |
| 84 // Passed to |invalidation_listener_|. | |
| 85 const UnackedInvalidationsMap saved_invalidations_; | |
| 86 | |
| 87 // Passed to |invalidation_listener_|. | |
| 88 const base::WeakPtr<InvalidationStateTracker> invalidation_state_tracker_; | |
| 89 scoped_refptr<base::SequencedTaskRunner> | |
| 90 invalidation_state_tracker_task_runner_; | |
| 91 | |
| 92 // Passed to |invalidation_listener_|. | |
| 93 const std::string client_info_; | |
| 94 | |
| 95 // The client ID to pass to |invalidation_listener_|. | |
| 96 const std::string invalidator_client_id_; | |
| 97 | |
| 98 // The initial bootstrap data to pass to |invalidation_listener_|. | |
| 99 const std::string invalidation_bootstrap_data_; | |
| 100 | |
| 101 // The invalidation listener. | |
| 102 SyncInvalidationListener invalidation_listener_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); | |
| 105 }; | |
| 106 | |
| 107 } // namespace syncer | |
| 108 | |
| 109 #endif // COMPONENTS_INVALIDATION_INVALIDATION_NOTIFIER_H_ | |
| OLD | NEW |