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_INVALIDATION_NOTIFIER_H_
13 #define COMPONENTS_INVALIDATION_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/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"
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 virtual ~InvalidationNotifier();
55 // Invalidator implementation.
56 virtual void RegisterHandler(InvalidationHandler
* handler
) OVERRIDE
;
57 virtual void UpdateRegisteredIds(InvalidationHandler
* handler
,
58 const ObjectIdSet
& ids
) OVERRIDE
;
59 virtual void UnregisterHandler(InvalidationHandler
* handler
) OVERRIDE
;
60 virtual InvalidatorState
GetInvalidatorState() const OVERRIDE
;
61 virtual void UpdateCredentials(
62 const std::string
& email
, const std::string
& token
) OVERRIDE
;
63 virtual void RequestDetailedStatus(
64 base::Callback
<void(const base::DictionaryValue
&)> callback
) const
67 // SyncInvalidationListener::Delegate implementation.
68 virtual void OnInvalidate(
69 const ObjectIdInvalidationMap
& invalidation_map
) OVERRIDE
;
70 virtual void OnInvalidatorStateChange(InvalidatorState state
) OVERRIDE
;
73 // We start off in the STOPPED state. When we get our initial
74 // credentials, we connect and move to the CONNECTING state. When
75 // we're connected we start the invalidation client and move to the
76 // STARTED state. We never go back to a previous state.
84 InvalidatorRegistrar registrar_
;
86 // Passed to |invalidation_listener_|.
87 const UnackedInvalidationsMap saved_invalidations_
;
89 // Passed to |invalidation_listener_|.
90 const base::WeakPtr
<InvalidationStateTracker
> invalidation_state_tracker_
;
91 scoped_refptr
<base::SequencedTaskRunner
>
92 invalidation_state_tracker_task_runner_
;
94 // Passed to |invalidation_listener_|.
95 const std::string client_info_
;
97 // The client ID to pass to |invalidation_listener_|.
98 const std::string invalidator_client_id_
;
100 // The initial bootstrap data to pass to |invalidation_listener_|.
101 const std::string invalidation_bootstrap_data_
;
103 // The invalidation listener.
104 SyncInvalidationListener invalidation_listener_
;
106 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier
);
109 } // namespace syncer
111 #endif // COMPONENTS_INVALIDATION_INVALIDATION_NOTIFIER_H_