[email protected] | 24c9ee5 | 2014-06-02 22:17:50 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 5 | #include "components/invalidation/non_blocking_invalidator.h" |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 6 | |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 7 | #include <cstddef> |
| 8 | |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 9 | #include "base/location.h" |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 12 | #include "base/single_thread_task_runner.h" |
| 13 | #include "base/thread_task_runner_handle.h" |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 14 | #include "base/threading/thread.h" |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 15 | #include "components/invalidation/gcm_network_channel_delegate.h" |
[email protected] | 001bbfdc | 2014-07-17 19:28:46 | [diff] [blame] | 16 | #include "components/invalidation/invalidation_handler.h" |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 17 | #include "components/invalidation/invalidation_notifier.h" |
[email protected] | 001bbfdc | 2014-07-17 19:28:46 | [diff] [blame] | 18 | #include "components/invalidation/object_id_invalidation_map.h" |
[email protected] | 4482877 | 2014-06-06 02:56:52 | [diff] [blame] | 19 | #include "components/invalidation/sync_system_resources.h" |
[email protected] | 1f7eba7 | 2012-05-30 09:10:17 | [diff] [blame] | 20 | #include "jingle/notifier/listener/push_client.h" |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 21 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 22 | namespace syncer { |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 23 | |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 24 | struct NonBlockingInvalidator::InitializeOptions { |
| 25 | InitializeOptions( |
| 26 | NetworkChannelCreator network_channel_creator, |
| 27 | const std::string& invalidator_client_id, |
| 28 | const UnackedInvalidationsMap& saved_invalidations, |
| 29 | const std::string& invalidation_bootstrap_data, |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 30 | const base::WeakPtr<InvalidationStateTracker>& invalidation_state_tracker, |
| 31 | const scoped_refptr<base::SingleThreadTaskRunner>& |
| 32 | invalidation_state_tracker_task_runner, |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 33 | const std::string& client_info, |
| 34 | scoped_refptr<net::URLRequestContextGetter> request_context_getter) |
| 35 | : network_channel_creator(network_channel_creator), |
| 36 | invalidator_client_id(invalidator_client_id), |
| 37 | saved_invalidations(saved_invalidations), |
| 38 | invalidation_bootstrap_data(invalidation_bootstrap_data), |
| 39 | invalidation_state_tracker(invalidation_state_tracker), |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 40 | invalidation_state_tracker_task_runner( |
| 41 | invalidation_state_tracker_task_runner), |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 42 | client_info(client_info), |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 43 | request_context_getter(request_context_getter) {} |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 44 | |
| 45 | NetworkChannelCreator network_channel_creator; |
| 46 | std::string invalidator_client_id; |
| 47 | UnackedInvalidationsMap saved_invalidations; |
| 48 | std::string invalidation_bootstrap_data; |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 49 | base::WeakPtr<InvalidationStateTracker> invalidation_state_tracker; |
| 50 | scoped_refptr<base::SingleThreadTaskRunner> |
| 51 | invalidation_state_tracker_task_runner; |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 52 | std::string client_info; |
| 53 | scoped_refptr<net::URLRequestContextGetter> request_context_getter; |
| 54 | }; |
| 55 | |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 56 | namespace { |
| 57 | // This class provides a wrapper for a logging class in order to receive |
| 58 | // callbacks across threads, without having to worry about owner threads. |
| 59 | class CallbackProxy { |
| 60 | public: |
| 61 | explicit CallbackProxy( |
| 62 | base::Callback<void(const base::DictionaryValue&)> callback); |
| 63 | ~CallbackProxy(); |
| 64 | |
| 65 | void Run(const base::DictionaryValue& value); |
| 66 | |
| 67 | private: |
| 68 | static void DoRun(base::Callback<void(const base::DictionaryValue&)> callback, |
| 69 | scoped_ptr<base::DictionaryValue> value); |
| 70 | |
| 71 | base::Callback<void(const base::DictionaryValue&)> callback_; |
| 72 | scoped_refptr<base::SingleThreadTaskRunner> running_thread_; |
| 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(CallbackProxy); |
| 75 | }; |
| 76 | |
| 77 | CallbackProxy::CallbackProxy( |
| 78 | base::Callback<void(const base::DictionaryValue&)> callback) |
| 79 | : callback_(callback), |
| 80 | running_thread_(base::ThreadTaskRunnerHandle::Get()) {} |
| 81 | |
| 82 | CallbackProxy::~CallbackProxy() {} |
| 83 | |
| 84 | void CallbackProxy::DoRun( |
| 85 | base::Callback<void(const base::DictionaryValue&)> callback, |
| 86 | scoped_ptr<base::DictionaryValue> value) { |
| 87 | callback.Run(*value); |
| 88 | } |
| 89 | |
| 90 | void CallbackProxy::Run(const base::DictionaryValue& value) { |
| 91 | scoped_ptr<base::DictionaryValue> copied(value.DeepCopy()); |
| 92 | running_thread_->PostTask( |
| 93 | FROM_HERE, |
| 94 | base::Bind(&CallbackProxy::DoRun, callback_, base::Passed(&copied))); |
| 95 | } |
| 96 | } |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 97 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 98 | class NonBlockingInvalidator::Core |
| 99 | : public base::RefCountedThreadSafe<NonBlockingInvalidator::Core>, |
| 100 | // InvalidationHandler to observe the InvalidationNotifier we create. |
| 101 | public InvalidationHandler { |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 102 | public: |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 103 | // Called on parent thread. |delegate_observer| should be initialized. |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 104 | Core(const base::WeakPtr<NonBlockingInvalidator>& delegate_observer, |
| 105 | const scoped_refptr<base::SingleThreadTaskRunner>& |
| 106 | delegate_observer_task_runner); |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 107 | |
| 108 | // Helpers called on I/O thread. |
[email protected] | e3b0ee5 | 2011-10-12 03:04:13 | [diff] [blame] | 109 | void Initialize( |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 110 | const NonBlockingInvalidator::InitializeOptions& initialize_options); |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 111 | void Teardown(); |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 112 | void UpdateRegisteredIds(const ObjectIdSet& ids); |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 113 | void UpdateCredentials(const std::string& email, const std::string& token); |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 114 | void RequestDetailedStatus( |
[email protected] | 40848a9 | 2014-03-24 22:41:02 | [diff] [blame] | 115 | base::Callback<void(const base::DictionaryValue&)> callback) const; |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 116 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 117 | // InvalidationHandler implementation (all called on I/O thread by |
[email protected] | 7800d79 | 2012-05-30 02:34:48 | [diff] [blame] | 118 | // InvalidationNotifier). |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 119 | void OnInvalidatorStateChange(InvalidatorState reason) override; |
| 120 | void OnIncomingInvalidation( |
mostynb | fe59f48 | 2014-10-06 15:04:46 | [diff] [blame] | 121 | const ObjectIdInvalidationMap& invalidation_map) override; |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 122 | std::string GetOwnerName() const override; |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 123 | |
| 124 | private: |
| 125 | friend class |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 126 | base::RefCountedThreadSafe<NonBlockingInvalidator::Core>; |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 127 | // Called on parent or I/O thread. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 128 | ~Core() override; |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 129 | |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 130 | // The variables below should be used only on the I/O thread. |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 131 | const base::WeakPtr<NonBlockingInvalidator> delegate_observer_; |
| 132 | scoped_refptr<base::SingleThreadTaskRunner> delegate_observer_task_runner_; |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 133 | scoped_ptr<InvalidationNotifier> invalidation_notifier_; |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 134 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
[email protected] | b9908a24 | 2011-11-19 09:31:32 | [diff] [blame] | 135 | |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 136 | DISALLOW_COPY_AND_ASSIGN(Core); |
| 137 | }; |
| 138 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 139 | NonBlockingInvalidator::Core::Core( |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 140 | const base::WeakPtr<NonBlockingInvalidator>& delegate_observer, |
| 141 | const scoped_refptr<base::SingleThreadTaskRunner>& |
| 142 | delegate_observer_task_runner) |
| 143 | : delegate_observer_(delegate_observer), |
| 144 | delegate_observer_task_runner_(delegate_observer_task_runner) { |
| 145 | DCHECK(delegate_observer_); |
dcheng | f0fe8bf | 2014-08-27 18:32:36 | [diff] [blame] | 146 | DCHECK(delegate_observer_task_runner_.get()); |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 147 | } |
| 148 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 149 | NonBlockingInvalidator::Core::~Core() { |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 152 | void NonBlockingInvalidator::Core::Initialize( |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 153 | const NonBlockingInvalidator::InitializeOptions& initialize_options) { |
| 154 | DCHECK(initialize_options.request_context_getter.get()); |
| 155 | network_task_runner_ = |
| 156 | initialize_options.request_context_getter->GetNetworkTaskRunner(); |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 157 | DCHECK(network_task_runner_->BelongsToCurrentThread()); |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 158 | scoped_ptr<SyncNetworkChannel> network_channel = |
| 159 | initialize_options.network_channel_creator.Run(); |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 160 | invalidation_notifier_.reset(new InvalidationNotifier( |
| 161 | network_channel.Pass(), |
| 162 | initialize_options.invalidator_client_id, |
| 163 | initialize_options.saved_invalidations, |
| 164 | initialize_options.invalidation_bootstrap_data, |
| 165 | initialize_options.invalidation_state_tracker, |
| 166 | initialize_options.invalidation_state_tracker_task_runner, |
| 167 | initialize_options.client_info)); |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 168 | invalidation_notifier_->RegisterHandler(this); |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 171 | void NonBlockingInvalidator::Core::Teardown() { |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 172 | DCHECK(network_task_runner_->BelongsToCurrentThread()); |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 173 | invalidation_notifier_->UnregisterHandler(this); |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 174 | invalidation_notifier_.reset(); |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 175 | network_task_runner_ = NULL; |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 176 | } |
| 177 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 178 | void NonBlockingInvalidator::Core::UpdateRegisteredIds(const ObjectIdSet& ids) { |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 179 | DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 180 | invalidation_notifier_->UpdateRegisteredIds(this, ids); |
| 181 | } |
| 182 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 183 | void NonBlockingInvalidator::Core::UpdateCredentials(const std::string& email, |
| 184 | const std::string& token) { |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 185 | DCHECK(network_task_runner_->BelongsToCurrentThread()); |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 186 | invalidation_notifier_->UpdateCredentials(email, token); |
| 187 | } |
| 188 | |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 189 | void NonBlockingInvalidator::Core::RequestDetailedStatus( |
[email protected] | 40848a9 | 2014-03-24 22:41:02 | [diff] [blame] | 190 | base::Callback<void(const base::DictionaryValue&)> callback) const { |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 191 | DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 192 | invalidation_notifier_->RequestDetailedStatus(callback); |
| 193 | } |
| 194 | |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 195 | void NonBlockingInvalidator::Core::OnInvalidatorStateChange( |
| 196 | InvalidatorState reason) { |
[email protected] | 2d3d1d1 | 2012-06-18 20:50:28 | [diff] [blame] | 197 | DCHECK(network_task_runner_->BelongsToCurrentThread()); |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 198 | delegate_observer_task_runner_->PostTask( |
| 199 | FROM_HERE, |
| 200 | base::Bind(&NonBlockingInvalidator::OnInvalidatorStateChange, |
| 201 | delegate_observer_, |
| 202 | reason)); |
[email protected] | 2d3d1d1 | 2012-06-18 20:50:28 | [diff] [blame] | 203 | } |
| 204 | |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 205 | void NonBlockingInvalidator::Core::OnIncomingInvalidation( |
[email protected] | 0d0b59d | 2013-02-02 00:24:47 | [diff] [blame] | 206 | const ObjectIdInvalidationMap& invalidation_map) { |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 207 | DCHECK(network_task_runner_->BelongsToCurrentThread()); |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 208 | delegate_observer_task_runner_->PostTask( |
| 209 | FROM_HERE, |
| 210 | base::Bind(&NonBlockingInvalidator::OnIncomingInvalidation, |
| 211 | delegate_observer_, |
| 212 | invalidation_map)); |
[email protected] | 942e202 | 2011-04-07 22:27:43 | [diff] [blame] | 213 | } |
| 214 | |
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame] | 215 | std::string NonBlockingInvalidator::Core::GetOwnerName() const { |
| 216 | return "Sync"; |
| 217 | } |
| 218 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 219 | NonBlockingInvalidator::NonBlockingInvalidator( |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 220 | NetworkChannelCreator network_channel_creator, |
[email protected] | d551123 | 2013-03-28 01:34:54 | [diff] [blame] | 221 | const std::string& invalidator_client_id, |
[email protected] | a7b1639 | 2013-11-26 22:46:26 | [diff] [blame] | 222 | const UnackedInvalidationsMap& saved_invalidations, |
[email protected] | 8cdb689 | 2012-10-03 05:54:40 | [diff] [blame] | 223 | const std::string& invalidation_bootstrap_data, |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 224 | InvalidationStateTracker* invalidation_state_tracker, |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 225 | const std::string& client_info, |
| 226 | const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 227 | : invalidation_state_tracker_(invalidation_state_tracker), |
| 228 | parent_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 229 | network_task_runner_(request_context_getter->GetNetworkTaskRunner()), |
[email protected] | 37d5b347 | 2013-10-10 16:20:36 | [diff] [blame] | 230 | weak_ptr_factory_(this) { |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 231 | base::WeakPtr<NonBlockingInvalidator> weak_ptr_this = |
| 232 | weak_ptr_factory_.GetWeakPtr(); |
| 233 | weak_ptr_this.get(); // Bind to this thread. |
[email protected] | 37d5b347 | 2013-10-10 16:20:36 | [diff] [blame] | 234 | |
[email protected] | 5fe215c | 2014-08-09 06:04:28 | [diff] [blame] | 235 | core_ = new Core(weak_ptr_this, |
| 236 | base::MessageLoopProxy::current()); |
| 237 | |
| 238 | InitializeOptions initialize_options(network_channel_creator, |
| 239 | invalidator_client_id, |
| 240 | saved_invalidations, |
| 241 | invalidation_bootstrap_data, |
| 242 | weak_ptr_this, |
| 243 | base::MessageLoopProxy::current(), |
| 244 | client_info, |
| 245 | request_context_getter); |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 246 | |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 247 | if (!network_task_runner_->PostTask( |
[email protected] | daf4e10 | 2011-04-26 08:30:28 | [diff] [blame] | 248 | FROM_HERE, |
[email protected] | 09e170f | 2011-10-28 23:22:02 | [diff] [blame] | 249 | base::Bind( |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 250 | &NonBlockingInvalidator::Core::Initialize, |
[email protected] | 09e170f | 2011-10-28 23:22:02 | [diff] [blame] | 251 | core_.get(), |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 252 | initialize_options))) { |
[email protected] | daf4e10 | 2011-04-26 08:30:28 | [diff] [blame] | 253 | NOTREACHED(); |
[email protected] | 0a561205 | 2011-06-29 03:29:18 | [diff] [blame] | 254 | } |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 255 | } |
| 256 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 257 | NonBlockingInvalidator::~NonBlockingInvalidator() { |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 258 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 259 | if (!network_task_runner_->PostTask( |
[email protected] | daf4e10 | 2011-04-26 08:30:28 | [diff] [blame] | 260 | FROM_HERE, |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 261 | base::Bind(&NonBlockingInvalidator::Core::Teardown, |
[email protected] | 09e170f | 2011-10-28 23:22:02 | [diff] [blame] | 262 | core_.get()))) { |
[email protected] | 93dcabfb | 2013-07-31 01:31:55 | [diff] [blame] | 263 | DVLOG(1) << "Network thread stopped before invalidator is destroyed."; |
[email protected] | 0a561205 | 2011-06-29 03:29:18 | [diff] [blame] | 264 | } |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 267 | void NonBlockingInvalidator::RegisterHandler(InvalidationHandler* handler) { |
[email protected] | 6529382 | 2012-08-10 04:07:19 | [diff] [blame] | 268 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 269 | registrar_.RegisterHandler(handler); |
| 270 | } |
| 271 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 272 | void NonBlockingInvalidator::UpdateRegisteredIds(InvalidationHandler* handler, |
| 273 | const ObjectIdSet& ids) { |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 274 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 275 | registrar_.UpdateRegisteredIds(handler, ids); |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 276 | if (!network_task_runner_->PostTask( |
| 277 | FROM_HERE, |
| 278 | base::Bind( |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 279 | &NonBlockingInvalidator::Core::UpdateRegisteredIds, |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 280 | core_.get(), |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 281 | registrar_.GetAllRegisteredIds()))) { |
[email protected] | d914f02 | 2012-07-27 02:02:00 | [diff] [blame] | 282 | NOTREACHED(); |
| 283 | } |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 286 | void NonBlockingInvalidator::UnregisterHandler(InvalidationHandler* handler) { |
[email protected] | 85b25eb | 2012-08-10 19:32:08 | [diff] [blame] | 287 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 288 | registrar_.UnregisterHandler(handler); |
| 289 | } |
| 290 | |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 291 | InvalidatorState NonBlockingInvalidator::GetInvalidatorState() const { |
| 292 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 293 | return registrar_.GetInvalidatorState(); |
| 294 | } |
| 295 | |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 296 | void NonBlockingInvalidator::UpdateCredentials(const std::string& email, |
| 297 | const std::string& token) { |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 298 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 299 | if (!network_task_runner_->PostTask( |
[email protected] | daf4e10 | 2011-04-26 08:30:28 | [diff] [blame] | 300 | FROM_HERE, |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 301 | base::Bind(&NonBlockingInvalidator::Core::UpdateCredentials, |
[email protected] | 09e170f | 2011-10-28 23:22:02 | [diff] [blame] | 302 | core_.get(), email, token))) { |
[email protected] | daf4e10 | 2011-04-26 08:30:28 | [diff] [blame] | 303 | NOTREACHED(); |
[email protected] | 0a561205 | 2011-06-29 03:29:18 | [diff] [blame] | 304 | } |
[email protected] | 0a80fed | 2011-03-24 22:31:48 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 307 | void NonBlockingInvalidator::RequestDetailedStatus( |
[email protected] | 40848a9 | 2014-03-24 22:41:02 | [diff] [blame] | 308 | base::Callback<void(const base::DictionaryValue&)> callback) const { |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 309 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 310 | base::Callback<void(const base::DictionaryValue&)> proxy_callback = |
| 311 | base::Bind(&CallbackProxy::Run, base::Owned(new CallbackProxy(callback))); |
| 312 | if (!network_task_runner_->PostTask( |
| 313 | FROM_HERE, |
| 314 | base::Bind(&NonBlockingInvalidator::Core::RequestDetailedStatus, |
| 315 | core_.get(), |
| 316 | proxy_callback))) { |
| 317 | NOTREACHED(); |
| 318 | } |
| 319 | } |
| 320 | |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 321 | NetworkChannelCreator |
| 322 | NonBlockingInvalidator::MakePushClientChannelCreator( |
| 323 | const notifier::NotifierOptions& notifier_options) { |
| 324 | return base::Bind(SyncNetworkChannel::CreatePushClientChannel, |
| 325 | notifier_options); |
| 326 | } |
| 327 | |
[email protected] | df006cbc | 2014-01-22 18:36:20 | [diff] [blame] | 328 | NetworkChannelCreator NonBlockingInvalidator::MakeGCMNetworkChannelCreator( |
| 329 | scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 330 | scoped_ptr<GCMNetworkChannelDelegate> delegate) { |
| 331 | return base::Bind(&SyncNetworkChannel::CreateGCMNetworkChannel, |
| 332 | request_context_getter, |
| 333 | base::Passed(&delegate)); |
[email protected] | 04a830a | 2014-01-04 02:48:51 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 3ee8ec7 | 2014-04-16 21:38:50 | [diff] [blame] | 336 | void NonBlockingInvalidator::ClearAndSetNewClientId(const std::string& data) { |
| 337 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 338 | invalidation_state_tracker_->ClearAndSetNewClientId(data); |
| 339 | } |
| 340 | |
| 341 | std::string NonBlockingInvalidator::GetInvalidatorClientId() const { |
| 342 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 343 | return invalidation_state_tracker_->GetInvalidatorClientId(); |
| 344 | } |
| 345 | |
| 346 | void NonBlockingInvalidator::SetBootstrapData(const std::string& data) { |
| 347 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 348 | invalidation_state_tracker_->SetBootstrapData(data); |
| 349 | } |
| 350 | |
| 351 | std::string NonBlockingInvalidator::GetBootstrapData() const { |
| 352 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 353 | return invalidation_state_tracker_->GetBootstrapData(); |
| 354 | } |
| 355 | |
| 356 | void NonBlockingInvalidator::SetSavedInvalidations( |
| 357 | const UnackedInvalidationsMap& states) { |
| 358 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 359 | invalidation_state_tracker_->SetSavedInvalidations(states); |
| 360 | } |
| 361 | |
| 362 | UnackedInvalidationsMap NonBlockingInvalidator::GetSavedInvalidations() const { |
| 363 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 364 | return invalidation_state_tracker_->GetSavedInvalidations(); |
| 365 | } |
| 366 | |
| 367 | void NonBlockingInvalidator::Clear() { |
| 368 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 369 | invalidation_state_tracker_->Clear(); |
| 370 | } |
| 371 | |
| 372 | void NonBlockingInvalidator::OnInvalidatorStateChange(InvalidatorState state) { |
| 373 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 374 | registrar_.UpdateInvalidatorState(state); |
| 375 | } |
| 376 | |
| 377 | void NonBlockingInvalidator::OnIncomingInvalidation( |
| 378 | const ObjectIdInvalidationMap& invalidation_map) { |
| 379 | DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 380 | registrar_.DispatchInvalidationsToHandlers(invalidation_map); |
| 381 | } |
| 382 | |
| 383 | std::string NonBlockingInvalidator::GetOwnerName() const { return "Sync"; } |
| 384 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 385 | } // namespace syncer |