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

Side by Side Diff: components/invalidation/sync_invalidation_listener.h

Issue 1191393008: Introduce a layering in the invalidation component as public and impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Explicitly forbid content to prevent future additions Created 5 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // A simple wrapper around invalidation::InvalidationClient that
6 // handles all the startup/shutdown details and hookups.
7
8 #ifndef COMPONENTS_INVALIDATION_SYNC_INVALIDATION_LISTENER_H_
9 #define COMPONENTS_INVALIDATION_SYNC_INVALIDATION_LISTENER_H_
10
11 #include <string>
12
13 #include "base/basictypes.h"
14 #include "base/callback_forward.h"
15 #include "base/compiler_specific.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/threading/non_thread_safe.h"
19 #include "components/invalidation/ack_handler.h"
20 #include "components/invalidation/invalidation_export.h"
21 #include "components/invalidation/invalidation_state_tracker.h"
22 #include "components/invalidation/invalidator_state.h"
23 #include "components/invalidation/state_writer.h"
24 #include "components/invalidation/sync_system_resources.h"
25 #include "components/invalidation/unacked_invalidation_set.h"
26 #include "google/cacheinvalidation/include/invalidation-listener.h"
27
28 namespace buzz {
29 class XmppTaskParentInterface;
30 } // namespace buzz
31
32 namespace notifier {
33 class PushClient;
34 } // namespace notifier
35
36 namespace syncer {
37
38 class ObjectIdInvalidationMap;
39 class RegistrationManager;
40
41 // SyncInvalidationListener is not thread-safe and lives on the sync
42 // thread.
43 class INVALIDATION_EXPORT_PRIVATE SyncInvalidationListener
44 : public NON_EXPORTED_BASE(invalidation::InvalidationListener),
45 public StateWriter,
46 public SyncNetworkChannel::Observer,
47 public AckHandler,
48 public base::NonThreadSafe {
49 public:
50 typedef base::Callback<invalidation::InvalidationClient*(
51 invalidation::SystemResources*,
52 int,
53 const invalidation::string&,
54 const invalidation::string&,
55 invalidation::InvalidationListener*)> CreateInvalidationClientCallback;
56
57 class INVALIDATION_EXPORT_PRIVATE Delegate {
58 public:
59 virtual ~Delegate();
60
61 virtual void OnInvalidate(
62 const ObjectIdInvalidationMap& invalidations) = 0;
63
64 virtual void OnInvalidatorStateChange(InvalidatorState state) = 0;
65 };
66
67 explicit SyncInvalidationListener(
68 scoped_ptr<SyncNetworkChannel> network_channel);
69
70 // Calls Stop().
71 ~SyncInvalidationListener() override;
72
73 // Does not take ownership of |delegate| or |state_writer|.
74 // |invalidation_state_tracker| must be initialized.
75 void Start(
76 const CreateInvalidationClientCallback&
77 create_invalidation_client_callback,
78 const std::string& client_id,
79 const std::string& client_info,
80 const std::string& invalidation_bootstrap_data,
81 const UnackedInvalidationsMap& initial_object_states,
82 const base::WeakPtr<InvalidationStateTracker>& invalidation_state_tracker,
83 const scoped_refptr<base::SequencedTaskRunner>&
84 invalidation_state_tracker_task_runner,
85 Delegate* delegate);
86
87 void UpdateCredentials(const std::string& email, const std::string& token);
88
89 // Update the set of object IDs that we're interested in getting
90 // notifications for. May be called at any time.
91 void UpdateRegisteredIds(const ObjectIdSet& ids);
92
93 // invalidation::InvalidationListener implementation.
94 void Ready(invalidation::InvalidationClient* client) override;
95 void Invalidate(invalidation::InvalidationClient* client,
96 const invalidation::Invalidation& invalidation,
97 const invalidation::AckHandle& ack_handle) override;
98 void InvalidateUnknownVersion(
99 invalidation::InvalidationClient* client,
100 const invalidation::ObjectId& object_id,
101 const invalidation::AckHandle& ack_handle) override;
102 void InvalidateAll(invalidation::InvalidationClient* client,
103 const invalidation::AckHandle& ack_handle) override;
104 void InformRegistrationStatus(
105 invalidation::InvalidationClient* client,
106 const invalidation::ObjectId& object_id,
107 invalidation::InvalidationListener::RegistrationState reg_state) override;
108 void InformRegistrationFailure(invalidation::InvalidationClient* client,
109 const invalidation::ObjectId& object_id,
110 bool is_transient,
111 const std::string& error_message) override;
112 void ReissueRegistrations(invalidation::InvalidationClient* client,
113 const std::string& prefix,
114 int prefix_length) override;
115 void InformError(invalidation::InvalidationClient* client,
116 const invalidation::ErrorInfo& error_info) override;
117
118 // AckHandler implementation.
119 void Acknowledge(const invalidation::ObjectId& id,
120 const syncer::AckHandle& handle) override;
121 void Drop(const invalidation::ObjectId& id,
122 const syncer::AckHandle& handle) override;
123
124 // StateWriter implementation.
125 void WriteState(const std::string& state) override;
126
127 // SyncNetworkChannel::Observer implementation.
128 void OnNetworkChannelStateChanged(
129 InvalidatorState invalidator_state) override;
130
131 void DoRegistrationUpdate();
132
133 void RequestDetailedStatus(
134 base::Callback<void(const base::DictionaryValue&)> callback) const;
135
136 void StopForTest();
137
138 private:
139 void Stop();
140
141 InvalidatorState GetState() const;
142
143 void EmitStateChange();
144
145 // Sends invalidations to their appropriate destination.
146 //
147 // If there are no observers registered for them, they will be saved for
148 // later.
149 //
150 // If there are observers registered, they will be saved (to make sure we
151 // don't drop them until they've been acted on) and emitted to the observers.
152 void DispatchInvalidations(const ObjectIdInvalidationMap& invalidations);
153
154 // Saves invalidations.
155 //
156 // This call isn't synchronous so we can't guarantee these invalidations will
157 // be safely on disk by the end of the call, but it should ensure that the
158 // data makes it to disk eventually.
159 void SaveInvalidations(const ObjectIdInvalidationMap& to_save);
160
161 // Emits previously saved invalidations to their registered observers.
162 void EmitSavedInvalidations(const ObjectIdInvalidationMap& to_emit);
163
164 // Generate a Dictionary with all the debugging information.
165 scoped_ptr<base::DictionaryValue> CollectDebugData() const;
166
167 base::WeakPtr<AckHandler> AsWeakPtr();
168
169 scoped_ptr<SyncNetworkChannel> sync_network_channel_;
170 SyncSystemResources sync_system_resources_;
171 UnackedInvalidationsMap unacked_invalidations_map_;
172 base::WeakPtr<InvalidationStateTracker> invalidation_state_tracker_;
173 scoped_refptr<base::SequencedTaskRunner>
174 invalidation_state_tracker_task_runner_;
175 Delegate* delegate_;
176 scoped_ptr<invalidation::InvalidationClient> invalidation_client_;
177 scoped_ptr<RegistrationManager> registration_manager_;
178 // Stored to pass to |registration_manager_| on start.
179 ObjectIdSet registered_ids_;
180
181 // The states of the ticl and the push client.
182 InvalidatorState ticl_state_;
183 InvalidatorState push_client_state_;
184
185 base::WeakPtrFactory<SyncInvalidationListener> weak_ptr_factory_;
186
187 DISALLOW_COPY_AND_ASSIGN(SyncInvalidationListener);
188 };
189
190 } // namespace syncer
191
192 #endif // COMPONENTS_INVALIDATION_SYNC_INVALIDATION_LISTENER_H_
OLDNEW
« no previous file with comments | « components/invalidation/state_writer.h ('k') | components/invalidation/sync_invalidation_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698