OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/invalidation/impl/ticl_invalidation_service.h" | 5 #include "components/invalidation/impl/ticl_invalidation_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 identity_provider_(std::move(identity_provider)), | 66 identity_provider_(std::move(identity_provider)), |
67 settings_provider_(std::move(settings_provider)), | 67 settings_provider_(std::move(settings_provider)), |
68 invalidator_registrar_(new syncer::InvalidatorRegistrar()), | 68 invalidator_registrar_(new syncer::InvalidatorRegistrar()), |
69 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), | 69 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), |
70 network_channel_type_(GCM_NETWORK_CHANNEL), | 70 network_channel_type_(GCM_NETWORK_CHANNEL), |
71 gcm_driver_(gcm_driver), | 71 gcm_driver_(gcm_driver), |
72 request_context_(request_context), | 72 request_context_(request_context), |
73 logger_() {} | 73 logger_() {} |
74 | 74 |
75 TiclInvalidationService::~TiclInvalidationService() { | 75 TiclInvalidationService::~TiclInvalidationService() { |
76 DCHECK(CalledOnValidThread()); | 76 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
77 invalidator_registrar_->UpdateInvalidatorState( | 77 invalidator_registrar_->UpdateInvalidatorState( |
78 syncer::INVALIDATOR_SHUTTING_DOWN); | 78 syncer::INVALIDATOR_SHUTTING_DOWN); |
79 settings_provider_->RemoveObserver(this); | 79 settings_provider_->RemoveObserver(this); |
80 identity_provider_->RemoveActiveAccountRefreshTokenObserver(this); | 80 identity_provider_->RemoveActiveAccountRefreshTokenObserver(this); |
81 identity_provider_->RemoveObserver(this); | 81 identity_provider_->RemoveObserver(this); |
82 if (IsStarted()) { | 82 if (IsStarted()) { |
83 StopInvalidator(); | 83 StopInvalidator(); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 void TiclInvalidationService::Init( | 87 void TiclInvalidationService::Init( |
88 std::unique_ptr<syncer::InvalidationStateTracker> | 88 std::unique_ptr<syncer::InvalidationStateTracker> |
89 invalidation_state_tracker) { | 89 invalidation_state_tracker) { |
90 DCHECK(CalledOnValidThread()); | 90 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
91 invalidation_state_tracker_ = std::move(invalidation_state_tracker); | 91 invalidation_state_tracker_ = std::move(invalidation_state_tracker); |
92 | 92 |
93 if (invalidation_state_tracker_->GetInvalidatorClientId().empty()) { | 93 if (invalidation_state_tracker_->GetInvalidatorClientId().empty()) { |
94 invalidation_state_tracker_->ClearAndSetNewClientId( | 94 invalidation_state_tracker_->ClearAndSetNewClientId( |
95 GenerateInvalidatorClientId()); | 95 GenerateInvalidatorClientId()); |
96 } | 96 } |
97 | 97 |
98 UpdateInvalidationNetworkChannel(); | 98 UpdateInvalidationNetworkChannel(); |
99 if (IsReadyToStart()) { | 99 if (IsReadyToStart()) { |
100 StartInvalidator(network_channel_type_); | 100 StartInvalidator(network_channel_type_); |
(...skipping 14 matching lines...) Expand all Loading... |
115 invalidation_state_tracker_ = std::move(invalidation_state_tracker); | 115 invalidation_state_tracker_ = std::move(invalidation_state_tracker); |
116 invalidator_.reset(invalidator); | 116 invalidator_.reset(invalidator); |
117 | 117 |
118 invalidator_->RegisterHandler(this); | 118 invalidator_->RegisterHandler(this); |
119 CHECK(invalidator_->UpdateRegisteredIds( | 119 CHECK(invalidator_->UpdateRegisteredIds( |
120 this, invalidator_registrar_->GetAllRegisteredIds())); | 120 this, invalidator_registrar_->GetAllRegisteredIds())); |
121 } | 121 } |
122 | 122 |
123 void TiclInvalidationService::RegisterInvalidationHandler( | 123 void TiclInvalidationService::RegisterInvalidationHandler( |
124 syncer::InvalidationHandler* handler) { | 124 syncer::InvalidationHandler* handler) { |
125 DCHECK(CalledOnValidThread()); | 125 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
126 DVLOG(2) << "Registering an invalidation handler"; | 126 DVLOG(2) << "Registering an invalidation handler"; |
127 invalidator_registrar_->RegisterHandler(handler); | 127 invalidator_registrar_->RegisterHandler(handler); |
128 logger_.OnRegistration(handler->GetOwnerName()); | 128 logger_.OnRegistration(handler->GetOwnerName()); |
129 } | 129 } |
130 | 130 |
131 bool TiclInvalidationService::UpdateRegisteredInvalidationIds( | 131 bool TiclInvalidationService::UpdateRegisteredInvalidationIds( |
132 syncer::InvalidationHandler* handler, | 132 syncer::InvalidationHandler* handler, |
133 const syncer::ObjectIdSet& ids) { | 133 const syncer::ObjectIdSet& ids) { |
134 DCHECK(CalledOnValidThread()); | 134 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
135 DVLOG(2) << "Registering ids: " << ids.size(); | 135 DVLOG(2) << "Registering ids: " << ids.size(); |
136 if (!invalidator_registrar_->UpdateRegisteredIds(handler, ids)) | 136 if (!invalidator_registrar_->UpdateRegisteredIds(handler, ids)) |
137 return false; | 137 return false; |
138 if (invalidator_) { | 138 if (invalidator_) { |
139 CHECK(invalidator_->UpdateRegisteredIds( | 139 CHECK(invalidator_->UpdateRegisteredIds( |
140 this, invalidator_registrar_->GetAllRegisteredIds())); | 140 this, invalidator_registrar_->GetAllRegisteredIds())); |
141 } | 141 } |
142 logger_.OnUpdateIds(invalidator_registrar_->GetSanitizedHandlersIdsMap()); | 142 logger_.OnUpdateIds(invalidator_registrar_->GetSanitizedHandlersIdsMap()); |
143 return true; | 143 return true; |
144 } | 144 } |
145 | 145 |
146 void TiclInvalidationService::UnregisterInvalidationHandler( | 146 void TiclInvalidationService::UnregisterInvalidationHandler( |
147 syncer::InvalidationHandler* handler) { | 147 syncer::InvalidationHandler* handler) { |
148 DCHECK(CalledOnValidThread()); | 148 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
149 DVLOG(2) << "Unregistering"; | 149 DVLOG(2) << "Unregistering"; |
150 invalidator_registrar_->UnregisterHandler(handler); | 150 invalidator_registrar_->UnregisterHandler(handler); |
151 if (invalidator_) { | 151 if (invalidator_) { |
152 CHECK(invalidator_->UpdateRegisteredIds( | 152 CHECK(invalidator_->UpdateRegisteredIds( |
153 this, invalidator_registrar_->GetAllRegisteredIds())); | 153 this, invalidator_registrar_->GetAllRegisteredIds())); |
154 } | 154 } |
155 logger_.OnUnregistration(handler->GetOwnerName()); | 155 logger_.OnUnregistration(handler->GetOwnerName()); |
156 } | 156 } |
157 | 157 |
158 syncer::InvalidatorState TiclInvalidationService::GetInvalidatorState() const { | 158 syncer::InvalidatorState TiclInvalidationService::GetInvalidatorState() const { |
159 DCHECK(CalledOnValidThread()); | 159 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
160 if (invalidator_) { | 160 if (invalidator_) { |
161 DVLOG(2) << "GetInvalidatorState returning " | 161 DVLOG(2) << "GetInvalidatorState returning " |
162 << invalidator_->GetInvalidatorState(); | 162 << invalidator_->GetInvalidatorState(); |
163 return invalidator_->GetInvalidatorState(); | 163 return invalidator_->GetInvalidatorState(); |
164 } else { | 164 } else { |
165 DVLOG(2) << "Invalidator currently stopped"; | 165 DVLOG(2) << "Invalidator currently stopped"; |
166 return syncer::TRANSIENT_INVALIDATION_ERROR; | 166 return syncer::TRANSIENT_INVALIDATION_ERROR; |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 std::string TiclInvalidationService::GetInvalidatorClientId() const { | 170 std::string TiclInvalidationService::GetInvalidatorClientId() const { |
171 DCHECK(CalledOnValidThread()); | 171 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
172 return invalidation_state_tracker_->GetInvalidatorClientId(); | 172 return invalidation_state_tracker_->GetInvalidatorClientId(); |
173 } | 173 } |
174 | 174 |
175 InvalidationLogger* TiclInvalidationService::GetInvalidationLogger() { | 175 InvalidationLogger* TiclInvalidationService::GetInvalidationLogger() { |
176 return &logger_; | 176 return &logger_; |
177 } | 177 } |
178 | 178 |
179 IdentityProvider* TiclInvalidationService::GetIdentityProvider() { | 179 IdentityProvider* TiclInvalidationService::GetIdentityProvider() { |
180 return identity_provider_.get(); | 180 return identity_provider_.get(); |
181 } | 181 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 342 |
343 return true; | 343 return true; |
344 } | 344 } |
345 | 345 |
346 bool TiclInvalidationService::IsStarted() const { | 346 bool TiclInvalidationService::IsStarted() const { |
347 return invalidator_.get() != NULL; | 347 return invalidator_.get() != NULL; |
348 } | 348 } |
349 | 349 |
350 void TiclInvalidationService::StartInvalidator( | 350 void TiclInvalidationService::StartInvalidator( |
351 InvalidationNetworkChannel network_channel) { | 351 InvalidationNetworkChannel network_channel) { |
352 DCHECK(CalledOnValidThread()); | 352 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
353 DCHECK(!invalidator_); | 353 DCHECK(!invalidator_); |
354 DCHECK(invalidation_state_tracker_); | 354 DCHECK(invalidation_state_tracker_); |
355 DCHECK(!invalidation_state_tracker_->GetInvalidatorClientId().empty()); | 355 DCHECK(!invalidation_state_tracker_->GetInvalidatorClientId().empty()); |
356 | 356 |
357 // Request access token for PushClientChannel. GCMNetworkChannel will request | 357 // Request access token for PushClientChannel. GCMNetworkChannel will request |
358 // access token before sending message to server. | 358 // access token before sending message to server. |
359 if (network_channel == PUSH_CLIENT_CHANNEL && access_token_.empty()) { | 359 if (network_channel == PUSH_CLIENT_CHANNEL && access_token_.empty()) { |
360 DVLOG(1) | 360 DVLOG(1) |
361 << "TiclInvalidationService: " | 361 << "TiclInvalidationService: " |
362 << "Deferring start until we have an access token."; | 362 << "Deferring start until we have an access token."; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } | 436 } |
437 | 437 |
438 void TiclInvalidationService::StopInvalidator() { | 438 void TiclInvalidationService::StopInvalidator() { |
439 DCHECK(invalidator_); | 439 DCHECK(invalidator_); |
440 gcm_invalidation_bridge_.reset(); | 440 gcm_invalidation_bridge_.reset(); |
441 invalidator_->UnregisterHandler(this); | 441 invalidator_->UnregisterHandler(this); |
442 invalidator_.reset(); | 442 invalidator_.reset(); |
443 } | 443 } |
444 | 444 |
445 } // namespace invalidation | 445 } // namespace invalidation |
OLD | NEW |