• 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/scoped_ptr.h"
20 #include "base/threading/non_thread_safe.h"
21 #include "components/invalidation/invalidation_export.h"
22 #include "components/invalidation/invalidator_registrar.h"
23 #include "components/invalidation/sync_invalidation_listener.h"
24 #include "sync/internal_api/public/base/model_type.h"
25 #include "sync/internal_api/public/util/weak_handle.h"
26 #include "sync/notifier/invalidation_state_tracker.h"
27 #include "sync/notifier/invalidator.h"
28 
29 namespace notifier {
30 class PushClient;
31 }  // namespace notifier
32 
33 namespace syncer {
34 
35 // This class must live on the IO thread.
36 class INVALIDATION_EXPORT_PRIVATE InvalidationNotifier
37     : public Invalidator,
38       public SyncInvalidationListener::Delegate,
39       public base::NonThreadSafe {
40  public:
41   // |invalidation_state_tracker| must be initialized.
42   InvalidationNotifier(
43       scoped_ptr<SyncNetworkChannel> network_channel,
44       const std::string& invalidator_client_id,
45       const UnackedInvalidationsMap& saved_invalidations,
46       const std::string& invalidation_bootstrap_data,
47       const WeakHandle<InvalidationStateTracker>&
48           invalidation_state_tracker,
49       const std::string& client_info);
50 
51   virtual ~InvalidationNotifier();
52 
53   // Invalidator implementation.
54   virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE;
55   virtual void UpdateRegisteredIds(InvalidationHandler* handler,
56                                    const ObjectIdSet& ids) OVERRIDE;
57   virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE;
58   virtual InvalidatorState GetInvalidatorState() const OVERRIDE;
59   virtual void UpdateCredentials(
60       const std::string& email, const std::string& token) OVERRIDE;
61   virtual void RequestDetailedStatus(
62       base::Callback<void(const base::DictionaryValue&)> callback) const
63       OVERRIDE;
64 
65   // SyncInvalidationListener::Delegate implementation.
66   virtual void OnInvalidate(
67       const ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
68   virtual 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 WeakHandle<InvalidationStateTracker>
89       invalidation_state_tracker_;
90 
91   // Passed to |invalidation_listener_|.
92   const std::string client_info_;
93 
94   // The client ID to pass to |invalidation_listener_|.
95   const std::string invalidator_client_id_;
96 
97   // The initial bootstrap data to pass to |invalidation_listener_|.
98   const std::string invalidation_bootstrap_data_;
99 
100   // The invalidation listener.
101   SyncInvalidationListener invalidation_listener_;
102 
103   DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier);
104 };
105 
106 }  // namespace syncer
107 
108 #endif  // COMPONENTS_INVALIDATION_INVALIDATION_NOTIFIER_H_
109