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 SyncNotifier 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" | 23 #include "sync/notifier/chrome_invalidation_client.h" |
24 #include "sync/notifier/invalidation_state_tracker.h" | 24 #include "sync/notifier/invalidation_state_tracker.h" |
25 #include "sync/notifier/sync_notifier.h" | 25 #include "sync/notifier/invalidator.h" |
26 #include "sync/notifier/sync_notifier_registrar.h" | 26 #include "sync/notifier/invalidator_registrar.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. |
akalin
2012/08/27 22:38:31
add a TODO to figure out a better name for this cl
dcheng
2012/08/28 00:20:22
Done.
| |
35 class InvalidationNotifier | 35 class InvalidationNotifier |
36 : public SyncNotifier, | 36 : public Invalidator, |
37 public ChromeInvalidationClient::Listener, | 37 public ChromeInvalidationClient::Listener, |
38 public base::NonThreadSafe { | 38 public base::NonThreadSafe { |
39 public: | 39 public: |
40 // |invalidation_state_tracker| must be initialized. | 40 // |invalidation_state_tracker| must be initialized. |
41 InvalidationNotifier( | 41 InvalidationNotifier( |
42 scoped_ptr<notifier::PushClient> push_client, | 42 scoped_ptr<notifier::PushClient> push_client, |
43 const InvalidationVersionMap& initial_max_invalidation_versions, | 43 const InvalidationVersionMap& initial_max_invalidation_versions, |
44 const std::string& initial_invalidation_state, | 44 const std::string& initial_invalidation_state, |
45 const WeakHandle<InvalidationStateTracker>& | 45 const WeakHandle<InvalidationStateTracker>& |
46 invalidation_state_tracker, | 46 invalidation_state_tracker, |
47 const std::string& client_info); | 47 const std::string& client_info); |
48 | 48 |
49 virtual ~InvalidationNotifier(); | 49 virtual ~InvalidationNotifier(); |
50 | 50 |
51 // SyncNotifier implementation. | 51 // Invalidator implementation. |
52 virtual void RegisterHandler(SyncNotifierObserver* handler) OVERRIDE; | 52 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; |
53 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, | 53 virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
54 const ObjectIdSet& ids) OVERRIDE; | 54 const ObjectIdSet& ids) OVERRIDE; |
55 virtual void UnregisterHandler(SyncNotifierObserver* handler) OVERRIDE; | 55 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; |
56 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 56 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
57 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; | 57 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
58 virtual void UpdateCredentials( | 58 virtual void UpdateCredentials( |
59 const std::string& email, const std::string& token) OVERRIDE; | 59 const std::string& email, const std::string& token) OVERRIDE; |
60 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; | 60 virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; |
61 | 61 |
62 // ChromeInvalidationClient::Listener implementation. | 62 // ChromeInvalidationClient::Listener implementation. |
63 virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) OVERRIDE; | 63 virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) OVERRIDE; |
64 virtual void OnNotificationsEnabled() OVERRIDE; | 64 virtual void OnNotificationsEnabled() OVERRIDE; |
65 virtual void OnNotificationsDisabled( | 65 virtual void OnNotificationsDisabled( |
66 NotificationsDisabledReason reason) OVERRIDE; | 66 NotificationsDisabledReason reason) OVERRIDE; |
67 | 67 |
68 private: | 68 private: |
69 // We start off in the STOPPED state. When we get our initial | 69 // We start off in the STOPPED state. When we get our initial |
70 // credentials, we connect and move to the CONNECTING state. When | 70 // credentials, we connect and move to the CONNECTING state. When |
71 // we're connected we start the invalidation client and move to the | 71 // we're connected we start the invalidation client and move to the |
72 // STARTED state. We never go back to a previous state. | 72 // STARTED state. We never go back to a previous state. |
73 enum State { | 73 enum State { |
74 STOPPED, | 74 STOPPED, |
75 CONNECTING, | 75 CONNECTING, |
76 STARTED | 76 STARTED |
77 }; | 77 }; |
78 State state_; | 78 State state_; |
79 | 79 |
80 SyncNotifierRegistrar registrar_; | 80 InvalidatorRegistrar registrar_; |
81 | 81 |
82 // Passed to |invalidation_client_|. | 82 // Passed to |invalidation_client_|. |
83 const InvalidationVersionMap initial_max_invalidation_versions_; | 83 const InvalidationVersionMap initial_max_invalidation_versions_; |
84 | 84 |
85 // Passed to |invalidation_client_|. | 85 // Passed to |invalidation_client_|. |
86 const WeakHandle<InvalidationStateTracker> | 86 const WeakHandle<InvalidationStateTracker> |
87 invalidation_state_tracker_; | 87 invalidation_state_tracker_; |
88 | 88 |
89 // Passed to |invalidation_client_|. | 89 // Passed to |invalidation_client_|. |
90 const std::string client_info_; | 90 const std::string client_info_; |
91 | 91 |
92 // The client ID to pass to |chrome_invalidation_client_|. | 92 // The client ID to pass to |chrome_invalidation_client_|. |
93 std::string invalidation_client_id_; | 93 std::string invalidation_client_id_; |
94 | 94 |
95 // The state to pass to |chrome_invalidation_client_|. | 95 // The state to pass to |chrome_invalidation_client_|. |
96 // TODO(tim): This should be made const once migration is completed for bug | 96 // TODO(tim): This should be made const once migration is completed for bug |
97 // 124140. | 97 // 124140. |
98 std::string invalidation_state_; | 98 std::string invalidation_state_; |
99 | 99 |
100 // The invalidation client. | 100 // The invalidation client. |
101 ChromeInvalidationClient invalidation_client_; | 101 ChromeInvalidationClient invalidation_client_; |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); | 103 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); |
104 }; | 104 }; |
105 | 105 |
106 } // namespace syncer | 106 } // namespace syncer |
107 | 107 |
108 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ | 108 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ |
OLD | NEW |