• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   virtual ~InvalidationNotifier();
54 
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
65       OVERRIDE;
66 
67   // SyncInvalidationListener::Delegate implementation.
68   virtual void OnInvalidate(
69       const ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
70   virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE;
71 
72  private:
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.
77   enum State {
78     STOPPED,
79     CONNECTING,
80     STARTED
81   };
82   State state_;
83 
84   InvalidatorRegistrar registrar_;
85 
86   // Passed to |invalidation_listener_|.
87   const UnackedInvalidationsMap saved_invalidations_;
88 
89   // Passed to |invalidation_listener_|.
90   const base::WeakPtr<InvalidationStateTracker> invalidation_state_tracker_;
91   scoped_refptr<base::SequencedTaskRunner>
92       invalidation_state_tracker_task_runner_;
93 
94   // Passed to |invalidation_listener_|.
95   const std::string client_info_;
96 
97   // The client ID to pass to |invalidation_listener_|.
98   const std::string invalidator_client_id_;
99 
100   // The initial bootstrap data to pass to |invalidation_listener_|.
101   const std::string invalidation_bootstrap_data_;
102 
103   // The invalidation listener.
104   SyncInvalidationListener invalidation_listener_;
105 
106   DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier);
107 };
108 
109 }  // namespace syncer
110 
111 #endif  // COMPONENTS_INVALIDATION_INVALIDATION_NOTIFIER_H_
112