#include "base/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
-#if !defined(ANDROID)
+#if !defined(OS_ANDROID)
// channel_common.proto defines ANDROID constant that conflicts with Android
// build. At the same time TiclInvalidationService is not used on Android so it
// is safe to exclude these protos from Android build.
#include "google/cacheinvalidation/android_channel.pb.h"
#include "google/cacheinvalidation/channel_common.pb.h"
+#include "google/cacheinvalidation/types.pb.h"
#endif
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/http/http_status_code.h"
void RecordOutgoingMessageStatus(OutgoingMessageStatus status) {
UMA_HISTOGRAM_ENUMERATION(kOutgoingMessageStatusHistogram,
- MESSAGE_DISCARDED,
+ status,
OUTGOING_MESSAGE_STATUS_COUNT);
}
} // namespace
-GCMNetworkChannelDiagnostic::GCMNetworkChannelDiagnostic(
- GCMNetworkChannel* parent)
- : parent_(parent),
- last_message_empty_echo_token_(false),
- last_post_response_code_(0),
- registration_result_(gcm::GCMClient::UNKNOWN_ERROR),
- sent_messages_count_(0) {}
-
-scoped_ptr<base::DictionaryValue>
-GCMNetworkChannelDiagnostic::CollectDebugData() const {
- scoped_ptr<base::DictionaryValue> status(new base::DictionaryValue);
- status->SetString("GCMNetworkChannel.Channel", "GCM");
- std::string reg_id_hash = base::SHA1HashString(registration_id_);
- status->SetString("GCMNetworkChannel.HashedRegistrationID",
- base::HexEncode(reg_id_hash.c_str(), reg_id_hash.size()));
- status->SetString("GCMNetworkChannel.RegistrationResult",
- GCMClientResultToString(registration_result_));
- status->SetBoolean("GCMNetworkChannel.HadLastMessageEmptyEchoToken",
- last_message_empty_echo_token_);
- status->SetString(
- "GCMNetworkChannel.LastMessageReceivedTime",
- base::TimeFormatShortDateAndTime(last_message_received_time_));
- status->SetInteger("GCMNetworkChannel.LastPostResponseCode",
- last_post_response_code_);
- status->SetInteger("GCMNetworkChannel.SentMessages", sent_messages_count_);
- status->SetInteger("GCMNetworkChannel.ReceivedMessages",
- parent_->GetReceivedMessagesCount());
- return status.Pass();
-}
-
-std::string GCMNetworkChannelDiagnostic::GCMClientResultToString(
- const gcm::GCMClient::Result result) const {
-#define ENUM_CASE(x) case x: return #x; break;
- switch (result) {
- ENUM_CASE(gcm::GCMClient::SUCCESS);
- ENUM_CASE(gcm::GCMClient::NETWORK_ERROR);
- ENUM_CASE(gcm::GCMClient::SERVER_ERROR);
- ENUM_CASE(gcm::GCMClient::TTL_EXCEEDED);
- ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR);
- ENUM_CASE(gcm::GCMClient::NOT_SIGNED_IN);
- ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER);
- ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING);
- }
- NOTREACHED();
- return "";
-}
-
GCMNetworkChannel::GCMNetworkChannel(
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
scoped_ptr<GCMNetworkChannelDelegate> delegate)
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
}
-void GCMNetworkChannel::UpdateCredentials(
- const std::string& email,
- const std::string& token) {
- // Do nothing. We get access token by requesting it for every message.
-}
-
-void GCMNetworkChannel::RequestDetailedStatus(
- base::Callback<void(const base::DictionaryValue&)> callback) {
- callback.Run(*diagnostic_info_.CollectDebugData());
-}
-
-void GCMNetworkChannel::ResetRegisterBackoffEntryForTest(
- const net::BackoffEntry::Policy* policy) {
- register_backoff_entry_.reset(new net::BackoffEntry(policy));
-}
-
void GCMNetworkChannel::Register() {
delegate_->Register(base::Bind(&GCMNetworkChannel::OnRegisterComplete,
weak_factory_.GetWeakPtr()));
}
}
-void GCMNetworkChannel::SetMessageReceiver(
- invalidation::MessageCallback* incoming_receiver) {
- delegate_->SetMessageReceiver(base::Bind(
- &GCMNetworkChannel::OnIncomingMessage, weak_factory_.GetWeakPtr()));
- SyncNetworkChannel::SetMessageReceiver(incoming_receiver);
-}
-
void GCMNetworkChannel::RequestAccessToken() {
DCHECK(CalledOnValidThread());
delegate_->RequestToken(base::Bind(&GCMNetworkChannel::OnGetTokenComplete,
cached_message_.clear();
}
+void GCMNetworkChannel::OnURLFetchComplete(const net::URLFetcher* source) {
+ DCHECK(CalledOnValidThread());
+ DCHECK_EQ(fetcher_, source);
+ // Free fetcher at the end of function.
+ scoped_ptr<net::URLFetcher> fetcher = fetcher_.Pass();
+
+ net::URLRequestStatus status = fetcher->GetStatus();
+ diagnostic_info_.last_post_response_code_ =
+ status.is_success() ? source->GetResponseCode() : status.error();
+
+ if (status.is_success() &&
+ fetcher->GetResponseCode() == net::HTTP_UNAUTHORIZED) {
+ DVLOG(1) << "URLFetcher failure: HTTP_UNAUTHORIZED";
+ delegate_->InvalidateToken(access_token_);
+ }
+
+ if (!status.is_success() ||
+ (fetcher->GetResponseCode() != net::HTTP_OK &&
+ fetcher->GetResponseCode() != net::HTTP_NO_CONTENT)) {
+ DVLOG(1) << "URLFetcher failure";
+ RecordOutgoingMessageStatus(POST_FAILURE);
+ NotifyStateChange(TRANSIENT_INVALIDATION_ERROR);
+ return;
+ }
+
+ RecordOutgoingMessageStatus(OUTGOING_MESSAGE_SUCCESS);
+ NotifyStateChange(INVALIDATIONS_ENABLED);
+ DVLOG(2) << "URLFetcher success";
+}
+
void GCMNetworkChannel::OnIncomingMessage(const std::string& message,
const std::string& echo_token) {
-#if !defined(ANDROID)
+#if !defined(OS_ANDROID)
if (!echo_token.empty())
echo_token_ = echo_token;
diagnostic_info_.last_message_empty_echo_token_ = echo_token.empty();
#endif
}
-void GCMNetworkChannel::OnURLFetchComplete(const net::URLFetcher* source) {
- DCHECK(CalledOnValidThread());
- DCHECK_EQ(fetcher_, source);
- // Free fetcher at the end of function.
- scoped_ptr<net::URLFetcher> fetcher = fetcher_.Pass();
-
- net::URLRequestStatus status = fetcher->GetStatus();
- diagnostic_info_.last_post_response_code_ =
- status.is_success() ? source->GetResponseCode() : status.error();
-
- if (status.is_success() &&
- fetcher->GetResponseCode() == net::HTTP_UNAUTHORIZED) {
- DVLOG(1) << "URLFetcher failure: HTTP_UNAUTHORIZED";
- delegate_->InvalidateToken(access_token_);
- }
-
- if (!status.is_success() ||
- (fetcher->GetResponseCode() != net::HTTP_OK &&
- fetcher->GetResponseCode() != net::HTTP_NO_CONTENT)) {
- DVLOG(1) << "URLFetcher failure";
- RecordOutgoingMessageStatus(POST_FAILURE);
- NotifyStateChange(TRANSIENT_INVALIDATION_ERROR);
- return;
- }
-
- RecordOutgoingMessageStatus(OUTGOING_MESSAGE_SUCCESS);
- NotifyStateChange(INVALIDATIONS_ENABLED);
- DVLOG(2) << "URLFetcher success";
-}
-
void GCMNetworkChannel::OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType connection_type) {
// Network connection is restored. Let's notify cacheinvalidations so it has
GURL GCMNetworkChannel::BuildUrl(const std::string& registration_id) {
DCHECK(!registration_id.empty());
-#if !defined(ANDROID)
+#if !defined(OS_ANDROID)
ipc::invalidation::EndpointId endpoint_id;
endpoint_id.set_c2dm_registration_id(registration_id);
endpoint_id.set_client_key(std::string());
return base::Base64Decode(padded_input, output);
}
+void GCMNetworkChannel::SetMessageReceiver(
+ invalidation::MessageCallback* incoming_receiver) {
+ delegate_->SetMessageReceiver(base::Bind(
+ &GCMNetworkChannel::OnIncomingMessage, weak_factory_.GetWeakPtr()));
+ SyncNetworkChannel::SetMessageReceiver(incoming_receiver);
+}
+
+void GCMNetworkChannel::RequestDetailedStatus(
+ base::Callback<void(const base::DictionaryValue&)> callback) {
+ callback.Run(*diagnostic_info_.CollectDebugData());
+}
+
+void GCMNetworkChannel::UpdateCredentials(const std::string& email,
+ const std::string& token) {
+ // Do nothing. We get access token by requesting it for every message.
+}
+
+int GCMNetworkChannel::GetInvalidationClientType() {
+#if defined(OS_IOS)
+ return ipc::invalidation::ClientType::CHROME_SYNC_GCM_IOS;
+#else
+ return ipc::invalidation::ClientType::CHROME_SYNC_GCM_DESKTOP;
+#endif
+}
+
+void GCMNetworkChannel::ResetRegisterBackoffEntryForTest(
+ const net::BackoffEntry::Policy* policy) {
+ register_backoff_entry_.reset(new net::BackoffEntry(policy));
+}
+
+GCMNetworkChannelDiagnostic::GCMNetworkChannelDiagnostic(
+ GCMNetworkChannel* parent)
+ : parent_(parent),
+ last_message_empty_echo_token_(false),
+ last_post_response_code_(0),
+ registration_result_(gcm::GCMClient::UNKNOWN_ERROR),
+ sent_messages_count_(0) {}
+
+scoped_ptr<base::DictionaryValue>
+GCMNetworkChannelDiagnostic::CollectDebugData() const {
+ scoped_ptr<base::DictionaryValue> status(new base::DictionaryValue);
+ status->SetString("GCMNetworkChannel.Channel", "GCM");
+ std::string reg_id_hash = base::SHA1HashString(registration_id_);
+ status->SetString("GCMNetworkChannel.HashedRegistrationID",
+ base::HexEncode(reg_id_hash.c_str(), reg_id_hash.size()));
+ status->SetString("GCMNetworkChannel.RegistrationResult",
+ GCMClientResultToString(registration_result_));
+ status->SetBoolean("GCMNetworkChannel.HadLastMessageEmptyEchoToken",
+ last_message_empty_echo_token_);
+ status->SetString(
+ "GCMNetworkChannel.LastMessageReceivedTime",
+ base::TimeFormatShortDateAndTime(last_message_received_time_));
+ status->SetInteger("GCMNetworkChannel.LastPostResponseCode",
+ last_post_response_code_);
+ status->SetInteger("GCMNetworkChannel.SentMessages", sent_messages_count_);
+ status->SetInteger("GCMNetworkChannel.ReceivedMessages",
+ parent_->GetReceivedMessagesCount());
+ return status.Pass();
+}
+
+std::string GCMNetworkChannelDiagnostic::GCMClientResultToString(
+ const gcm::GCMClient::Result result) const {
+#define ENUM_CASE(x) case x: return #x; break;
+ switch (result) {
+ ENUM_CASE(gcm::GCMClient::SUCCESS);
+ ENUM_CASE(gcm::GCMClient::NETWORK_ERROR);
+ ENUM_CASE(gcm::GCMClient::SERVER_ERROR);
+ ENUM_CASE(gcm::GCMClient::TTL_EXCEEDED);
+ ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR);
+ ENUM_CASE(gcm::GCMClient::NOT_SIGNED_IN);
+ ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER);
+ ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING);
+ }
+ NOTREACHED();
+ return "";
+}
+
} // namespace syncer