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

Side by Side Diff: sync/notifier/non_blocking_invalidation_notifier.cc

Issue 10451060: sync: migrate invalidation state from syncable::Directory to InvalidationStorage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: include order Created 8 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 | 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 #include "sync/notifier/non_blocking_invalidation_notifier.h" 5 #include "sync/notifier/non_blocking_invalidation_notifier.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 10 matching lines...) Expand all
21 // Called on parent thread. |delegate_observer| should be 21 // Called on parent thread. |delegate_observer| should be
22 // initialized. 22 // initialized.
23 explicit Core( 23 explicit Core(
24 const browser_sync::WeakHandle<SyncNotifierObserver>& 24 const browser_sync::WeakHandle<SyncNotifierObserver>&
25 delegate_observer); 25 delegate_observer);
26 26
27 // Helpers called on I/O thread. 27 // Helpers called on I/O thread.
28 void Initialize( 28 void Initialize(
29 const notifier::NotifierOptions& notifier_options, 29 const notifier::NotifierOptions& notifier_options,
30 const InvalidationVersionMap& initial_max_invalidation_versions, 30 const InvalidationVersionMap& initial_max_invalidation_versions,
31 const std::string& initial_invalidation_state,
31 const browser_sync::WeakHandle<InvalidationStateTracker>& 32 const browser_sync::WeakHandle<InvalidationStateTracker>&
32 invalidation_state_tracker, 33 invalidation_state_tracker,
33 const std::string& client_info); 34 const std::string& client_info);
34 void Teardown(); 35 void Teardown();
35 void SetUniqueId(const std::string& unique_id); 36 void SetUniqueId(const std::string& unique_id);
36 void SetState(const std::string& state); 37 void SetStateDeprecated(const std::string& state);
37 void UpdateCredentials(const std::string& email, const std::string& token); 38 void UpdateCredentials(const std::string& email, const std::string& token);
38 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); 39 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types);
39 40
40 // SyncNotifierObserver implementation (all called on I/O thread by 41 // SyncNotifierObserver implementation (all called on I/O thread by
41 // InvalidationNotifier). 42 // InvalidationNotifier).
42 virtual void OnIncomingNotification( 43 virtual void OnIncomingNotification(
43 const syncable::ModelTypePayloadMap& type_payloads, 44 const syncable::ModelTypePayloadMap& type_payloads,
44 IncomingNotificationSource source); 45 IncomingNotificationSource source);
45 virtual void OnNotificationStateChange(bool notifications_enabled); 46 virtual void OnNotificationStateChange(bool notifications_enabled);
46 virtual void StoreState(const std::string& state);
47 47
48 private: 48 private:
49 friend class 49 friend class
50 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; 50 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>;
51 // Called on parent or I/O thread. 51 // Called on parent or I/O thread.
52 ~Core(); 52 ~Core();
53 53
54 // The variables below should be used only on the I/O thread. 54 // The variables below should be used only on the I/O thread.
55 const browser_sync::WeakHandle<SyncNotifierObserver> delegate_observer_; 55 const browser_sync::WeakHandle<SyncNotifierObserver> delegate_observer_;
56 scoped_ptr<InvalidationNotifier> invalidation_notifier_; 56 scoped_ptr<InvalidationNotifier> invalidation_notifier_;
57 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 57 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
58 58
59 DISALLOW_COPY_AND_ASSIGN(Core); 59 DISALLOW_COPY_AND_ASSIGN(Core);
60 }; 60 };
61 61
62 NonBlockingInvalidationNotifier::Core::Core( 62 NonBlockingInvalidationNotifier::Core::Core(
63 const browser_sync::WeakHandle<SyncNotifierObserver>& 63 const browser_sync::WeakHandle<SyncNotifierObserver>&
64 delegate_observer) 64 delegate_observer)
65 : delegate_observer_(delegate_observer) { 65 : delegate_observer_(delegate_observer) {
66 DCHECK(delegate_observer_.IsInitialized()); 66 DCHECK(delegate_observer_.IsInitialized());
67 } 67 }
68 68
69 NonBlockingInvalidationNotifier::Core::~Core() { 69 NonBlockingInvalidationNotifier::Core::~Core() {
70 } 70 }
71 71
72 void NonBlockingInvalidationNotifier::Core::Initialize( 72 void NonBlockingInvalidationNotifier::Core::Initialize(
73 const notifier::NotifierOptions& notifier_options, 73 const notifier::NotifierOptions& notifier_options,
74 const InvalidationVersionMap& initial_max_invalidation_versions, 74 const InvalidationVersionMap& initial_max_invalidation_versions,
75 const std::string& initial_invalidation_state,
75 const browser_sync::WeakHandle<InvalidationStateTracker>& 76 const browser_sync::WeakHandle<InvalidationStateTracker>&
76 invalidation_state_tracker, 77 invalidation_state_tracker,
77 const std::string& client_info) { 78 const std::string& client_info) {
78 DCHECK(notifier_options.request_context_getter); 79 DCHECK(notifier_options.request_context_getter);
79 DCHECK_EQ(notifier::NOTIFICATION_SERVER, 80 DCHECK_EQ(notifier::NOTIFICATION_SERVER,
80 notifier_options.notification_method); 81 notifier_options.notification_method);
81 io_message_loop_proxy_ = notifier_options.request_context_getter-> 82 io_message_loop_proxy_ = notifier_options.request_context_getter->
82 GetIOMessageLoopProxy(); 83 GetIOMessageLoopProxy();
83 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 84 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
84 invalidation_notifier_.reset( 85 invalidation_notifier_.reset(
85 new InvalidationNotifier( 86 new InvalidationNotifier(
86 notifier::PushClient::CreateDefaultOnIOThread(notifier_options), 87 notifier::PushClient::CreateDefaultOnIOThread(notifier_options),
87 initial_max_invalidation_versions, 88 initial_max_invalidation_versions,
89 initial_invalidation_state,
88 invalidation_state_tracker, 90 invalidation_state_tracker,
89 client_info)); 91 client_info));
90 invalidation_notifier_->AddObserver(this); 92 invalidation_notifier_->AddObserver(this);
91 } 93 }
92 94
93 95
94 void NonBlockingInvalidationNotifier::Core::Teardown() { 96 void NonBlockingInvalidationNotifier::Core::Teardown() {
95 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 97 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
96 invalidation_notifier_->RemoveObserver(this); 98 invalidation_notifier_->RemoveObserver(this);
97 invalidation_notifier_.reset(); 99 invalidation_notifier_.reset();
98 io_message_loop_proxy_ = NULL; 100 io_message_loop_proxy_ = NULL;
99 } 101 }
100 102
101 void NonBlockingInvalidationNotifier::Core::SetUniqueId( 103 void NonBlockingInvalidationNotifier::Core::SetUniqueId(
102 const std::string& unique_id) { 104 const std::string& unique_id) {
103 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 105 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
104 invalidation_notifier_->SetUniqueId(unique_id); 106 invalidation_notifier_->SetUniqueId(unique_id);
105 } 107 }
106 108
107 void NonBlockingInvalidationNotifier::Core::SetState( 109 void NonBlockingInvalidationNotifier::Core::SetStateDeprecated(
108 const std::string& state) { 110 const std::string& state) {
109 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 111 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
110 invalidation_notifier_->SetState(state); 112 invalidation_notifier_->SetStateDeprecated(state);
111 } 113 }
112 114
113 void NonBlockingInvalidationNotifier::Core::UpdateCredentials( 115 void NonBlockingInvalidationNotifier::Core::UpdateCredentials(
114 const std::string& email, const std::string& token) { 116 const std::string& email, const std::string& token) {
115 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 117 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
116 invalidation_notifier_->UpdateCredentials(email, token); 118 invalidation_notifier_->UpdateCredentials(email, token);
117 } 119 }
118 120
119 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( 121 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes(
120 syncable::ModelTypeSet enabled_types) { 122 syncable::ModelTypeSet enabled_types) {
(...skipping 12 matching lines...) Expand all
133 } 135 }
134 136
135 void NonBlockingInvalidationNotifier::Core::OnNotificationStateChange( 137 void NonBlockingInvalidationNotifier::Core::OnNotificationStateChange(
136 bool notifications_enabled) { 138 bool notifications_enabled) {
137 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 139 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
138 delegate_observer_.Call(FROM_HERE, 140 delegate_observer_.Call(FROM_HERE,
139 &SyncNotifierObserver::OnNotificationStateChange, 141 &SyncNotifierObserver::OnNotificationStateChange,
140 notifications_enabled); 142 notifications_enabled);
141 } 143 }
142 144
143 void NonBlockingInvalidationNotifier::Core::StoreState(
144 const std::string& state) {
145 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
146 delegate_observer_.Call(FROM_HERE,
147 &SyncNotifierObserver::StoreState, state);
148 }
149
150 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( 145 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier(
151 const notifier::NotifierOptions& notifier_options, 146 const notifier::NotifierOptions& notifier_options,
152 const InvalidationVersionMap& initial_max_invalidation_versions, 147 const InvalidationVersionMap& initial_max_invalidation_versions,
148 const std::string& initial_invalidation_state,
153 const browser_sync::WeakHandle<InvalidationStateTracker>& 149 const browser_sync::WeakHandle<InvalidationStateTracker>&
154 invalidation_state_tracker, 150 invalidation_state_tracker,
155 const std::string& client_info) 151 const std::string& client_info)
156 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 152 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
157 core_( 153 core_(
158 new Core(browser_sync::MakeWeakHandle( 154 new Core(browser_sync::MakeWeakHandle(
159 weak_ptr_factory_.GetWeakPtr()))), 155 weak_ptr_factory_.GetWeakPtr()))),
160 parent_message_loop_proxy_( 156 parent_message_loop_proxy_(
161 base::MessageLoopProxy::current()), 157 base::MessageLoopProxy::current()),
162 io_message_loop_proxy_(notifier_options.request_context_getter-> 158 io_message_loop_proxy_(notifier_options.request_context_getter->
163 GetIOMessageLoopProxy()) { 159 GetIOMessageLoopProxy()) {
164 if (!io_message_loop_proxy_->PostTask( 160 if (!io_message_loop_proxy_->PostTask(
165 FROM_HERE, 161 FROM_HERE,
166 base::Bind( 162 base::Bind(
167 &NonBlockingInvalidationNotifier::Core::Initialize, 163 &NonBlockingInvalidationNotifier::Core::Initialize,
168 core_.get(), 164 core_.get(),
169 notifier_options, 165 notifier_options,
170 initial_max_invalidation_versions, 166 initial_max_invalidation_versions,
167 initial_invalidation_state,
171 invalidation_state_tracker, 168 invalidation_state_tracker,
172 client_info))) { 169 client_info))) {
173 NOTREACHED(); 170 NOTREACHED();
174 } 171 }
175 } 172 }
176 173
177 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { 174 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() {
178 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 175 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
179 if (!io_message_loop_proxy_->PostTask( 176 if (!io_message_loop_proxy_->PostTask(
180 FROM_HERE, 177 FROM_HERE,
(...skipping 19 matching lines...) Expand all
200 const std::string& unique_id) { 197 const std::string& unique_id) {
201 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 198 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
202 if (!io_message_loop_proxy_->PostTask( 199 if (!io_message_loop_proxy_->PostTask(
203 FROM_HERE, 200 FROM_HERE,
204 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId, 201 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId,
205 core_.get(), unique_id))) { 202 core_.get(), unique_id))) {
206 NOTREACHED(); 203 NOTREACHED();
207 } 204 }
208 } 205 }
209 206
210 void NonBlockingInvalidationNotifier::SetState(const std::string& state) { 207 void NonBlockingInvalidationNotifier::SetStateDeprecated(
208 const std::string& state) {
211 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 209 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
212 if (!io_message_loop_proxy_->PostTask( 210 if (!io_message_loop_proxy_->PostTask(
213 FROM_HERE, 211 FROM_HERE,
214 base::Bind(&NonBlockingInvalidationNotifier::Core::SetState, 212 base::Bind(
215 core_.get(), state))) { 213 &NonBlockingInvalidationNotifier::Core::SetStateDeprecated,
214 core_.get(), state))) {
216 NOTREACHED(); 215 NOTREACHED();
217 } 216 }
218 } 217 }
219 218
220 void NonBlockingInvalidationNotifier::UpdateCredentials( 219 void NonBlockingInvalidationNotifier::UpdateCredentials(
221 const std::string& email, const std::string& token) { 220 const std::string& email, const std::string& token) {
222 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 221 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
223 if (!io_message_loop_proxy_->PostTask( 222 if (!io_message_loop_proxy_->PostTask(
224 FROM_HERE, 223 FROM_HERE,
225 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials, 224 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials,
(...skipping 28 matching lines...) Expand all
254 OnIncomingNotification(type_payloads, source)); 253 OnIncomingNotification(type_payloads, source));
255 } 254 }
256 255
257 void NonBlockingInvalidationNotifier::OnNotificationStateChange( 256 void NonBlockingInvalidationNotifier::OnNotificationStateChange(
258 bool notifications_enabled) { 257 bool notifications_enabled) {
259 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); 258 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
260 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, 259 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_,
261 OnNotificationStateChange(notifications_enabled)); 260 OnNotificationStateChange(notifications_enabled));
262 } 261 }
263 262
264 void NonBlockingInvalidationNotifier::StoreState(
265 const std::string& state) {
266 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread());
267 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_,
268 StoreState(state));
269 }
270
271 } // namespace sync_notifier 263 } // namespace sync_notifier
OLDNEW
« no previous file with comments | « sync/notifier/non_blocking_invalidation_notifier.h ('k') | sync/notifier/non_blocking_invalidation_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698