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 // A simple wrapper around invalidation::InvalidationClient that | 5 // A simple wrapper around invalidation::InvalidationClient that |
6 // handles all the startup/shutdown details and hookups. | 6 // handles all the startup/shutdown details and hookups. |
7 | 7 |
8 #ifndef SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 8 #ifndef SYNC_NOTIFIER_SYNC_INVALIDATION_CLIENT_H_ |
9 #define SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 9 #define SYNC_NOTIFIER_SYNC_INVALIDATION_CLIENT_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
19 #include "google/cacheinvalidation/include/invalidation-listener.h" | 19 #include "google/cacheinvalidation/include/invalidation-listener.h" |
20 #include "jingle/notifier/listener/push_client_observer.h" | 20 #include "jingle/notifier/listener/push_client_observer.h" |
21 #include "sync/internal_api/public/util/weak_handle.h" | 21 #include "sync/internal_api/public/util/weak_handle.h" |
22 #include "sync/notifier/chrome_system_resources.h" | |
23 #include "sync/notifier/invalidation_state_tracker.h" | 22 #include "sync/notifier/invalidation_state_tracker.h" |
24 #include "sync/notifier/notifications_disabled_reason.h" | 23 #include "sync/notifier/notifications_disabled_reason.h" |
25 #include "sync/notifier/object_id_state_map.h" | 24 #include "sync/notifier/object_id_state_map.h" |
26 #include "sync/notifier/state_writer.h" | 25 #include "sync/notifier/state_writer.h" |
| 26 #include "sync/notifier/sync_system_resources.h" |
27 | 27 |
28 namespace buzz { | 28 namespace buzz { |
29 class XmppTaskParentInterface; | 29 class XmppTaskParentInterface; |
30 } // namespace buzz | 30 } // namespace buzz |
31 | 31 |
32 namespace notifier { | 32 namespace notifier { |
33 class PushClient; | 33 class PushClient; |
34 } // namespace notifier | 34 } // namespace notifier |
35 | 35 |
36 namespace syncer { | 36 namespace syncer { |
37 | 37 |
38 class RegistrationManager; | 38 class RegistrationManager; |
39 | 39 |
40 // ChromeInvalidationClient is not thread-safe and lives on the sync | 40 // SyncInvalidationClient is not thread-safe and lives on the sync |
41 // thread. | 41 // thread. |
42 class ChromeInvalidationClient | 42 class SyncInvalidationClient |
43 : public invalidation::InvalidationListener, | 43 : public invalidation::InvalidationListener, |
44 public StateWriter, | 44 public StateWriter, |
45 public notifier::PushClientObserver, | 45 public notifier::PushClientObserver, |
46 public base::NonThreadSafe { | 46 public base::NonThreadSafe { |
47 public: | 47 public: |
48 typedef base::Callback<invalidation::InvalidationClient*( | 48 typedef base::Callback<invalidation::InvalidationClient*( |
49 invalidation::SystemResources*, | 49 invalidation::SystemResources*, |
50 int, | 50 int, |
51 const invalidation::string&, | 51 const invalidation::string&, |
52 const invalidation::string&, | 52 const invalidation::string&, |
53 invalidation::InvalidationListener*)> CreateInvalidationClientCallback; | 53 invalidation::InvalidationListener*)> CreateInvalidationClientCallback; |
54 | 54 |
55 class Listener { | 55 class Listener { |
56 public: | 56 public: |
57 virtual ~Listener(); | 57 virtual ~Listener(); |
58 | 58 |
59 virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) = 0; | 59 virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) = 0; |
60 | 60 |
61 virtual void OnNotificationsEnabled() = 0; | 61 virtual void OnNotificationsEnabled() = 0; |
62 | 62 |
63 virtual void OnNotificationsDisabled( | 63 virtual void OnNotificationsDisabled( |
64 NotificationsDisabledReason reason) = 0; | 64 NotificationsDisabledReason reason) = 0; |
65 }; | 65 }; |
66 | 66 |
67 explicit ChromeInvalidationClient( | 67 explicit SyncInvalidationClient( |
68 scoped_ptr<notifier::PushClient> push_client); | 68 scoped_ptr<notifier::PushClient> push_client); |
69 | 69 |
70 // Calls Stop(). | 70 // Calls Stop(). |
71 virtual ~ChromeInvalidationClient(); | 71 virtual ~SyncInvalidationClient(); |
72 | 72 |
73 // Does not take ownership of |listener| or |state_writer|. | 73 // Does not take ownership of |listener| or |state_writer|. |
74 // |invalidation_state_tracker| must be initialized. | 74 // |invalidation_state_tracker| must be initialized. |
75 void Start( | 75 void Start( |
76 const CreateInvalidationClientCallback& | 76 const CreateInvalidationClientCallback& |
77 create_invalidation_client_callback, | 77 create_invalidation_client_callback, |
78 const std::string& client_id, const std::string& client_info, | 78 const std::string& client_id, const std::string& client_info, |
79 const std::string& state, | 79 const std::string& state, |
80 const InvalidationVersionMap& initial_max_invalidation_versions, | 80 const InvalidationVersionMap& initial_max_invalidation_versions, |
81 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, | 81 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 private: | 133 private: |
134 void Stop(); | 134 void Stop(); |
135 | 135 |
136 NotificationsDisabledReason GetState() const; | 136 NotificationsDisabledReason GetState() const; |
137 | 137 |
138 void EmitStateChange(); | 138 void EmitStateChange(); |
139 | 139 |
140 void EmitInvalidation(const ObjectIdStateMap& id_state_map); | 140 void EmitInvalidation(const ObjectIdStateMap& id_state_map); |
141 | 141 |
142 // Owned by |chrome_system_resources_|. | 142 // Owned by |sync_system_resources_|. |
143 notifier::PushClient* const push_client_; | 143 notifier::PushClient* const push_client_; |
144 ChromeSystemResources chrome_system_resources_; | 144 SyncSystemResources sync_system_resources_; |
145 InvalidationVersionMap max_invalidation_versions_; | 145 InvalidationVersionMap max_invalidation_versions_; |
146 WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; | 146 WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; |
147 Listener* listener_; | 147 Listener* listener_; |
148 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; | 148 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; |
149 scoped_ptr<RegistrationManager> registration_manager_; | 149 scoped_ptr<RegistrationManager> registration_manager_; |
150 // Stored to pass to |registration_manager_| on start. | 150 // Stored to pass to |registration_manager_| on start. |
151 ObjectIdSet registered_ids_; | 151 ObjectIdSet registered_ids_; |
152 | 152 |
153 // The states of the ticl and the push client (with | 153 // The states of the ticl and the push client (with |
154 // NO_NOTIFICATION_ERROR meaning notifications are enabled). | 154 // NO_NOTIFICATION_ERROR meaning notifications are enabled). |
155 NotificationsDisabledReason ticl_state_; | 155 NotificationsDisabledReason ticl_state_; |
156 NotificationsDisabledReason push_client_state_; | 156 NotificationsDisabledReason push_client_state_; |
157 | 157 |
158 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient); | 158 DISALLOW_COPY_AND_ASSIGN(SyncInvalidationClient); |
159 }; | 159 }; |
160 | 160 |
161 } // namespace syncer | 161 } // namespace syncer |
162 | 162 |
163 #endif // SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 163 #endif // SYNC_NOTIFIER_SYNC_INVALIDATION_CLIENT_H_ |
OLD | NEW |