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 #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" |
11 #include "sync/notifier/invalidation_notifier.h" | 11 #include "sync/notifier/invalidation_notifier.h" |
12 | 12 |
13 namespace sync_notifier { | 13 namespace sync_notifier { |
14 | 14 |
15 class NonBlockingInvalidationNotifier::Core | 15 class NonBlockingInvalidationNotifier::Core |
16 : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>, | 16 : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>, |
17 public SyncNotifierObserver { | 17 public SyncNotifierObserver { |
18 public: | 18 public: |
19 // Called on parent thread. |delegate_observer| should be | 19 // Called on parent thread. |delegate_observer| should be |
20 // initialized. | 20 // initialized. |
21 explicit Core( | 21 explicit Core( |
22 const browser_sync::WeakHandle<SyncNotifierObserver>& | 22 const browser_sync::WeakHandle<SyncNotifierObserver>& |
23 delegate_observer); | 23 delegate_observer); |
24 | 24 |
25 // Helpers called on I/O thread. | 25 // Helpers called on I/O thread. |
26 void Initialize( | 26 void Initialize( |
27 const notifier::NotifierOptions& notifier_options, | 27 const notifier::NotifierOptions& notifier_options, |
28 const InvalidationVersionMap& initial_max_invalidation_versions, | 28 const InvalidationVersionMap& initial_max_invalidation_versions, |
29 const browser_sync::WeakHandle<InvalidationVersionTracker>& | 29 const browser_sync::WeakHandle<InvalidationStateTracker>& |
30 invalidation_version_tracker, | 30 invalidation_state_tracker, |
31 const std::string& client_info); | 31 const std::string& client_info); |
32 void Teardown(); | 32 void Teardown(); |
33 void SetUniqueId(const std::string& unique_id); | 33 void SetUniqueId(const std::string& unique_id); |
34 void SetState(const std::string& state); | 34 void SetState(const std::string& state); |
35 void UpdateCredentials(const std::string& email, const std::string& token); | 35 void UpdateCredentials(const std::string& email, const std::string& token); |
36 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); | 36 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); |
37 | 37 |
38 // SyncNotifierObserver implementation (all called on I/O thread). | 38 // SyncNotifierObserver implementation (all called on I/O thread). |
39 virtual void OnIncomingNotification( | 39 virtual void OnIncomingNotification( |
40 const syncable::ModelTypePayloadMap& type_payloads, | 40 const syncable::ModelTypePayloadMap& type_payloads, |
(...skipping 21 matching lines...) Expand all Loading... |
62 : delegate_observer_(delegate_observer) { | 62 : delegate_observer_(delegate_observer) { |
63 DCHECK(delegate_observer_.IsInitialized()); | 63 DCHECK(delegate_observer_.IsInitialized()); |
64 } | 64 } |
65 | 65 |
66 NonBlockingInvalidationNotifier::Core::~Core() { | 66 NonBlockingInvalidationNotifier::Core::~Core() { |
67 } | 67 } |
68 | 68 |
69 void NonBlockingInvalidationNotifier::Core::Initialize( | 69 void NonBlockingInvalidationNotifier::Core::Initialize( |
70 const notifier::NotifierOptions& notifier_options, | 70 const notifier::NotifierOptions& notifier_options, |
71 const InvalidationVersionMap& initial_max_invalidation_versions, | 71 const InvalidationVersionMap& initial_max_invalidation_versions, |
72 const browser_sync::WeakHandle<InvalidationVersionTracker>& | 72 const browser_sync::WeakHandle<InvalidationStateTracker>& |
73 invalidation_version_tracker, | 73 invalidation_state_tracker, |
74 const std::string& client_info) { | 74 const std::string& client_info) { |
75 DCHECK(notifier_options.request_context_getter); | 75 DCHECK(notifier_options.request_context_getter); |
76 DCHECK_EQ(notifier::NOTIFICATION_SERVER, | 76 DCHECK_EQ(notifier::NOTIFICATION_SERVER, |
77 notifier_options.notification_method); | 77 notifier_options.notification_method); |
78 io_message_loop_proxy_ = notifier_options.request_context_getter-> | 78 io_message_loop_proxy_ = notifier_options.request_context_getter-> |
79 GetIOMessageLoopProxy(); | 79 GetIOMessageLoopProxy(); |
80 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 80 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
81 invalidation_notifier_.reset( | 81 invalidation_notifier_.reset( |
82 new InvalidationNotifier( | 82 new InvalidationNotifier( |
83 notifier_options, | 83 notifier_options, |
84 initial_max_invalidation_versions, | 84 initial_max_invalidation_versions, |
85 invalidation_version_tracker, | 85 invalidation_state_tracker, |
86 client_info)); | 86 client_info)); |
87 invalidation_notifier_->AddObserver(this); | 87 invalidation_notifier_->AddObserver(this); |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 void NonBlockingInvalidationNotifier::Core::Teardown() { | 91 void NonBlockingInvalidationNotifier::Core::Teardown() { |
92 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 92 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
93 invalidation_notifier_->RemoveObserver(this); | 93 invalidation_notifier_->RemoveObserver(this); |
94 invalidation_notifier_.reset(); | 94 invalidation_notifier_.reset(); |
95 io_message_loop_proxy_ = NULL; | 95 io_message_loop_proxy_ = NULL; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 void NonBlockingInvalidationNotifier::Core::StoreState( | 140 void NonBlockingInvalidationNotifier::Core::StoreState( |
141 const std::string& state) { | 141 const std::string& state) { |
142 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 142 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
143 delegate_observer_.Call(FROM_HERE, | 143 delegate_observer_.Call(FROM_HERE, |
144 &SyncNotifierObserver::StoreState, state); | 144 &SyncNotifierObserver::StoreState, state); |
145 } | 145 } |
146 | 146 |
147 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( | 147 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( |
148 const notifier::NotifierOptions& notifier_options, | 148 const notifier::NotifierOptions& notifier_options, |
149 const InvalidationVersionMap& initial_max_invalidation_versions, | 149 const InvalidationVersionMap& initial_max_invalidation_versions, |
150 const browser_sync::WeakHandle<InvalidationVersionTracker>& | 150 const browser_sync::WeakHandle<InvalidationStateTracker>& |
151 invalidation_version_tracker, | 151 invalidation_state_tracker, |
152 const std::string& client_info) | 152 const std::string& client_info) |
153 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 153 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
154 core_( | 154 core_( |
155 new Core(browser_sync::MakeWeakHandle( | 155 new Core(browser_sync::MakeWeakHandle( |
156 weak_ptr_factory_.GetWeakPtr()))), | 156 weak_ptr_factory_.GetWeakPtr()))), |
157 parent_message_loop_proxy_( | 157 parent_message_loop_proxy_( |
158 base::MessageLoopProxy::current()), | 158 base::MessageLoopProxy::current()), |
159 io_message_loop_proxy_(notifier_options.request_context_getter-> | 159 io_message_loop_proxy_(notifier_options.request_context_getter-> |
160 GetIOMessageLoopProxy()) { | 160 GetIOMessageLoopProxy()) { |
161 if (!io_message_loop_proxy_->PostTask( | 161 if (!io_message_loop_proxy_->PostTask( |
162 FROM_HERE, | 162 FROM_HERE, |
163 base::Bind( | 163 base::Bind( |
164 &NonBlockingInvalidationNotifier::Core::Initialize, | 164 &NonBlockingInvalidationNotifier::Core::Initialize, |
165 core_.get(), | 165 core_.get(), |
166 notifier_options, | 166 notifier_options, |
167 initial_max_invalidation_versions, | 167 initial_max_invalidation_versions, |
168 invalidation_version_tracker, | 168 invalidation_state_tracker, |
169 client_info))) { | 169 client_info))) { |
170 NOTREACHED(); | 170 NOTREACHED(); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { | 174 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { |
175 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 175 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
176 if (!io_message_loop_proxy_->PostTask( | 176 if (!io_message_loop_proxy_->PostTask( |
177 FROM_HERE, | 177 FROM_HERE, |
178 base::Bind(&NonBlockingInvalidationNotifier::Core::Teardown, | 178 base::Bind(&NonBlockingInvalidationNotifier::Core::Teardown, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 259 } |
260 | 260 |
261 void NonBlockingInvalidationNotifier::StoreState( | 261 void NonBlockingInvalidationNotifier::StoreState( |
262 const std::string& state) { | 262 const std::string& state) { |
263 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 263 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
264 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 264 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
265 StoreState(state)); | 265 StoreState(state)); |
266 } | 266 } |
267 | 267 |
268 } // namespace sync_notifier | 268 } // namespace sync_notifier |
OLD | NEW |