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.
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.
9 // You probably don't want to use this directly; use
10 // NonBlockingInvalidator.
12 #ifndef COMPONENTS_INVALIDATION_IMPL_INVALIDATION_NOTIFIER_H_
13 #define COMPONENTS_INVALIDATION_IMPL_INVALIDATION_NOTIFIER_H_
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/impl/invalidation_state_tracker.h"
25 #include "components/invalidation/impl/invalidator.h"
26 #include "components/invalidation/impl/invalidator_registrar.h"
27 #include "components/invalidation/impl/sync_invalidation_listener.h"
28 #include "components/invalidation/public/invalidation_export.h"
32 } // namespace notifier
36 // This class must live on the IO thread.
37 class INVALIDATION_EXPORT_PRIVATE InvalidationNotifier
39 public SyncInvalidationListener::Delegate
,
40 public base::NonThreadSafe
{
42 // |invalidation_state_tracker| must be initialized.
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
);
53 ~InvalidationNotifier() override
;
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
;
66 // SyncInvalidationListener::Delegate implementation.
67 void OnInvalidate(const ObjectIdInvalidationMap
& invalidation_map
) override
;
68 void OnInvalidatorStateChange(InvalidatorState state
) override
;
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.
82 InvalidatorRegistrar registrar_
;
84 // Passed to |invalidation_listener_|.
85 const UnackedInvalidationsMap saved_invalidations_
;
87 // Passed to |invalidation_listener_|.
88 const base::WeakPtr
<InvalidationStateTracker
> invalidation_state_tracker_
;
89 scoped_refptr
<base::SequencedTaskRunner
>
90 invalidation_state_tracker_task_runner_
;
92 // Passed to |invalidation_listener_|.
93 const std::string client_info_
;
95 // The client ID to pass to |invalidation_listener_|.
96 const std::string invalidator_client_id_
;
98 // The initial bootstrap data to pass to |invalidation_listener_|.
99 const std::string invalidation_bootstrap_data_
;
101 // The invalidation listener.
102 SyncInvalidationListener invalidation_listener_
;
104 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier
);
107 } // namespace syncer
109 #endif // COMPONENTS_INVALIDATION_IMPL_INVALIDATION_NOTIFIER_H_