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 // An implementation of SyncNotifier that wraps an invalidation | 5 // An implementation of SyncNotifier 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 #pragma once | 14 #pragma once |
| 15 | 15 |
| 16 #include <string> | 16 #include <string> |
| 17 | 17 |
| 18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 22 #include "base/threading/non_thread_safe.h" | 22 #include "base/threading/non_thread_safe.h" |
| 23 #include "jingle/notifier/base/notifier_options.h" | 23 #include "jingle/notifier/base/notifier_options.h" |
| 24 #include "jingle/notifier/communicator/login.h" | 24 #include "jingle/notifier/communicator/login.h" |
| 25 #include "sync/notifier/chrome_invalidation_client.h" | 25 #include "sync/notifier/chrome_invalidation_client.h" |
| 26 #include "sync/notifier/invalidation_state_tracker.h" | 26 #include "sync/notifier/invalidation_state_tracker.h" |
| 27 #include "sync/notifier/state_writer.h" | 27 #include "sync/notifier/state_writer.h" |
|
nilesh
2012/05/29 23:01:37
I think you can remove the include now.
| |
| 28 #include "sync/notifier/sync_notifier.h" | 28 #include "sync/notifier/sync_notifier.h" |
| 29 #include "sync/syncable/model_type.h" | 29 #include "sync/syncable/model_type.h" |
| 30 #include "sync/util/weak_handle.h" | 30 #include "sync/util/weak_handle.h" |
| 31 | 31 |
| 32 namespace sync_notifier { | 32 namespace sync_notifier { |
| 33 | 33 |
| 34 // This class must live on the IO thread. | 34 // This class must live on the IO thread. |
| 35 class InvalidationNotifier | 35 class InvalidationNotifier |
| 36 : public SyncNotifier, | 36 : public SyncNotifier, |
| 37 public notifier::LoginDelegate, | 37 public notifier::LoginDelegate, |
| 38 public ChromeInvalidationClient::Listener, | 38 public ChromeInvalidationClient::Listener { |
| 39 public StateWriter { | |
| 40 public: | 39 public: |
| 41 // |invalidation_state_tracker| must be initialized. | 40 // |invalidation_state_tracker| must be initialized. |
| 42 InvalidationNotifier( | 41 InvalidationNotifier( |
| 43 const notifier::NotifierOptions& notifier_options, | 42 const notifier::NotifierOptions& notifier_options, |
| 44 const InvalidationVersionMap& initial_max_invalidation_versions, | 43 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 44 const std::string& initial_invalidation_state, | |
| 45 const browser_sync::WeakHandle<InvalidationStateTracker>& | 45 const browser_sync::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 // SyncNotifier implementation. |
| 52 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; | 52 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; |
| 53 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; | 53 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; |
| 54 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; | 54 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; |
| 55 virtual void SetState(const std::string& state) OVERRIDE; | 55 virtual void SetStateDeprecated(const std::string& state) OVERRIDE; |
| 56 virtual void UpdateCredentials( | 56 virtual void UpdateCredentials( |
| 57 const std::string& email, const std::string& token) OVERRIDE; | 57 const std::string& email, const std::string& token) OVERRIDE; |
| 58 virtual void UpdateEnabledTypes( | 58 virtual void UpdateEnabledTypes( |
| 59 syncable::ModelTypeSet enabled_types) OVERRIDE; | 59 syncable::ModelTypeSet enabled_types) OVERRIDE; |
| 60 virtual void SendNotification( | 60 virtual void SendNotification( |
| 61 syncable::ModelTypeSet changed_types) OVERRIDE; | 61 syncable::ModelTypeSet changed_types) OVERRIDE; |
| 62 | 62 |
| 63 // notifier::LoginDelegate implementation. | 63 // notifier::LoginDelegate implementation. |
| 64 virtual void OnConnect( | 64 virtual void OnConnect( |
| 65 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) OVERRIDE; | 65 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) OVERRIDE; |
| 66 virtual void OnDisconnect() OVERRIDE; | 66 virtual void OnDisconnect() OVERRIDE; |
| 67 | 67 |
| 68 // ChromeInvalidationClient::Listener implementation. | 68 // ChromeInvalidationClient::Listener implementation. |
| 69 virtual void OnInvalidate( | 69 virtual void OnInvalidate( |
| 70 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE; | 70 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE; |
| 71 virtual void OnSessionStatusChanged(bool has_session) OVERRIDE; | 71 virtual void OnSessionStatusChanged(bool has_session) OVERRIDE; |
| 72 | 72 |
| 73 // StateWriter implementation. | |
| 74 virtual void WriteState(const std::string& state) OVERRIDE; | |
| 75 | |
| 76 private: | 73 private: |
| 77 base::NonThreadSafe non_thread_safe_; | 74 base::NonThreadSafe non_thread_safe_; |
| 78 | 75 |
| 79 // We start off in the STOPPED state. When we get our initial | 76 // We start off in the STOPPED state. When we get our initial |
| 80 // credentials, we connect and move to the CONNECTING state. When | 77 // credentials, we connect and move to the CONNECTING state. When |
| 81 // we're connected we start the invalidation client and move to the | 78 // we're connected we start the invalidation client and move to the |
| 82 // STARTED state. We never go back to a previous state. | 79 // STARTED state. We never go back to a previous state. |
| 83 enum State { | 80 enum State { |
| 84 STOPPED, | 81 STOPPED, |
| 85 CONNECTING, | 82 CONNECTING, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 100 // Passed to |invalidation_client_|. | 97 // Passed to |invalidation_client_|. |
| 101 const std::string client_info_; | 98 const std::string client_info_; |
| 102 | 99 |
| 103 // Our observers (which must live on the same thread). | 100 // Our observers (which must live on the same thread). |
| 104 ObserverList<SyncNotifierObserver> observers_; | 101 ObserverList<SyncNotifierObserver> observers_; |
| 105 | 102 |
| 106 // The client ID to pass to |chrome_invalidation_client_|. | 103 // The client ID to pass to |chrome_invalidation_client_|. |
| 107 std::string invalidation_client_id_; | 104 std::string invalidation_client_id_; |
| 108 | 105 |
| 109 // The state to pass to |chrome_invalidation_client_|. | 106 // The state to pass to |chrome_invalidation_client_|. |
| 107 // TODO(tim): This should be made const once migration is completed for bug | |
| 108 // 124140. | |
| 110 std::string invalidation_state_; | 109 std::string invalidation_state_; |
| 111 | 110 |
| 112 // The XMPP connection manager. | 111 // The XMPP connection manager. |
| 113 // TODO(akalin): Use PushClient instead. | 112 // TODO(akalin): Use PushClient instead. |
| 114 scoped_ptr<notifier::Login> login_; | 113 scoped_ptr<notifier::Login> login_; |
| 115 | 114 |
| 116 // The invalidation client. | 115 // The invalidation client. |
| 117 ChromeInvalidationClient invalidation_client_; | 116 ChromeInvalidationClient invalidation_client_; |
| 118 | 117 |
| 119 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); | 118 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); |
| 120 }; | 119 }; |
| 121 | 120 |
| 122 } // namespace sync_notifier | 121 } // namespace sync_notifier |
| 123 | 122 |
| 124 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ | 123 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ |
| OLD | NEW |