diff options
author | mvanouwerkerk <mvanouwerkerk@chromium.org> | 2015-07-13 04:04:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-13 11:04:50 +0000 |
commit | f8633deb9da835a863a5f77bdc1c52ee701d8ae2 (patch) | |
tree | ff01f7e933c522cfd797efb19dc3c4816db995ec /components | |
parent | ae428c2d3e3db2875b7c089db367d7f0caf077ac (diff) | |
download | chromium_src-f8633deb9da835a863a5f77bdc1c52ee701d8ae2.zip chromium_src-f8633deb9da835a863a5f77bdc1c52ee701d8ae2.tar.gz chromium_src-f8633deb9da835a863a5f77bdc1c52ee701d8ae2.tar.bz2 |
GCM: refactor IncomingMessaging and OutgoingMessage.
This will allow them to be used in:
chrome/common/service_messages.h
* Make them top level classes.
* Move IncomingMessage and OutgoingMessage to their own file
* Depend on this through the gcm_driver_common component
* Export them
BUG=402456
Design document: https://goo.gl/LRdGTm
Review URL: https://codereview.chromium.org/1210073006
Cr-Commit-Position: refs/heads/master@{#338494}
Diffstat (limited to 'components')
34 files changed, 206 insertions, 131 deletions
diff --git a/components/copresence/handlers/gcm_handler_impl.cc b/components/copresence/handlers/gcm_handler_impl.cc index 5b50e2f..362b535 100644 --- a/components/copresence/handlers/gcm_handler_impl.cc +++ b/components/copresence/handlers/gcm_handler_impl.cc @@ -78,7 +78,7 @@ void GCMHandlerImpl::ShutdownHandler() { } void GCMHandlerImpl::OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) { + const gcm::IncomingMessage& message) { DCHECK_EQ(kCopresenceAppId, app_id); DVLOG(2) << "Incoming GCM message"; diff --git a/components/copresence/handlers/gcm_handler_impl.h b/components/copresence/handlers/gcm_handler_impl.h index cc81f03..d193eb8 100644 --- a/components/copresence/handlers/gcm_handler_impl.h +++ b/components/copresence/handlers/gcm_handler_impl.h @@ -51,7 +51,7 @@ class GCMHandlerImpl final : public GCMHandler, // GCMAppHandler overrides void ShutdownHandler() override; void OnMessage(const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) override; + const gcm::IncomingMessage& message) override; void OnMessagesDeleted(const std::string& app_id) override; void OnSendError( const std::string& /* app_id */, diff --git a/components/copresence/handlers/gcm_handler_unittest.cc b/components/copresence/handlers/gcm_handler_unittest.cc index eec6c77..39a873bf 100644 --- a/components/copresence/handlers/gcm_handler_unittest.cc +++ b/components/copresence/handlers/gcm_handler_unittest.cc @@ -12,8 +12,6 @@ #include "components/gcm_driver/gcm_client.h" #include "testing/gmock/include/gmock/gmock.h" -using gcm::GCMClient; - namespace copresence { namespace { @@ -43,7 +41,7 @@ class GCMHandlerTest : public testing::Test { } protected: - void ProcessMessage(const GCMClient::IncomingMessage& message) { + void ProcessMessage(const gcm::IncomingMessage& message) { gcm_handler_.OnMessage(GCMHandlerImpl::kCopresenceAppId, message); } @@ -67,7 +65,7 @@ TEST_F(GCMHandlerTest, OnMessage) { base::Base64Encode(serialized_proto, &encoded_proto); // Send it in a GCM message. - GCMClient::IncomingMessage gcm_message; + gcm::IncomingMessage gcm_message; gcm_message.data[GCMHandlerImpl::kGcmMessageKey] = ToUrlSafe(encoded_proto); ProcessMessage(gcm_message); diff --git a/components/gcm_driver.gypi b/components/gcm_driver.gypi index a52086c..bb9a64d 100644 --- a/components/gcm_driver.gypi +++ b/components/gcm_driver.gypi @@ -5,6 +5,23 @@ { 'targets': [ { + # GN version: //components/gcm_driver:common + 'target_name': 'gcm_driver_common', + 'type': '<(component)', + 'include_dirs': [ + '..', + ], + 'defines': [ + 'GCM_DRIVER_IMPLEMENTATION', + ], + 'sources': [ + # Note: file list duplicated in GN build. + 'gcm_driver/common/gcm_driver_export.h', + 'gcm_driver/common/gcm_messages.cc', + 'gcm_driver/common/gcm_messages.h', + ], + }, + { # GN version: //components/gcm_driver 'target_name': 'gcm_driver', 'type': 'static_library', @@ -14,6 +31,7 @@ '../google_apis/gcm/gcm.gyp:gcm', '../net/net.gyp:net', '../sync/sync.gyp:sync_proto', + 'gcm_driver_common', ], 'include_dirs': [ '..', diff --git a/components/gcm_driver/BUILD.gn b/components/gcm_driver/BUILD.gn index 2b47118..e4ecdc8 100644 --- a/components/gcm_driver/BUILD.gn +++ b/components/gcm_driver/BUILD.gn @@ -2,6 +2,17 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +# GYP version: components/gcm_driver.gypi:gcm_driver_common +component("common") { + sources = [ + "common/gcm_driver_export.h", + "common/gcm_messages.cc", + "common/gcm_messages.h", + ] + + defines = [ "GCM_DRIVER_IMPLEMENTATION" ] +} + # GYP version: components/gcm_driver.gypi:gcm_driver static_library("gcm_driver") { sources = [ @@ -51,6 +62,7 @@ static_library("gcm_driver") { "//google_apis/gcm", "//net", "//sync/protocol", + ":common", ] if (is_chromeos) { diff --git a/components/gcm_driver/common/gcm_driver_export.h b/components/gcm_driver/common/gcm_driver_export.h new file mode 100644 index 0000000..5809ea34 --- /dev/null +++ b/components/gcm_driver/common/gcm_driver_export.h @@ -0,0 +1,29 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_GCM_DRIVER_COMMON_GCM_DRIVER_EXPORT_H_ +#define COMPONENTS_GCM_DRIVER_COMMON_GCM_DRIVER_EXPORT_H_ + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(GCM_DRIVER_IMPLEMENTATION) +#define GCM_DRIVER_EXPORT __declspec(dllexport) +#else +#define GCM_DRIVER_EXPORT __declspec(dllimport) +#endif // defined(GCM_DRIVER_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(GCM_DRIVER_IMPLEMENTATION) +#define GCM_DRIVER_EXPORT __attribute__((visibility("default"))) +#else +#define GCM_DRIVER_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define GCM_DRIVER_EXPORT +#endif + +#endif // COMPONENTS_GCM_DRIVER_COMMON_GCM_DRIVER_EXPORT_H_ diff --git a/components/gcm_driver/common/gcm_messages.cc b/components/gcm_driver/common/gcm_messages.cc new file mode 100644 index 0000000..0d44fce --- /dev/null +++ b/components/gcm_driver/common/gcm_messages.cc @@ -0,0 +1,24 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/gcm_driver/common/gcm_messages.h" + +namespace gcm { + +// static +const int OutgoingMessage::kMaximumTTL = 24 * 60 * 60; // 1 day. + +OutgoingMessage::OutgoingMessage() : time_to_live(kMaximumTTL) { +} + +OutgoingMessage::~OutgoingMessage() { +} + +IncomingMessage::IncomingMessage() { +} + +IncomingMessage::~IncomingMessage() { +} + +} // namespace gcm diff --git a/components/gcm_driver/common/gcm_messages.h b/components/gcm_driver/common/gcm_messages.h new file mode 100644 index 0000000..21555d3 --- /dev/null +++ b/components/gcm_driver/common/gcm_messages.h @@ -0,0 +1,44 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_GCM_DRIVER_COMMON_GCM_MESSAGES_H_ +#define COMPONENTS_GCM_DRIVER_COMMON_GCM_MESSAGES_H_ + +#include <map> +#include <string> + +#include "components/gcm_driver/common/gcm_driver_export.h" + +namespace gcm { + +// Message data consisting of key-value pairs. +typedef std::map<std::string, std::string> MessageData; + +// Message to be delivered to the other party. +struct GCM_DRIVER_EXPORT OutgoingMessage { + OutgoingMessage(); + ~OutgoingMessage(); + + // Message ID. + std::string id; + // In seconds. + int time_to_live; + MessageData data; + + static const int kMaximumTTL; +}; + +// Message being received from the other party. +struct GCM_DRIVER_EXPORT IncomingMessage { + IncomingMessage(); + ~IncomingMessage(); + + MessageData data; + std::string collapse_key; + std::string sender_id; +}; + +} // namespace gcm + +#endif // COMPONENTS_GCM_DRIVER_COMMON_GCM_MESSAGES_H_ diff --git a/components/gcm_driver/default_gcm_app_handler.cc b/components/gcm_driver/default_gcm_app_handler.cc index 07fc6e6..f1d4fba 100644 --- a/components/gcm_driver/default_gcm_app_handler.cc +++ b/components/gcm_driver/default_gcm_app_handler.cc @@ -18,9 +18,8 @@ void DefaultGCMAppHandler::ShutdownHandler() { // Nothing to do. } -void DefaultGCMAppHandler::OnMessage( - const std::string& app_id, - const GCMClient::IncomingMessage& message) { +void DefaultGCMAppHandler::OnMessage(const std::string& app_id, + const IncomingMessage& message) { DVLOG(1) << "No app handler is found to route message for " << app_id; } diff --git a/components/gcm_driver/default_gcm_app_handler.h b/components/gcm_driver/default_gcm_app_handler.h index bfe76a11..2e3d5f0 100644 --- a/components/gcm_driver/default_gcm_app_handler.h +++ b/components/gcm_driver/default_gcm_app_handler.h @@ -20,7 +20,7 @@ class DefaultGCMAppHandler : public GCMAppHandler { // Overridden from GCMAppHandler: void ShutdownHandler() override; void OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) override; + const IncomingMessage& message) override; void OnMessagesDeleted(const std::string& app_id) override; void OnSendError( const std::string& app_id, diff --git a/components/gcm_driver/fake_gcm_app_handler.cc b/components/gcm_driver/fake_gcm_app_handler.cc index 3ac6b08..14a43f2 100644 --- a/components/gcm_driver/fake_gcm_app_handler.cc +++ b/components/gcm_driver/fake_gcm_app_handler.cc @@ -25,7 +25,7 @@ void FakeGCMAppHandler::ShutdownHandler() { } void FakeGCMAppHandler::OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) { + const IncomingMessage& message) { ClearResults(); received_event_ = MESSAGE_EVENT; app_id_ = app_id; @@ -67,7 +67,7 @@ void FakeGCMAppHandler::ClearResults() { received_event_ = NO_EVENT; app_id_.clear(); acked_message_id_.clear(); - message_ = GCMClient::IncomingMessage(); + message_ = IncomingMessage(); send_error_details_ = GCMClient::SendErrorDetails(); } diff --git a/components/gcm_driver/fake_gcm_app_handler.h b/components/gcm_driver/fake_gcm_app_handler.h index 29fcd29..11b9257 100644 --- a/components/gcm_driver/fake_gcm_app_handler.h +++ b/components/gcm_driver/fake_gcm_app_handler.h @@ -30,7 +30,7 @@ class FakeGCMAppHandler : public GCMAppHandler { const Event& received_event() const { return received_event_; } const std::string& app_id() const { return app_id_; } const std::string& acked_message_id() const { return acked_message_id_; } - const GCMClient::IncomingMessage& message() const { return message_; } + const IncomingMessage& message() const { return message_; } const GCMClient::SendErrorDetails& send_error_details() const { return send_error_details_; } @@ -40,7 +40,7 @@ class FakeGCMAppHandler : public GCMAppHandler { // GCMAppHandler implementation. void ShutdownHandler() override; void OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) override; + const IncomingMessage& message) override; void OnMessagesDeleted(const std::string& app_id) override; void OnSendError( const std::string& app_id, @@ -56,7 +56,7 @@ class FakeGCMAppHandler : public GCMAppHandler { Event received_event_; std::string app_id_; std::string acked_message_id_; - GCMClient::IncomingMessage message_; + IncomingMessage message_; GCMClient::SendErrorDetails send_error_details_; DISALLOW_COPY_AND_ASSIGN(FakeGCMAppHandler); diff --git a/components/gcm_driver/fake_gcm_driver.cc b/components/gcm_driver/fake_gcm_driver.cc index dfdd918..8572e83 100644 --- a/components/gcm_driver/fake_gcm_driver.cc +++ b/components/gcm_driver/fake_gcm_driver.cc @@ -74,7 +74,7 @@ void FakeGCMDriver::UnregisterImpl(const std::string& app_id) { void FakeGCMDriver::SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) { + const OutgoingMessage& message) { } void FakeGCMDriver::SetAccountTokens( diff --git a/components/gcm_driver/fake_gcm_driver.h b/components/gcm_driver/fake_gcm_driver.h index 96bad7a..8aa19da 100644 --- a/components/gcm_driver/fake_gcm_driver.h +++ b/components/gcm_driver/fake_gcm_driver.h @@ -54,7 +54,7 @@ class FakeGCMDriver : public GCMDriver { void UnregisterImpl(const std::string& app_id) override; void SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) override; + const OutgoingMessage& message) override; private: DISALLOW_COPY_AND_ASSIGN(FakeGCMDriver); diff --git a/components/gcm_driver/gcm_account_mapper.cc b/components/gcm_driver/gcm_account_mapper.cc index 7caeaba..8730950 100644 --- a/components/gcm_driver/gcm_account_mapper.cc +++ b/components/gcm_driver/gcm_account_mapper.cc @@ -149,7 +149,7 @@ void GCMAccountMapper::ShutdownHandler() { } void GCMAccountMapper::OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) { + const IncomingMessage& message) { DCHECK_EQ(app_id, kGCMAccountMapperAppId); // TODO(fgorski): Report Send to Gaia ID failures using UMA. @@ -158,8 +158,7 @@ void GCMAccountMapper::OnMessage(const std::string& app_id, return; } - GCMClient::MessageData::const_iterator it = - message.data.find(kGCMSendToGaiaIdAppIdKey); + MessageData::const_iterator it = message.data.find(kGCMSendToGaiaIdAppIdKey); if (it == message.data.end()) { DVLOG(1) << "Send to Gaia ID failure: Embedded app ID missing."; return; @@ -172,7 +171,7 @@ void GCMAccountMapper::OnMessage(const std::string& app_id, } // Ensuring the message does not carry the embedded app ID. - GCMClient::IncomingMessage new_message = message; + IncomingMessage new_message = message; new_message.data.erase(new_message.data.find(kGCMSendToGaiaIdAppIdKey)); dispatch_message_callback_.Run(embedded_app_id, new_message); } @@ -279,7 +278,7 @@ void GCMAccountMapper::SendRemoveMappingMessage( void GCMAccountMapper::CreateAndSendMessage( const AccountMapping& account_mapping) { - GCMClient::OutgoingMessage outgoing_message; + OutgoingMessage outgoing_message; outgoing_message.id = GenerateMessageID(); outgoing_message.data[kRegistrationIdMessgaeKey] = registration_id_; outgoing_message.data[kAccountMessageKey] = account_mapping.email; diff --git a/components/gcm_driver/gcm_account_mapper.h b/components/gcm_driver/gcm_account_mapper.h index 2f9522d..45ece23 100644 --- a/components/gcm_driver/gcm_account_mapper.h +++ b/components/gcm_driver/gcm_account_mapper.h @@ -31,7 +31,7 @@ class GCMAccountMapper : public GCMAppHandler { // List of account mappings. typedef std::vector<AccountMapping> AccountMappings; typedef base::Callback<void(const std::string& app_id, - const GCMClient::IncomingMessage& message)> + const IncomingMessage& message)> DispatchMessageCallback; explicit GCMAccountMapper(GCMDriver* gcm_driver); @@ -48,7 +48,7 @@ class GCMAccountMapper : public GCMAppHandler { // Implementation of GCMAppHandler: void ShutdownHandler() override; void OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) override; + const IncomingMessage& message) override; void OnMessagesDeleted(const std::string& app_id) override; void OnSendError( const std::string& app_id, @@ -60,7 +60,7 @@ class GCMAccountMapper : public GCMAppHandler { private: friend class GCMAccountMapperTest; - typedef std::map<std::string, GCMClient::OutgoingMessage> OutgoingMessages; + typedef std::map<std::string, OutgoingMessage> OutgoingMessages; // Checks whether account mapper is ready to process new account tokens. bool IsReady(); diff --git a/components/gcm_driver/gcm_account_mapper_unittest.cc b/components/gcm_driver/gcm_account_mapper_unittest.cc index ff16088..7b76b36 100644 --- a/components/gcm_driver/gcm_account_mapper_unittest.cc +++ b/components/gcm_driver/gcm_account_mapper_unittest.cc @@ -123,7 +123,7 @@ class CustomFakeGCMDriver : public FakeGCMDriver { protected: void SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) override; + const OutgoingMessage& message) override; private: AccountMapping account_mapping_; @@ -201,7 +201,7 @@ void CustomFakeGCMDriver::MessageSendError(const std::string& message_id) { void CustomFakeGCMDriver::SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) { + const OutgoingMessage& message) { DCHECK_EQ(kGCMAccountMapperAppId, app_id); DCHECK_EQ(kGCMAccountMapperSendTo, receiver_id); @@ -257,7 +257,7 @@ class GCMAccountMapperTest : public testing::Test { return account_mapper_->accounts_; } void MessageReceived(const std::string& app_id, - const GCMClient::IncomingMessage& message); + const IncomingMessage& message); GCMAccountMapper* mapper() { return account_mapper_.get(); } @@ -267,7 +267,7 @@ class GCMAccountMapperTest : public testing::Test { const std::string& last_received_app_id() const { return last_received_app_id_; } - const GCMClient::IncomingMessage& last_received_message() const { + const IncomingMessage& last_received_message() const { return last_received_message_; } @@ -276,7 +276,7 @@ class GCMAccountMapperTest : public testing::Test { scoped_ptr<GCMAccountMapper> account_mapper_; base::SimpleTestClock* clock_; std::string last_received_app_id_; - GCMClient::IncomingMessage last_received_message_; + IncomingMessage last_received_message_; }; GCMAccountMapperTest::GCMAccountMapperTest() { @@ -303,9 +303,8 @@ void GCMAccountMapperTest::Initialize( base::Unretained(this))); } -void GCMAccountMapperTest::MessageReceived( - const std::string& app_id, - const GCMClient::IncomingMessage& message) { +void GCMAccountMapperTest::MessageReceived(const std::string& app_id, + const IncomingMessage& message) { last_received_app_id_ = app_id; last_received_message_ = message; } @@ -947,7 +946,7 @@ TEST_F(GCMAccountMapperTest, MultipleAccountMappings) { TEST_F(GCMAccountMapperTest, DispatchMessageSentToGaiaID) { Initialize(GCMAccountMapper::AccountMappings()); gcm_driver().AddAppHandler(kGCMAccountMapperAppId, mapper()); - GCMClient::IncomingMessage message; + IncomingMessage message; message.data[kEmbeddedAppIdKey] = kTestAppId; message.data[kTestDataKey] = kTestDataValue; message.collapse_key = kTestCollapseKey; @@ -956,7 +955,7 @@ TEST_F(GCMAccountMapperTest, DispatchMessageSentToGaiaID) { EXPECT_EQ(kTestAppId, last_received_app_id()); EXPECT_EQ(1UL, last_received_message().data.size()); - GCMClient::MessageData::const_iterator it = + MessageData::const_iterator it = last_received_message().data.find(kTestDataKey); EXPECT_TRUE(it != last_received_message().data.end()); EXPECT_EQ(kTestDataValue, it->second); diff --git a/components/gcm_driver/gcm_app_handler.h b/components/gcm_driver/gcm_app_handler.h index 4a841f3..a77990a 100644 --- a/components/gcm_driver/gcm_app_handler.h +++ b/components/gcm_driver/gcm_app_handler.h @@ -26,7 +26,7 @@ class GCMAppHandler { // Called when a GCM message has been received. virtual void OnMessage(const std::string& app_id, - const GCMClient::IncomingMessage& message) = 0; + const IncomingMessage& message) = 0; // Called when some GCM messages have been deleted from the server. virtual void OnMessagesDeleted(const std::string& app_id) = 0; diff --git a/components/gcm_driver/gcm_client.cc b/components/gcm_driver/gcm_client.cc index 76dc0f6..33271ba 100644 --- a/components/gcm_driver/gcm_client.cc +++ b/components/gcm_driver/gcm_client.cc @@ -14,22 +14,6 @@ GCMClient::ChromeBuildInfo::ChromeBuildInfo() GCMClient::ChromeBuildInfo::~ChromeBuildInfo() { } -// static -const int GCMClient::OutgoingMessage::kMaximumTTL = 24 * 60 * 60; // 1 day. - -GCMClient::OutgoingMessage::OutgoingMessage() - : time_to_live(kMaximumTTL) { -} - -GCMClient::OutgoingMessage::~OutgoingMessage() { -} - -GCMClient::IncomingMessage::IncomingMessage() { -} - -GCMClient::IncomingMessage::~IncomingMessage() { -} - GCMClient::SendErrorDetails::SendErrorDetails() : result(UNKNOWN_ERROR) {} GCMClient::SendErrorDetails::~SendErrorDetails() {} diff --git a/components/gcm_driver/gcm_client.h b/components/gcm_driver/gcm_client.h index cb6042f..0aa9a1a 100644 --- a/components/gcm_driver/gcm_client.h +++ b/components/gcm_driver/gcm_client.h @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" +#include "components/gcm_driver/common/gcm_messages.h" #include "components/gcm_driver/gcm_activity.h" #include "components/gcm_driver/registration_info.h" @@ -97,33 +98,6 @@ class GCMClient { std::string version; }; - // Message data consisting of key-value pairs. - typedef std::map<std::string, std::string> MessageData; - - // Message to be delivered to the other party. - struct OutgoingMessage { - OutgoingMessage(); - ~OutgoingMessage(); - - // Message ID. - std::string id; - // In seconds. - int time_to_live; - MessageData data; - - static const int kMaximumTTL; - }; - - // Message being received from the other party. - struct IncomingMessage { - IncomingMessage(); - ~IncomingMessage(); - - MessageData data; - std::string collapse_key; - std::string sender_id; - }; - // Detailed information of the Send Error event. struct SendErrorDetails { SendErrorDetails(); diff --git a/components/gcm_driver/gcm_client_impl.cc b/components/gcm_driver/gcm_client_impl.cc index e875215..25f4be1 100644 --- a/components/gcm_driver/gcm_client_impl.cc +++ b/components/gcm_driver/gcm_client_impl.cc @@ -211,8 +211,7 @@ bool DeserializeInstanceIDData(const std::string& serialized_data, return !instance_id->empty() && !extra_data->empty(); } -void RecordOutgoingMessageToUMA( - const gcm::GCMClient::OutgoingMessage& message) { +void RecordOutgoingMessageToUMA(const gcm::OutgoingMessage& message) { OutgoingMessageTTLCategory ttl_category; if (message.time_to_live == 0) ttl_category = TTL_ZERO; diff --git a/components/gcm_driver/gcm_client_impl_unittest.cc b/components/gcm_driver/gcm_client_impl_unittest.cc index 37851c0..4b0a279 100644 --- a/components/gcm_driver/gcm_client_impl_unittest.cc +++ b/components/gcm_driver/gcm_client_impl_unittest.cc @@ -285,7 +285,7 @@ class GCMClientImplTest : public testing::Test, const std::string& message_id, GCMClient::Result result) override {} void OnMessageReceived(const std::string& registration_id, - const GCMClient::IncomingMessage& message) override; + const IncomingMessage& message) override; void OnMessagesDeleted(const std::string& app_id) override; void OnMessageSendError( const std::string& app_id, @@ -330,9 +330,7 @@ class GCMClientImplTest : public testing::Test, } const std::string& last_message_id() const { return last_message_id_; } GCMClient::Result last_result() const { return last_result_; } - const GCMClient::IncomingMessage& last_message() const { - return last_message_; - } + const IncomingMessage& last_message() const { return last_message_; } const GCMClient::SendErrorDetails& last_error_details() const { return last_error_details_; } @@ -380,7 +378,7 @@ class GCMClientImplTest : public testing::Test, std::string last_registration_id_; std::string last_message_id_; GCMClient::Result last_result_; - GCMClient::IncomingMessage last_message_; + IncomingMessage last_message_; GCMClient::SendErrorDetails last_error_details_; base::Time last_token_fetch_time_; std::vector<AccountMapping> last_account_mappings_; @@ -577,9 +575,8 @@ void GCMClientImplTest::OnGCMReady( last_token_fetch_time_ = last_token_fetch_time; } -void GCMClientImplTest::OnMessageReceived( - const std::string& registration_id, - const GCMClient::IncomingMessage& message) { +void GCMClientImplTest::OnMessageReceived(const std::string& registration_id, + const IncomingMessage& message) { last_event_ = MESSAGE_RECEIVED; last_app_id_ = registration_id; last_message_ = message; @@ -867,7 +864,7 @@ TEST_F(GCMClientImplTest, DispatchDownstreamMessageSendError) { EXPECT_EQ(kAppId, last_app_id()); EXPECT_EQ("007", last_error_details().message_id); EXPECT_EQ(1UL, last_error_details().additional_data.size()); - GCMClient::MessageData::const_iterator iter = + MessageData::const_iterator iter = last_error_details().additional_data.find("error_details"); EXPECT_TRUE(iter != last_error_details().additional_data.end()); EXPECT_EQ("some details", iter->second); @@ -886,7 +883,7 @@ TEST_F(GCMClientImplTest, DispatchDownstreamMessgaesDeleted) { } TEST_F(GCMClientImplTest, SendMessage) { - GCMClient::OutgoingMessage message; + OutgoingMessage message; message.id = "007"; message.time_to_live = 500; message.data["key"] = "value"; diff --git a/components/gcm_driver/gcm_driver.cc b/components/gcm_driver/gcm_driver.cc index 8227817..cebec36 100644 --- a/components/gcm_driver/gcm_driver.cc +++ b/components/gcm_driver/gcm_driver.cc @@ -125,7 +125,7 @@ void GCMDriver::UnregisterInternal(const std::string& app_id, void GCMDriver::Send(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message, + const OutgoingMessage& message, const SendCallback& callback) { DCHECK(!app_id.empty()); DCHECK(!receiver_id.empty()); diff --git a/components/gcm_driver/gcm_driver.h b/components/gcm_driver/gcm_driver.h index 9122d84..4095f3e 100644 --- a/components/gcm_driver/gcm_driver.h +++ b/components/gcm_driver/gcm_driver.h @@ -13,6 +13,7 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/threading/thread_checker.h" +#include "components/gcm_driver/common/gcm_messages.h" #include "components/gcm_driver/default_gcm_app_handler.h" #include "components/gcm_driver/gcm_client.h" @@ -113,7 +114,7 @@ class GCMDriver { // |callback|: to be called once the asynchronous operation is done. void Send(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message, + const OutgoingMessage& message, const SendCallback& callback); const GCMAppHandlerMap& app_handlers() const { return app_handlers_; } @@ -230,7 +231,7 @@ class GCMDriver { // Platform-specific implementation of Send. virtual void SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) = 0; + const OutgoingMessage& message) = 0; // Runs the Register callback. void RegisterFinished(const std::string& app_id, diff --git a/components/gcm_driver/gcm_driver_android.cc b/components/gcm_driver/gcm_driver_android.cc index 6f8dd59..2ce34f8 100644 --- a/components/gcm_driver/gcm_driver_android.cc +++ b/components/gcm_driver/gcm_driver_android.cc @@ -64,7 +64,7 @@ void GCMDriverAndroid::OnMessageReceived(JNIEnv* env, jobjectArray j_data_keys_and_values) { std::string app_id = ConvertJavaStringToUTF8(env, j_app_id); - GCMClient::IncomingMessage message; + IncomingMessage message; message.sender_id = ConvertJavaStringToUTF8(env, j_sender_id); message.collapse_key = ConvertJavaStringToUTF8(env, j_collapse_key); // Expand j_data_keys_and_values from array to map. @@ -205,7 +205,7 @@ void GCMDriverAndroid::UnregisterWithSenderIdImpl( void GCMDriverAndroid::SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) { + const OutgoingMessage& message) { NOTIMPLEMENTED(); } diff --git a/components/gcm_driver/gcm_driver_android.h b/components/gcm_driver/gcm_driver_android.h index 2dd0e70..6929847 100644 --- a/components/gcm_driver/gcm_driver_android.h +++ b/components/gcm_driver/gcm_driver_android.h @@ -78,7 +78,7 @@ class GCMDriverAndroid : public GCMDriver { const std::string& sender_id) override; void SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) override; + const OutgoingMessage& message) override; private: base::android::ScopedJavaGlobalRef<jobject> java_ref_; diff --git a/components/gcm_driver/gcm_driver_desktop.cc b/components/gcm_driver/gcm_driver_desktop.cc index 7ccdf4b..6864ed2 100644 --- a/components/gcm_driver/gcm_driver_desktop.cc +++ b/components/gcm_driver/gcm_driver_desktop.cc @@ -51,7 +51,7 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { const std::string& message_id, GCMClient::Result result) override; void OnMessageReceived(const std::string& app_id, - const GCMClient::IncomingMessage& message) override; + const IncomingMessage& message) override; void OnMessagesDeleted(const std::string& app_id) override; void OnMessageSendError( const std::string& app_id, @@ -79,7 +79,7 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { void Unregister(const std::string& app_id); void Send(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message); + const OutgoingMessage& message); void GetGCMStatistics(bool clear_logs); void SetGCMRecording(bool recording); @@ -229,7 +229,7 @@ void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id, void GCMDriverDesktop::IOWorker::OnMessageReceived( const std::string& app_id, - const GCMClient::IncomingMessage& message) { + const IncomingMessage& message) { DCHECK(io_thread_->RunsTasksOnCurrentThread()); ui_thread_->PostTask( @@ -335,10 +335,9 @@ void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { make_linked_ptr<RegistrationInfo>(gcm_info.release())); } -void GCMDriverDesktop::IOWorker::Send( - const std::string& app_id, - const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) { +void GCMDriverDesktop::IOWorker::Send(const std::string& app_id, + const std::string& receiver_id, + const OutgoingMessage& message) { DCHECK(io_thread_->RunsTasksOnCurrentThread()); gcm_client_->Send(app_id, receiver_id, message); @@ -692,7 +691,7 @@ void GCMDriverDesktop::DoUnregister(const std::string& app_id) { void GCMDriverDesktop::SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) { + const OutgoingMessage& message) { // Delay the send operation until all GCMClient is ready. if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { delayed_task_controller_->AddTask(base::Bind(&GCMDriverDesktop::DoSend, @@ -708,7 +707,7 @@ void GCMDriverDesktop::SendImpl(const std::string& app_id, void GCMDriverDesktop::DoSend(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) { + const OutgoingMessage& message) { DCHECK(ui_thread_->RunsTasksOnCurrentThread()); io_thread_->PostTask( FROM_HERE, @@ -1187,9 +1186,8 @@ void GCMDriverDesktop::RemoveCachedData() { ClearCallbacks(); } -void GCMDriverDesktop::MessageReceived( - const std::string& app_id, - const GCMClient::IncomingMessage& message) { +void GCMDriverDesktop::MessageReceived(const std::string& app_id, + const IncomingMessage& message) { DCHECK(ui_thread_->RunsTasksOnCurrentThread()); // Drop the event if the service has been stopped. diff --git a/components/gcm_driver/gcm_driver_desktop.h b/components/gcm_driver/gcm_driver_desktop.h index 6900abf..ae2d0fd 100644 --- a/components/gcm_driver/gcm_driver_desktop.h +++ b/components/gcm_driver/gcm_driver_desktop.h @@ -120,7 +120,7 @@ class GCMDriverDesktop : public GCMDriver, void UnregisterImpl(const std::string& app_id) override; void SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) override; + const OutgoingMessage& message) override; private: class IOWorker; @@ -141,7 +141,7 @@ class GCMDriverDesktop : public GCMDriver, void DoUnregister(const std::string& app_id); void DoSend(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message); + const OutgoingMessage& message); void DoAddInstanceIDData(const std::string& app_id, const std::string& instance_id, const std::string& extra_data); @@ -157,7 +157,7 @@ class GCMDriverDesktop : public GCMDriver, // Callbacks posted from IO thread to UI thread. void MessageReceived(const std::string& app_id, - const GCMClient::IncomingMessage& message); + const IncomingMessage& message); void MessagesDeleted(const std::string& app_id); void MessageSendError(const std::string& app_id, const GCMClient::SendErrorDetails& send_error_details); diff --git a/components/gcm_driver/gcm_driver_desktop_unittest.cc b/components/gcm_driver/gcm_driver_desktop_unittest.cc index fb195ed..591a02b 100644 --- a/components/gcm_driver/gcm_driver_desktop_unittest.cc +++ b/components/gcm_driver/gcm_driver_desktop_unittest.cc @@ -134,7 +134,7 @@ class GCMDriverTest : public testing::Test { WaitToFinish wait_to_finish); void Send(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message, + const OutgoingMessage& message, WaitToFinish wait_to_finish); void Unregister(const std::string& app_id, WaitToFinish wait_to_finish); @@ -278,7 +278,7 @@ void GCMDriverTest::Register(const std::string& app_id, void GCMDriverTest::Send(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message, + const OutgoingMessage& message, WaitToFinish wait_to_finish) { base::RunLoop run_loop; async_operation_completed_callback_ = run_loop.QuitClosure(); @@ -466,7 +466,7 @@ TEST_F(GCMDriverTest, UnregisterFailed) { } TEST_F(GCMDriverTest, SendFailed) { - GCMClient::OutgoingMessage message; + OutgoingMessage message; message.id = "1"; message.data["key1"] = "value1"; @@ -528,7 +528,7 @@ TEST_F(GCMDriverTest, GCMClientNotReadyBeforeSending) { AddAppHandlers(); // The sending is on hold until GCMClient is ready. - GCMClient::OutgoingMessage message; + OutgoingMessage message; message.id = "1"; message.data["key1"] = "value1"; message.data["key2"] = "value2"; @@ -734,7 +734,7 @@ TEST_F(GCMDriverFunctionalTest, RegisterAfterUnfinishedUnregister) { } TEST_F(GCMDriverFunctionalTest, Send) { - GCMClient::OutgoingMessage message; + OutgoingMessage message; message.id = "1@ack"; message.data["key1"] = "value1"; message.data["key2"] = "value2"; @@ -749,7 +749,7 @@ TEST_F(GCMDriverFunctionalTest, Send) { } TEST_F(GCMDriverFunctionalTest, SendError) { - GCMClient::OutgoingMessage message; + OutgoingMessage message; // Embedding error in id will tell the mock to simulate the send error. message.id = "1@error"; message.data["key1"] = "value1"; @@ -776,7 +776,7 @@ TEST_F(GCMDriverFunctionalTest, MessageReceived) { // GCM registration has to be performed otherwise GCM will not be started. Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT); - GCMClient::IncomingMessage message; + IncomingMessage message; message.data["key1"] = "value1"; message.data["key2"] = "value2"; message.sender_id = "sender"; @@ -794,7 +794,7 @@ TEST_F(GCMDriverFunctionalTest, MessageWithCollapseKeyReceived) { // GCM registration has to be performed otherwise GCM will not be started. Register(kTestAppID1, ToSenderList("sender"), GCMDriverTest::WAIT); - GCMClient::IncomingMessage message; + IncomingMessage message; message.data["key1"] = "value1"; message.collapse_key = "collapse_key_value"; message.sender_id = "sender"; diff --git a/components/invalidation/impl/gcm_invalidation_bridge.cc b/components/invalidation/impl/gcm_invalidation_bridge.cc index 7f025e1..dbc44fe 100644 --- a/components/invalidation/impl/gcm_invalidation_bridge.cc +++ b/components/invalidation/impl/gcm_invalidation_bridge.cc @@ -318,10 +318,9 @@ void GCMInvalidationBridge::ShutdownHandler() { // Nothing to do. } -void GCMInvalidationBridge::OnMessage( - const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) { - gcm::GCMClient::MessageData::const_iterator it; +void GCMInvalidationBridge::OnMessage(const std::string& app_id, + const gcm::IncomingMessage& message) { + gcm::MessageData::const_iterator it; std::string content; std::string echo_token; it = message.data.find(kContentKey); diff --git a/components/invalidation/impl/gcm_invalidation_bridge.h b/components/invalidation/impl/gcm_invalidation_bridge.h index 2e590dc..e1a4069 100644 --- a/components/invalidation/impl/gcm_invalidation_bridge.h +++ b/components/invalidation/impl/gcm_invalidation_bridge.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/threading/non_thread_safe.h" +#include "components/gcm_driver/common/gcm_messages.h" #include "components/gcm_driver/gcm_app_handler.h" #include "components/gcm_driver/gcm_client.h" #include "components/gcm_driver/gcm_connection_observer.h" @@ -53,7 +54,7 @@ class GCMInvalidationBridge : public gcm::GCMAppHandler, // gcm::GCMAppHandler implementation. void ShutdownHandler() override; void OnMessage(const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) override; + const gcm::IncomingMessage& message) override; void OnMessagesDeleted(const std::string& app_id) override; void OnSendError( const std::string& app_id, diff --git a/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.cc b/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.cc index 548e9d6..7c07fc2 100644 --- a/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.cc +++ b/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.cc @@ -83,9 +83,8 @@ void CryptAuthGCMManagerImpl::RemoveObserver(Observer* observer) { void CryptAuthGCMManagerImpl::ShutdownHandler() { } -void CryptAuthGCMManagerImpl::OnMessage( - const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) { +void CryptAuthGCMManagerImpl::OnMessage(const std::string& app_id, + const gcm::IncomingMessage& message) { std::vector<std::string> fields; for (const auto& kv : message.data) { fields.push_back(std::string(kv.first) + ": " + std::string(kv.second)); diff --git a/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h b/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h index 84ae53b..c58fa45 100644 --- a/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h +++ b/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h @@ -8,6 +8,7 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" +#include "components/gcm_driver/common/gcm_messages.h" #include "components/gcm_driver/gcm_app_handler.h" #include "components/gcm_driver/gcm_client.h" #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager.h" @@ -46,7 +47,7 @@ class CryptAuthGCMManagerImpl : public CryptAuthGCMManager, // GCMAppHandler: void ShutdownHandler() override; void OnMessage(const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) override; + const gcm::IncomingMessage& message) override; void OnMessagesDeleted(const std::string& app_id) override; void OnSendError(const std::string& app_id, const gcm::GCMClient::SendErrorDetails& details) override; diff --git a/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl_unittest.cc b/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl_unittest.cc index 02b35ac..9b93bca 100644 --- a/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl_unittest.cc +++ b/components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl_unittest.cc @@ -168,7 +168,7 @@ TEST_F(ProximityAuthCryptAuthGCMManagerImplTest, ConcurrentRegistrations) { TEST_F(ProximityAuthCryptAuthGCMManagerImplTest, ReenrollmentMessagesReceived) { EXPECT_CALL(*this, OnReenrollMessageProxy()).Times(2); - gcm::GCMClient::IncomingMessage message; + gcm::IncomingMessage message; message.data["registrationTickleType"] = "1"; // FORCE_ENROLLMENT message.collapse_key = kCryptAuthMessageCollapseKey; message.sender_id = kCryptAuthGCMSenderId; @@ -183,7 +183,7 @@ TEST_F(ProximityAuthCryptAuthGCMManagerImplTest, ReenrollmentMessagesReceived) { TEST_F(ProximityAuthCryptAuthGCMManagerImplTest, ResyncMessagesReceived) { EXPECT_CALL(*this, OnResyncMessageProxy()).Times(2); - gcm::GCMClient::IncomingMessage message; + gcm::IncomingMessage message; message.data["registrationTickleType"] = "3"; // DEVICES_SYNC message.collapse_key = kCryptAuthMessageCollapseKey; message.sender_id = kCryptAuthGCMSenderId; |