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

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

Issue 270873002: Extract GCMClient data types into separate gcm_types.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reupload Created 6 years, 7 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
« no previous file with comments | « sync/notifier/gcm_network_channel.h ('k') | sync/notifier/gcm_network_channel_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/i18n/time_formatting.h" 6 #include "base/i18n/time_formatting.h"
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/sha1.h" 8 #include "base/sha1.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); 118 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
119 } 119 }
120 120
121 void GCMNetworkChannel::Register() { 121 void GCMNetworkChannel::Register() {
122 delegate_->Register(base::Bind(&GCMNetworkChannel::OnRegisterComplete, 122 delegate_->Register(base::Bind(&GCMNetworkChannel::OnRegisterComplete,
123 weak_factory_.GetWeakPtr())); 123 weak_factory_.GetWeakPtr()));
124 } 124 }
125 125
126 void GCMNetworkChannel::OnRegisterComplete( 126 void GCMNetworkChannel::OnRegisterComplete(
127 const std::string& registration_id, 127 const std::string& registration_id,
128 gcm::GCMClient::Result result) { 128 gcm::Result result) {
129 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
130 if (result == gcm::GCMClient::SUCCESS) { 130 if (result == gcm::RESULT_SUCCESS) {
131 DCHECK(!registration_id.empty()); 131 DCHECK(!registration_id.empty());
132 DVLOG(2) << "Got registration_id"; 132 DVLOG(2) << "Got registration_id";
133 register_backoff_entry_->Reset(); 133 register_backoff_entry_->Reset();
134 registration_id_ = registration_id; 134 registration_id_ = registration_id;
135 if (!cached_message_.empty()) 135 if (!cached_message_.empty())
136 RequestAccessToken(); 136 RequestAccessToken();
137 } else { 137 } else {
138 DVLOG(2) << "Register failed: " << result; 138 DVLOG(2) << "Register failed: " << result;
139 // Retry in case of transient error. 139 // Retry in case of transient error.
140 switch (result) { 140 switch (result) {
141 case gcm::GCMClient::NETWORK_ERROR: 141 case gcm::RESULT_NETWORK_ERROR:
142 case gcm::GCMClient::SERVER_ERROR: 142 case gcm::RESULT_SERVER_ERROR:
143 case gcm::GCMClient::TTL_EXCEEDED: 143 case gcm::RESULT_TTL_EXCEEDED:
144 case gcm::GCMClient::UNKNOWN_ERROR: { 144 case gcm::RESULT_UNKNOWN_ERROR: {
145 register_backoff_entry_->InformOfRequest(false); 145 register_backoff_entry_->InformOfRequest(false);
146 base::MessageLoop::current()->PostDelayedTask( 146 base::MessageLoop::current()->PostDelayedTask(
147 FROM_HERE, 147 FROM_HERE,
148 base::Bind(&GCMNetworkChannel::Register, 148 base::Bind(&GCMNetworkChannel::Register,
149 weak_factory_.GetWeakPtr()), 149 weak_factory_.GetWeakPtr()),
150 register_backoff_entry_->GetTimeUntilRelease()); 150 register_backoff_entry_->GetTimeUntilRelease());
151 break; 151 break;
152 } 152 }
153 default: 153 default:
154 break; 154 break;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 void GCMNetworkChannel::ResetRegisterBackoffEntryForTest( 377 void GCMNetworkChannel::ResetRegisterBackoffEntryForTest(
378 const net::BackoffEntry::Policy* policy) { 378 const net::BackoffEntry::Policy* policy) {
379 register_backoff_entry_.reset(new net::BackoffEntry(policy)); 379 register_backoff_entry_.reset(new net::BackoffEntry(policy));
380 } 380 }
381 381
382 GCMNetworkChannelDiagnostic::GCMNetworkChannelDiagnostic( 382 GCMNetworkChannelDiagnostic::GCMNetworkChannelDiagnostic(
383 GCMNetworkChannel* parent) 383 GCMNetworkChannel* parent)
384 : parent_(parent), 384 : parent_(parent),
385 last_message_empty_echo_token_(false), 385 last_message_empty_echo_token_(false),
386 last_post_response_code_(0), 386 last_post_response_code_(0),
387 registration_result_(gcm::GCMClient::UNKNOWN_ERROR), 387 registration_result_(gcm::RESULT_UNKNOWN_ERROR),
388 sent_messages_count_(0) {} 388 sent_messages_count_(0) {}
389 389
390 scoped_ptr<base::DictionaryValue> 390 scoped_ptr<base::DictionaryValue>
391 GCMNetworkChannelDiagnostic::CollectDebugData() const { 391 GCMNetworkChannelDiagnostic::CollectDebugData() const {
392 scoped_ptr<base::DictionaryValue> status(new base::DictionaryValue); 392 scoped_ptr<base::DictionaryValue> status(new base::DictionaryValue);
393 status->SetString("GCMNetworkChannel.Channel", "GCM"); 393 status->SetString("GCMNetworkChannel.Channel", "GCM");
394 std::string reg_id_hash = base::SHA1HashString(registration_id_); 394 std::string reg_id_hash = base::SHA1HashString(registration_id_);
395 status->SetString("GCMNetworkChannel.HashedRegistrationID", 395 status->SetString("GCMNetworkChannel.HashedRegistrationID",
396 base::HexEncode(reg_id_hash.c_str(), reg_id_hash.size())); 396 base::HexEncode(reg_id_hash.c_str(), reg_id_hash.size()));
397 status->SetString("GCMNetworkChannel.RegistrationResult", 397 status->SetString("GCMNetworkChannel.RegistrationResult",
398 GCMClientResultToString(registration_result_)); 398 GCMClientResultToString(registration_result_));
399 status->SetBoolean("GCMNetworkChannel.HadLastMessageEmptyEchoToken", 399 status->SetBoolean("GCMNetworkChannel.HadLastMessageEmptyEchoToken",
400 last_message_empty_echo_token_); 400 last_message_empty_echo_token_);
401 status->SetString( 401 status->SetString(
402 "GCMNetworkChannel.LastMessageReceivedTime", 402 "GCMNetworkChannel.LastMessageReceivedTime",
403 base::TimeFormatShortDateAndTime(last_message_received_time_)); 403 base::TimeFormatShortDateAndTime(last_message_received_time_));
404 status->SetInteger("GCMNetworkChannel.LastPostResponseCode", 404 status->SetInteger("GCMNetworkChannel.LastPostResponseCode",
405 last_post_response_code_); 405 last_post_response_code_);
406 status->SetInteger("GCMNetworkChannel.SentMessages", sent_messages_count_); 406 status->SetInteger("GCMNetworkChannel.SentMessages", sent_messages_count_);
407 status->SetInteger("GCMNetworkChannel.ReceivedMessages", 407 status->SetInteger("GCMNetworkChannel.ReceivedMessages",
408 parent_->GetReceivedMessagesCount()); 408 parent_->GetReceivedMessagesCount());
409 return status.Pass(); 409 return status.Pass();
410 } 410 }
411 411
412 std::string GCMNetworkChannelDiagnostic::GCMClientResultToString( 412 std::string GCMNetworkChannelDiagnostic::GCMClientResultToString(
413 const gcm::GCMClient::Result result) const { 413 const gcm::Result result) const {
414 #define ENUM_CASE(x) case x: return #x; break; 414 #define ENUM_CASE(x) case x: return #x; break;
415 switch (result) { 415 switch (result) {
416 ENUM_CASE(gcm::GCMClient::SUCCESS); 416 ENUM_CASE(gcm::RESULT_SUCCESS);
417 ENUM_CASE(gcm::GCMClient::NETWORK_ERROR); 417 ENUM_CASE(gcm::RESULT_NETWORK_ERROR);
418 ENUM_CASE(gcm::GCMClient::SERVER_ERROR); 418 ENUM_CASE(gcm::RESULT_SERVER_ERROR);
419 ENUM_CASE(gcm::GCMClient::TTL_EXCEEDED); 419 ENUM_CASE(gcm::RESULT_TTL_EXCEEDED);
420 ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR); 420 ENUM_CASE(gcm::RESULT_UNKNOWN_ERROR);
421 ENUM_CASE(gcm::GCMClient::NOT_SIGNED_IN); 421 ENUM_CASE(gcm::RESULT_NOT_SIGNED_IN);
422 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER); 422 ENUM_CASE(gcm::RESULT_INVALID_PARAMETER);
423 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING); 423 ENUM_CASE(gcm::RESULT_ASYNC_OPERATION_PENDING);
424 } 424 }
425 NOTREACHED(); 425 NOTREACHED();
426 return ""; 426 return "";
427 } 427 }
428 428
429 } // namespace syncer 429 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/gcm_network_channel.h ('k') | sync/notifier/gcm_network_channel_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698