OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // An implementation of Invalidator that wraps an invalidation | 5 // An implementation of Invalidator that wraps an invalidation |
6 // client. Handles the details of connecting to XMPP and hooking it | 6 // client. Handles the details of connecting to XMPP and hooking it |
7 // up to the invalidation client. | 7 // up to the invalidation client. |
8 // | 8 // |
9 // You probably don't want to use this directly; use | 9 // You probably don't want to use this directly; use |
10 // NonBlockingInvalidationNotifier. | 10 // NonBlockingInvalidationNotifier. |
11 | 11 |
12 #ifndef SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ | 12 #ifndef SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ |
13 #define SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ | 13 #define SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/threading/non_thread_safe.h" | 20 #include "base/threading/non_thread_safe.h" |
21 #include "sync/internal_api/public/base/model_type.h" | 21 #include "sync/internal_api/public/base/model_type.h" |
22 #include "sync/internal_api/public/util/weak_handle.h" | 22 #include "sync/internal_api/public/util/weak_handle.h" |
23 #include "sync/notifier/chrome_invalidation_client.h" | |
24 #include "sync/notifier/invalidation_state_tracker.h" | 23 #include "sync/notifier/invalidation_state_tracker.h" |
25 #include "sync/notifier/invalidator.h" | 24 #include "sync/notifier/invalidator.h" |
26 #include "sync/notifier/invalidator_registrar.h" | 25 #include "sync/notifier/invalidator_registrar.h" |
| 26 #include "sync/notifier/sync_invalidation_listener.h" |
27 | 27 |
28 namespace notifier { | 28 namespace notifier { |
29 class PushClient; | 29 class PushClient; |
30 } // namespace notifier | 30 } // namespace notifier |
31 | 31 |
32 namespace syncer { | 32 namespace syncer { |
33 | 33 |
34 // This class must live on the IO thread. | 34 // This class must live on the IO thread. |
35 // TODO(dcheng): Think of a name better than InvalidationInvalidator. | 35 // TODO(dcheng): Think of a name better than InvalidationInvalidator. |
36 class InvalidationNotifier | 36 class InvalidationNotifier |
37 : public Invalidator, | 37 : public Invalidator, |
38 public ChromeInvalidationClient::Listener, | 38 public SyncInvalidationListener::Delegate, |
39 public base::NonThreadSafe { | 39 public base::NonThreadSafe { |
40 public: | 40 public: |
41 // |invalidation_state_tracker| must be initialized. | 41 // |invalidation_state_tracker| must be initialized. |
42 InvalidationNotifier( | 42 InvalidationNotifier( |
43 scoped_ptr<notifier::PushClient> push_client, | 43 scoped_ptr<notifier::PushClient> push_client, |
44 const InvalidationVersionMap& initial_max_invalidation_versions, | 44 const InvalidationVersionMap& initial_max_invalidation_versions, |
45 const std::string& initial_invalidation_state, | 45 const std::string& initial_invalidation_state, |
46 const WeakHandle<InvalidationStateTracker>& | 46 const WeakHandle<InvalidationStateTracker>& |
47 invalidation_state_tracker, | 47 invalidation_state_tracker, |
48 const std::string& client_info); | 48 const std::string& client_info); |
49 | 49 |
50 virtual ~InvalidationNotifier(); | 50 virtual ~InvalidationNotifier(); |
51 | 51 |
52 // Invalidator implementation. | 52 // Invalidator implementation. |
53 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; | 53 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; |
54 virtual void UpdateRegisteredIds(InvalidationHandler* handler, | 54 virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
55 const ObjectIdSet& ids) OVERRIDE; | 55 const ObjectIdSet& ids) OVERRIDE; |
56 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; | 56 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; |
57 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 57 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
58 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 58 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
59 virtual void UpdateCredentials( | 59 virtual void UpdateCredentials( |
60 const std::string& email, const std::string& token) OVERRIDE; | 60 const std::string& email, const std::string& token) OVERRIDE; |
61 virtual void SendNotification(const ObjectIdStateMap& id_state_map) OVERRIDE; | 61 virtual void SendNotification(const ObjectIdStateMap& id_state_map) OVERRIDE; |
62 | 62 |
63 // ChromeInvalidationClient::Listener implementation. | 63 // SyncInvalidationListener::Delegate implementation. |
64 virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) OVERRIDE; | 64 virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) OVERRIDE; |
65 virtual void OnNotificationsEnabled() OVERRIDE; | 65 virtual void OnNotificationsEnabled() OVERRIDE; |
66 virtual void OnNotificationsDisabled( | 66 virtual void OnNotificationsDisabled( |
67 NotificationsDisabledReason reason) OVERRIDE; | 67 NotificationsDisabledReason reason) OVERRIDE; |
68 | 68 |
69 private: | 69 private: |
70 // We start off in the STOPPED state. When we get our initial | 70 // We start off in the STOPPED state. When we get our initial |
71 // credentials, we connect and move to the CONNECTING state. When | 71 // credentials, we connect and move to the CONNECTING state. When |
72 // we're connected we start the invalidation client and move to the | 72 // we're connected we start the invalidation client and move to the |
73 // STARTED state. We never go back to a previous state. | 73 // STARTED state. We never go back to a previous state. |
74 enum State { | 74 enum State { |
75 STOPPED, | 75 STOPPED, |
76 CONNECTING, | 76 CONNECTING, |
77 STARTED | 77 STARTED |
78 }; | 78 }; |
79 State state_; | 79 State state_; |
80 | 80 |
81 InvalidatorRegistrar registrar_; | 81 InvalidatorRegistrar registrar_; |
82 | 82 |
83 // Passed to |invalidation_client_|. | 83 // Passed to |invalidation_listener_|. |
84 const InvalidationVersionMap initial_max_invalidation_versions_; | 84 const InvalidationVersionMap initial_max_invalidation_versions_; |
85 | 85 |
86 // Passed to |invalidation_client_|. | 86 // Passed to |invalidation_listener_|. |
87 const WeakHandle<InvalidationStateTracker> | 87 const WeakHandle<InvalidationStateTracker> |
88 invalidation_state_tracker_; | 88 invalidation_state_tracker_; |
89 | 89 |
90 // Passed to |invalidation_client_|. | 90 // Passed to |invalidation_listener_|. |
91 const std::string client_info_; | 91 const std::string client_info_; |
92 | 92 |
93 // The client ID to pass to |chrome_invalidation_client_|. | 93 // The client ID to pass to |invalidation_listener_|. |
94 std::string invalidation_client_id_; | 94 std::string client_id_; |
95 | 95 |
96 // The state to pass to |chrome_invalidation_client_|. | 96 // The state to pass to |invalidation_listener_|. |
97 // TODO(tim): This should be made const once migration is completed for bug | 97 // TODO(tim): This should be made const once migration is completed for bug |
98 // 124140. | 98 // 124140. |
99 std::string invalidation_state_; | 99 std::string invalidation_state_; |
100 | 100 |
101 // The invalidation client. | 101 // The invalidation listener. |
102 ChromeInvalidationClient invalidation_client_; | 102 SyncInvalidationListener invalidation_listener_; |
103 | 103 |
104 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); | 104 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); |
105 }; | 105 }; |
106 | 106 |
107 } // namespace syncer | 107 } // namespace syncer |
108 | 108 |
109 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ | 109 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ |
OLD | NEW |