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

Side by Side Diff: components/invalidation/impl/gcm_network_channel.cc

Issue 2473813002: Notify GCMAppHandlers when the store is reset, so they clear cached IDs (Closed)
Patch Set: Update Cryptauth comment Created 4 years, 1 month 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
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/gcm_network_channel.h" 5 #include "components/invalidation/impl/gcm_network_channel.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64url.h" 9 #include "base/base64url.h"
10 #include "base/i18n/time_formatting.h" 10 #include "base/i18n/time_formatting.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 scoped_refptr<net::URLRequestContextGetter> request_context_getter, 114 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
115 std::unique_ptr<GCMNetworkChannelDelegate> delegate) 115 std::unique_ptr<GCMNetworkChannelDelegate> delegate)
116 : request_context_getter_(request_context_getter), 116 : request_context_getter_(request_context_getter),
117 delegate_(std::move(delegate)), 117 delegate_(std::move(delegate)),
118 register_backoff_entry_(new net::BackoffEntry(&kRegisterBackoffPolicy)), 118 register_backoff_entry_(new net::BackoffEntry(&kRegisterBackoffPolicy)),
119 gcm_channel_online_(false), 119 gcm_channel_online_(false),
120 http_channel_online_(false), 120 http_channel_online_(false),
121 diagnostic_info_(this), 121 diagnostic_info_(this),
122 weak_factory_(this) { 122 weak_factory_(this) {
123 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 123 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
124 delegate_->Initialize(base::Bind(&GCMNetworkChannel::OnConnectionStateChanged, 124 delegate_->Initialize(
125 weak_factory_.GetWeakPtr())); 125 base::Bind(&GCMNetworkChannel::OnConnectionStateChanged,
126 weak_factory_.GetWeakPtr()),
127 base::Bind(&GCMNetworkChannel::OnStoreReset, weak_factory_.GetWeakPtr()));
126 Register(); 128 Register();
127 } 129 }
128 130
129 GCMNetworkChannel::~GCMNetworkChannel() { 131 GCMNetworkChannel::~GCMNetworkChannel() {
130 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 132 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
131 } 133 }
132 134
133 void GCMNetworkChannel::Register() { 135 void GCMNetworkChannel::Register() {
134 delegate_->Register(base::Bind(&GCMNetworkChannel::OnRegisterComplete, 136 delegate_->Register(base::Bind(&GCMNetworkChannel::OnRegisterComplete,
135 weak_factory_.GetWeakPtr())); 137 weak_factory_.GetWeakPtr()));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 void GCMNetworkChannel::RequestAccessToken() { 189 void GCMNetworkChannel::RequestAccessToken() {
188 DCHECK(CalledOnValidThread()); 190 DCHECK(CalledOnValidThread());
189 delegate_->RequestToken(base::Bind(&GCMNetworkChannel::OnGetTokenComplete, 191 delegate_->RequestToken(base::Bind(&GCMNetworkChannel::OnGetTokenComplete,
190 weak_factory_.GetWeakPtr())); 192 weak_factory_.GetWeakPtr()));
191 } 193 }
192 194
193 void GCMNetworkChannel::OnGetTokenComplete( 195 void GCMNetworkChannel::OnGetTokenComplete(
194 const GoogleServiceAuthError& error, 196 const GoogleServiceAuthError& error,
195 const std::string& token) { 197 const std::string& token) {
196 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
197 if (cached_message_.empty()) { 199 if (cached_message_.empty() || registration_id_.empty()) {
198 // Nothing to do. 200 // Nothing to do.
199 return; 201 return;
200 } 202 }
201 203
202 if (error.state() != GoogleServiceAuthError::NONE) { 204 if (error.state() != GoogleServiceAuthError::NONE) {
203 // Requesting access token failed. Persistent errors will be reported by 205 // Requesting access token failed. Persistent errors will be reported by
204 // token service. Just drop this request, cacheinvalidations will retry 206 // token service. Just drop this request, cacheinvalidations will retry
205 // sending message and at that time we'll retry requesting access token. 207 // sending message and at that time we'll retry requesting access token.
206 DVLOG(1) << "RequestAccessToken failed: " << error.ToString(); 208 DVLOG(1) << "RequestAccessToken failed: " << error.ToString();
207 RecordOutgoingMessageStatus(ACCESS_TOKEN_FAILURE); 209 RecordOutgoingMessageStatus(ACCESS_TOKEN_FAILURE);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 #else 297 #else
296 // This code shouldn't be invoked on Android. 298 // This code shouldn't be invoked on Android.
297 NOTREACHED(); 299 NOTREACHED();
298 #endif 300 #endif
299 } 301 }
300 302
301 void GCMNetworkChannel::OnConnectionStateChanged(bool online) { 303 void GCMNetworkChannel::OnConnectionStateChanged(bool online) {
302 UpdateGcmChannelState(online); 304 UpdateGcmChannelState(online);
303 } 305 }
304 306
307 void GCMNetworkChannel::OnStoreReset() {
308 // TODO(crbug.com/661660): Tell server the registration ID is no longer valid.
309 registration_id_.clear();
310 }
311
305 void GCMNetworkChannel::OnNetworkChanged( 312 void GCMNetworkChannel::OnNetworkChanged(
306 net::NetworkChangeNotifier::ConnectionType connection_type) { 313 net::NetworkChangeNotifier::ConnectionType connection_type) {
307 // Network connection is restored. Let's notify cacheinvalidations so it has 314 // Network connection is restored. Let's notify cacheinvalidations so it has
308 // chance to retry. 315 // chance to retry.
309 NotifyNetworkStatusChange( 316 NotifyNetworkStatusChange(
310 connection_type != net::NetworkChangeNotifier::CONNECTION_NONE); 317 connection_type != net::NetworkChangeNotifier::CONNECTION_NONE);
311 } 318 }
312 319
313 void GCMNetworkChannel::UpdateGcmChannelState(bool online) { 320 void GCMNetworkChannel::UpdateGcmChannelState(bool online) {
314 if (gcm_channel_online_ == online) 321 if (gcm_channel_online_ == online)
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR); 443 ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR);
437 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER); 444 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER);
438 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING); 445 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING);
439 ENUM_CASE(gcm::GCMClient::GCM_DISABLED); 446 ENUM_CASE(gcm::GCMClient::GCM_DISABLED);
440 } 447 }
441 NOTREACHED(); 448 NOTREACHED();
442 return ""; 449 return "";
443 } 450 }
444 451
445 } // namespace syncer 452 } // namespace syncer
OLDNEW
« no previous file with comments | « components/invalidation/impl/gcm_network_channel.h ('k') | components/invalidation/impl/gcm_network_channel_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698