Chromium Code Reviews| 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_CHROME_INVALIDATION_CLIENT_H_ |
| 9 #define SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 9 #define SYNC_NOTIFIER_CHROME_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/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 18 #include "google/cacheinvalidation/include/invalidation-listener.h" | 19 #include "google/cacheinvalidation/include/invalidation-listener.h" |
| 19 #include "jingle/notifier/listener/push_client_observer.h" | 20 #include "jingle/notifier/listener/push_client_observer.h" |
| 20 #include "sync/internal_api/public/util/weak_handle.h" | 21 #include "sync/internal_api/public/util/weak_handle.h" |
| 21 #include "sync/notifier/chrome_system_resources.h" | 22 #include "sync/notifier/chrome_system_resources.h" |
| 22 #include "sync/notifier/invalidation_state_tracker.h" | 23 #include "sync/notifier/invalidation_state_tracker.h" |
| 23 #include "sync/notifier/notifications_disabled_reason.h" | 24 #include "sync/notifier/notifications_disabled_reason.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 37 class RegistrationManager; | 38 class RegistrationManager; |
| 38 | 39 |
| 39 // ChromeInvalidationClient is not thread-safe and lives on the sync | 40 // ChromeInvalidationClient is not thread-safe and lives on the sync |
| 40 // thread. | 41 // thread. |
| 41 class ChromeInvalidationClient | 42 class ChromeInvalidationClient |
| 42 : public invalidation::InvalidationListener, | 43 : public invalidation::InvalidationListener, |
| 43 public StateWriter, | 44 public StateWriter, |
| 44 public notifier::PushClientObserver, | 45 public notifier::PushClientObserver, |
| 45 public base::NonThreadSafe { | 46 public base::NonThreadSafe { |
| 46 public: | 47 public: |
| 48 typedef base::Callback<invalidation::InvalidationClient*( | |
| 49 invalidation::SystemResources*, | |
| 50 int, | |
| 51 const invalidation::string&, | |
| 52 const invalidation::string&, | |
| 53 invalidation::InvalidationListener*)> CreateInvalidationClientCallback; | |
|
rlarocque
2012/08/07 18:21:48
I'm not sure that adding a function parameter is t
akalin
2012/08/08 22:46:35
I think we want to move away from the mark-functio
rlarocque
2012/08/08 23:22:56
I agree that dependency injection is generally bet
| |
| 54 | |
| 47 class Listener { | 55 class Listener { |
| 48 public: | 56 public: |
| 49 virtual ~Listener(); | 57 virtual ~Listener(); |
| 50 | 58 |
| 51 virtual void OnInvalidate(const ObjectIdPayloadMap& id_payloads) = 0; | 59 virtual void OnInvalidate(const ObjectIdPayloadMap& id_payloads) = 0; |
| 52 | 60 |
| 53 virtual void OnNotificationsEnabled() = 0; | 61 virtual void OnNotificationsEnabled() = 0; |
| 54 | 62 |
| 55 virtual void OnNotificationsDisabled( | 63 virtual void OnNotificationsDisabled( |
| 56 NotificationsDisabledReason reason) = 0; | 64 NotificationsDisabledReason reason) = 0; |
| 57 }; | 65 }; |
| 58 | 66 |
| 59 explicit ChromeInvalidationClient( | 67 explicit ChromeInvalidationClient( |
| 60 scoped_ptr<notifier::PushClient> push_client); | 68 scoped_ptr<notifier::PushClient> push_client); |
| 61 | 69 |
| 62 // Calls Stop(). | 70 // Calls Stop(). |
| 63 virtual ~ChromeInvalidationClient(); | 71 virtual ~ChromeInvalidationClient(); |
| 64 | 72 |
| 65 // Does not take ownership of |listener| or |state_writer|. | 73 // Does not take ownership of |listener| or |state_writer|. |
| 66 // |invalidation_state_tracker| must be initialized. | 74 // |invalidation_state_tracker| must be initialized. |
| 67 void Start( | 75 void Start( |
| 76 const CreateInvalidationClientCallback& | |
| 77 create_invalidation_client_callback, | |
| 68 const std::string& client_id, const std::string& client_info, | 78 const std::string& client_id, const std::string& client_info, |
| 69 const std::string& state, | 79 const std::string& state, |
| 70 const InvalidationVersionMap& initial_max_invalidation_versions, | 80 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 71 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, | 81 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, |
| 72 Listener* listener); | 82 Listener* listener); |
| 73 | 83 |
| 74 void UpdateCredentials(const std::string& email, const std::string& token); | 84 void UpdateCredentials(const std::string& email, const std::string& token); |
| 75 | 85 |
| 76 // Register the object IDs that we're interested in getting | 86 // Update the set of object IDs that we're interested in getting |
| 77 // notifications for. May be called at any time. | 87 // notifications for. May be called at any time. |
| 78 void RegisterIds(const ObjectIdSet& ids); | 88 void UpdateRegisteredIds(const ObjectIdSet& ids); |
| 79 | 89 |
| 80 // invalidation::InvalidationListener implementation. | 90 // invalidation::InvalidationListener implementation. |
| 81 virtual void Ready( | 91 virtual void Ready( |
| 82 invalidation::InvalidationClient* client) OVERRIDE; | 92 invalidation::InvalidationClient* client) OVERRIDE; |
| 83 virtual void Invalidate( | 93 virtual void Invalidate( |
| 84 invalidation::InvalidationClient* client, | 94 invalidation::InvalidationClient* client, |
| 85 const invalidation::Invalidation& invalidation, | 95 const invalidation::Invalidation& invalidation, |
| 86 const invalidation::AckHandle& ack_handle) OVERRIDE; | 96 const invalidation::AckHandle& ack_handle) OVERRIDE; |
| 87 virtual void InvalidateUnknownVersion( | 97 virtual void InvalidateUnknownVersion( |
| 88 invalidation::InvalidationClient* client, | 98 invalidation::InvalidationClient* client, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 111 // StateWriter implementation. | 121 // StateWriter implementation. |
| 112 virtual void WriteState(const std::string& state) OVERRIDE; | 122 virtual void WriteState(const std::string& state) OVERRIDE; |
| 113 | 123 |
| 114 // notifier::PushClientObserver implementation. | 124 // notifier::PushClientObserver implementation. |
| 115 virtual void OnNotificationsEnabled() OVERRIDE; | 125 virtual void OnNotificationsEnabled() OVERRIDE; |
| 116 virtual void OnNotificationsDisabled( | 126 virtual void OnNotificationsDisabled( |
| 117 notifier::NotificationsDisabledReason reason) OVERRIDE; | 127 notifier::NotificationsDisabledReason reason) OVERRIDE; |
| 118 virtual void OnIncomingNotification( | 128 virtual void OnIncomingNotification( |
| 119 const notifier::Notification& notification) OVERRIDE; | 129 const notifier::Notification& notification) OVERRIDE; |
| 120 | 130 |
| 131 void StopForTest(); | |
| 132 | |
| 121 private: | 133 private: |
| 122 friend class ChromeInvalidationClientTest; | |
| 123 | |
| 124 void Stop(); | 134 void Stop(); |
| 125 | 135 |
| 126 NotificationsDisabledReason GetState() const; | 136 NotificationsDisabledReason GetState() const; |
| 127 | 137 |
| 128 void EmitStateChange(); | 138 void EmitStateChange(); |
| 129 | 139 |
| 130 void EmitInvalidation(const ObjectIdPayloadMap& id_payloads); | 140 void EmitInvalidation(const ObjectIdPayloadMap& id_payloads); |
| 131 | 141 |
| 132 // Owned by |chrome_system_resources_|. | 142 // Owned by |chrome_system_resources_|. |
| 133 notifier::PushClient* const push_client_; | 143 notifier::PushClient* const push_client_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 144 // NO_NOTIFICATION_ERROR meaning notifications are enabled). | 154 // NO_NOTIFICATION_ERROR meaning notifications are enabled). |
| 145 NotificationsDisabledReason ticl_state_; | 155 NotificationsDisabledReason ticl_state_; |
| 146 NotificationsDisabledReason push_client_state_; | 156 NotificationsDisabledReason push_client_state_; |
| 147 | 157 |
| 148 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient); | 158 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient); |
| 149 }; | 159 }; |
| 150 | 160 |
| 151 } // namespace syncer | 161 } // namespace syncer |
| 152 | 162 |
| 153 #endif // SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 163 #endif // SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ |
| OLD | NEW |