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 #pragma once | 10 #pragma once |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "sync/notifier/invalidation_state_tracker.h" | 21 #include "sync/notifier/invalidation_state_tracker.h" |
| 22 #include "sync/notifier/state_writer.h" | 22 #include "sync/notifier/state_writer.h" |
| 23 #include "sync/syncable/model_type.h" | 23 #include "sync/syncable/model_type.h" |
| 24 #include "sync/syncable/model_type_payload_map.h" | 24 #include "sync/syncable/model_type_payload_map.h" |
| 25 #include "sync/util/weak_handle.h" | 25 #include "sync/util/weak_handle.h" |
| 26 | 26 |
| 27 namespace buzz { | 27 namespace buzz { |
| 28 class XmppTaskParentInterface; | 28 class XmppTaskParentInterface; |
| 29 } // namespace buzz | 29 } // namespace buzz |
| 30 | 30 |
| 31 namespace notifier { | |
| 32 class PushClient; | |
| 33 } // namespace notifier | |
| 34 | |
| 31 namespace sync_notifier { | 35 namespace sync_notifier { |
| 32 | 36 |
| 33 using invalidation::InvalidationListener; | 37 using invalidation::InvalidationListener; |
| 34 | 38 |
| 35 class CacheInvalidationPacketHandler; | |
| 36 class RegistrationManager; | 39 class RegistrationManager; |
| 37 | 40 |
| 38 // ChromeInvalidationClient is not thread-safe and lives on the sync | 41 // ChromeInvalidationClient is not thread-safe and lives on the sync |
| 39 // thread. | 42 // thread. |
| 40 class ChromeInvalidationClient | 43 class ChromeInvalidationClient |
| 41 : public InvalidationListener, | 44 : public InvalidationListener, |
| 42 public StateWriter { | 45 public StateWriter { |
| 43 public: | 46 public: |
| 44 class Listener { | 47 class Listener { |
| 45 public: | 48 public: |
| 46 virtual ~Listener(); | 49 virtual ~Listener(); |
| 47 | 50 |
| 48 virtual void OnInvalidate( | 51 virtual void OnInvalidate( |
| 49 const syncable::ModelTypePayloadMap& type_payloads) = 0; | 52 const syncable::ModelTypePayloadMap& type_payloads) = 0; |
| 50 | 53 |
| 51 virtual void OnSessionStatusChanged(bool has_session) = 0; | 54 virtual void OnSessionStatusChanged(bool has_session) = 0; |
| 52 }; | 55 }; |
| 53 | 56 |
| 54 ChromeInvalidationClient(); | 57 explicit ChromeInvalidationClient( |
| 58 scoped_ptr<notifier::PushClient> push_client); | |
|
rlarocque
2012/05/24 00:44:49
A scoped_ptr as a constructor parameter looks stra
akalin
2012/05/24 00:48:27
.Pass() still returns a scoped_ptr<> so that would
| |
| 55 | 59 |
| 56 // Calls Stop(). | 60 // Calls Stop(). |
| 57 virtual ~ChromeInvalidationClient(); | 61 virtual ~ChromeInvalidationClient(); |
| 58 | 62 |
| 59 // Does not take ownership of |listener| or |state_writer|. | 63 // Does not take ownership of |listener| or |state_writer|. |
| 60 // |invalidation_state_tracker| must be initialized. | 64 // |invalidation_state_tracker| must be initialized. |
| 61 // |base_task| must still be non-NULL. | |
| 62 void Start( | 65 void Start( |
| 63 const std::string& client_id, const std::string& client_info, | 66 const std::string& client_id, const std::string& client_info, |
| 64 const std::string& state, | 67 const std::string& state, |
| 65 const InvalidationVersionMap& initial_max_invalidation_versions, | 68 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 66 const browser_sync::WeakHandle<InvalidationStateTracker>& | 69 const browser_sync::WeakHandle<InvalidationStateTracker>& |
| 67 invalidation_state_tracker, | 70 invalidation_state_tracker, |
| 68 Listener* listener, | 71 Listener* listener, |
| 69 StateWriter* state_writer, | 72 StateWriter* state_writer); |
| 70 base::WeakPtr<buzz::XmppTaskParentInterface> base_task); | |
| 71 | 73 |
| 72 void Stop(); | 74 void UpdateCredentials(const std::string& email, const std::string& token); |
| 73 | |
| 74 // Changes the task used to |base_task|, which must still be | |
| 75 // non-NULL. Must only be called between calls to Start() and | |
| 76 // Stop(). | |
| 77 void ChangeBaseTask(base::WeakPtr<buzz::XmppTaskParentInterface> base_task); | |
| 78 | 75 |
| 79 // Register the sync types that we're interested in getting | 76 // Register the sync types that we're interested in getting |
| 80 // notifications for. May be called at any time. | 77 // notifications for. May be called at any time. |
| 81 void RegisterTypes(syncable::ModelTypeSet types); | 78 void RegisterTypes(syncable::ModelTypeSet types); |
| 82 | 79 |
| 83 virtual void WriteState(const std::string& state) OVERRIDE; | 80 virtual void WriteState(const std::string& state) OVERRIDE; |
| 84 | 81 |
| 85 // invalidation::InvalidationListener implementation. | 82 // invalidation::InvalidationListener implementation. |
| 86 virtual void Ready( | 83 virtual void Ready( |
| 87 invalidation::InvalidationClient* client) OVERRIDE; | 84 invalidation::InvalidationClient* client) OVERRIDE; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 109 invalidation::InvalidationClient* client, | 106 invalidation::InvalidationClient* client, |
| 110 const std::string& prefix, | 107 const std::string& prefix, |
| 111 int prefix_length) OVERRIDE; | 108 int prefix_length) OVERRIDE; |
| 112 virtual void InformError( | 109 virtual void InformError( |
| 113 invalidation::InvalidationClient* client, | 110 invalidation::InvalidationClient* client, |
| 114 const invalidation::ErrorInfo& error_info) OVERRIDE; | 111 const invalidation::ErrorInfo& error_info) OVERRIDE; |
| 115 | 112 |
| 116 private: | 113 private: |
| 117 friend class ChromeInvalidationClientTest; | 114 friend class ChromeInvalidationClientTest; |
| 118 | 115 |
| 116 void Stop(); | |
| 117 | |
| 119 void EmitInvalidation( | 118 void EmitInvalidation( |
| 120 syncable::ModelTypeSet types, const std::string& payload); | 119 syncable::ModelTypeSet types, const std::string& payload); |
| 121 | 120 |
| 122 base::NonThreadSafe non_thread_safe_; | 121 base::NonThreadSafe non_thread_safe_; |
| 123 ChromeSystemResources chrome_system_resources_; | 122 ChromeSystemResources chrome_system_resources_; |
| 124 InvalidationVersionMap max_invalidation_versions_; | 123 InvalidationVersionMap max_invalidation_versions_; |
| 125 browser_sync::WeakHandle<InvalidationStateTracker> | 124 browser_sync::WeakHandle<InvalidationStateTracker> |
| 126 invalidation_state_tracker_; | 125 invalidation_state_tracker_; |
| 127 Listener* listener_; | 126 Listener* listener_; |
| 128 StateWriter* state_writer_; | 127 StateWriter* state_writer_; |
| 129 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; | 128 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; |
| 130 scoped_ptr<CacheInvalidationPacketHandler> | |
| 131 cache_invalidation_packet_handler_; | |
| 132 scoped_ptr<RegistrationManager> registration_manager_; | 129 scoped_ptr<RegistrationManager> registration_manager_; |
| 133 // Stored to pass to |registration_manager_| on start. | 130 // Stored to pass to |registration_manager_| on start. |
| 134 syncable::ModelTypeSet registered_types_; | 131 syncable::ModelTypeSet registered_types_; |
| 135 bool ticl_ready_; | 132 bool ticl_ready_; |
| 136 | 133 |
| 137 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient); | 134 DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationClient); |
| 138 }; | 135 }; |
| 139 | 136 |
| 140 } // namespace sync_notifier | 137 } // namespace sync_notifier |
| 141 | 138 |
| 142 #endif // SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ | 139 #endif // SYNC_NOTIFIER_CHROME_INVALIDATION_CLIENT_H_ |
| OLD | NEW |