Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: sync/notifier/invalidation_notifier.h

Issue 10436013: [Sync] Make InvalidationNotifier use PushClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
24 #include "jingle/notifier/communicator/login.h"
25 #include "sync/notifier/chrome_invalidation_client.h" 23 #include "sync/notifier/chrome_invalidation_client.h"
26 #include "sync/notifier/invalidation_state_tracker.h" 24 #include "sync/notifier/invalidation_state_tracker.h"
27 #include "sync/notifier/state_writer.h" 25 #include "sync/notifier/state_writer.h"
28 #include "sync/notifier/sync_notifier.h" 26 #include "sync/notifier/sync_notifier.h"
29 #include "sync/syncable/model_type.h" 27 #include "sync/syncable/model_type.h"
30 #include "sync/util/weak_handle.h" 28 #include "sync/util/weak_handle.h"
31 29
30 namespace notifier {
31 class PushClient;
32 } // namespace notifier
33
32 namespace sync_notifier { 34 namespace sync_notifier {
33 35
34 // This class must live on the IO thread. 36 // This class must live on the IO thread.
35 class InvalidationNotifier 37 class InvalidationNotifier
36 : public SyncNotifier, 38 : public SyncNotifier,
37 public notifier::LoginDelegate,
38 public ChromeInvalidationClient::Listener, 39 public ChromeInvalidationClient::Listener,
39 public StateWriter { 40 public StateWriter {
40 public: 41 public:
41 // |invalidation_state_tracker| must be initialized. 42 // |invalidation_state_tracker| must be initialized.
42 InvalidationNotifier( 43 InvalidationNotifier(
43 const notifier::NotifierOptions& notifier_options, 44 scoped_ptr<notifier::PushClient> push_client,
rlarocque 2012/05/24 00:44:49 Same concern as before. I'm not sure it makes sen
44 const InvalidationVersionMap& initial_max_invalidation_versions, 45 const InvalidationVersionMap& initial_max_invalidation_versions,
45 const browser_sync::WeakHandle<InvalidationStateTracker>& 46 const browser_sync::WeakHandle<InvalidationStateTracker>&
46 invalidation_state_tracker, 47 invalidation_state_tracker,
47 const std::string& client_info); 48 const std::string& client_info);
48 49
49 virtual ~InvalidationNotifier(); 50 virtual ~InvalidationNotifier();
50 51
51 // SyncNotifier implementation. 52 // SyncNotifier implementation.
52 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE; 53 virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE;
53 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE; 54 virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE;
54 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE; 55 virtual void SetUniqueId(const std::string& unique_id) OVERRIDE;
55 virtual void SetState(const std::string& state) OVERRIDE; 56 virtual void SetState(const std::string& state) OVERRIDE;
56 virtual void UpdateCredentials( 57 virtual void UpdateCredentials(
57 const std::string& email, const std::string& token) OVERRIDE; 58 const std::string& email, const std::string& token) OVERRIDE;
58 virtual void UpdateEnabledTypes( 59 virtual void UpdateEnabledTypes(
59 syncable::ModelTypeSet enabled_types) OVERRIDE; 60 syncable::ModelTypeSet enabled_types) OVERRIDE;
60 virtual void SendNotification( 61 virtual void SendNotification(
61 syncable::ModelTypeSet changed_types) OVERRIDE; 62 syncable::ModelTypeSet changed_types) OVERRIDE;
62 63
63 // notifier::LoginDelegate implementation.
64 virtual void OnConnect(
65 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) OVERRIDE;
66 virtual void OnDisconnect() OVERRIDE;
67
68 // ChromeInvalidationClient::Listener implementation. 64 // ChromeInvalidationClient::Listener implementation.
69 virtual void OnInvalidate( 65 virtual void OnInvalidate(
70 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE; 66 const syncable::ModelTypePayloadMap& type_payloads) OVERRIDE;
71 virtual void OnSessionStatusChanged(bool has_session) OVERRIDE; 67 virtual void OnSessionStatusChanged(bool has_session) OVERRIDE;
72 68
73 // StateWriter implementation. 69 // StateWriter implementation.
74 virtual void WriteState(const std::string& state) OVERRIDE; 70 virtual void WriteState(const std::string& state) OVERRIDE;
75 71
76 private: 72 private:
77 base::NonThreadSafe non_thread_safe_; 73 base::NonThreadSafe non_thread_safe_;
78 74
79 // We start off in the STOPPED state. When we get our initial 75 // We start off in the STOPPED state. When we get our initial
80 // credentials, we connect and move to the CONNECTING state. When 76 // credentials, we connect and move to the CONNECTING state. When
81 // we're connected we start the invalidation client and move to the 77 // we're connected we start the invalidation client and move to the
82 // STARTED state. We never go back to a previous state. 78 // STARTED state. We never go back to a previous state.
83 enum State { 79 enum State {
84 STOPPED, 80 STOPPED,
85 CONNECTING, 81 CONNECTING,
86 STARTED 82 STARTED
87 }; 83 };
88 State state_; 84 State state_;
89 85
90 // Used to build parameters for |login_|.
91 const notifier::NotifierOptions notifier_options_;
92
93 // Passed to |invalidation_client_|. 86 // Passed to |invalidation_client_|.
94 const InvalidationVersionMap initial_max_invalidation_versions_; 87 const InvalidationVersionMap initial_max_invalidation_versions_;
95 88
96 // Passed to |invalidation_client_|. 89 // Passed to |invalidation_client_|.
97 const browser_sync::WeakHandle<InvalidationStateTracker> 90 const browser_sync::WeakHandle<InvalidationStateTracker>
98 invalidation_state_tracker_; 91 invalidation_state_tracker_;
99 92
100 // Passed to |invalidation_client_|. 93 // Passed to |invalidation_client_|.
101 const std::string client_info_; 94 const std::string client_info_;
102 95
103 // Our observers (which must live on the same thread). 96 // Our observers (which must live on the same thread).
104 ObserverList<SyncNotifierObserver> observers_; 97 ObserverList<SyncNotifierObserver> observers_;
105 98
106 // The client ID to pass to |chrome_invalidation_client_|. 99 // The client ID to pass to |chrome_invalidation_client_|.
107 std::string invalidation_client_id_; 100 std::string invalidation_client_id_;
108 101
109 // The state to pass to |chrome_invalidation_client_|. 102 // The state to pass to |chrome_invalidation_client_|.
110 std::string invalidation_state_; 103 std::string invalidation_state_;
111 104
112 // The XMPP connection manager.
113 // TODO(akalin): Use PushClient instead.
114 scoped_ptr<notifier::Login> login_;
115
116 // The invalidation client. 105 // The invalidation client.
117 ChromeInvalidationClient invalidation_client_; 106 ChromeInvalidationClient invalidation_client_;
118 107
119 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); 108 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier);
120 }; 109 };
121 110
122 } // namespace sync_notifier 111 } // namespace sync_notifier
123 112
124 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ 113 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698