diff options
51 files changed, 262 insertions, 189 deletions
diff --git a/chrome/browser/chromeos/policy/heartbeat_scheduler.cc b/chrome/browser/chromeos/policy/heartbeat_scheduler.cc index 74dd1e0..4e4e4ef 100644 --- a/chrome/browser/chromeos/policy/heartbeat_scheduler.cc +++ b/chrome/browser/chromeos/policy/heartbeat_scheduler.cc @@ -306,7 +306,7 @@ void HeartbeatScheduler::SendHeartbeat() { if (!gcm_driver_ || !heartbeat_enabled_) return; - gcm::GCMClient::OutgoingMessage message; + gcm::OutgoingMessage message; message.time_to_live = heartbeat_interval_.InSeconds(); // Just use the current timestamp as the message ID - if the user changes the // time and we send a message with the same ID that we previously used, no @@ -351,9 +351,8 @@ void HeartbeatScheduler::ShutdownHandler() { NOTREACHED() << "HeartbeatScheduler should be destroyed before GCMDriver"; } -void HeartbeatScheduler::OnMessage( - const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) { +void HeartbeatScheduler::OnMessage(const std::string& app_id, + const gcm::IncomingMessage& message) { // Should never be called because we don't get any incoming messages // for our app ID. NOTREACHED() << "Received incoming message for " << app_id; diff --git a/chrome/browser/chromeos/policy/heartbeat_scheduler.h b/chrome/browser/chromeos/policy/heartbeat_scheduler.h index d516eb0..9c268fa 100644 --- a/chrome/browser/chromeos/policy/heartbeat_scheduler.h +++ b/chrome/browser/chromeos/policy/heartbeat_scheduler.h @@ -53,7 +53,7 @@ class HeartbeatScheduler : public gcm::GCMAppHandler { // 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, const gcm::GCMClient::SendErrorDetails& details) override; diff --git a/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc b/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc index 8e5686b..6b409f3 100644 --- a/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc +++ b/chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc @@ -32,9 +32,9 @@ class MockGCMDriver : public testing::StrictMock<gcm::FakeGCMDriver> { MOCK_METHOD2(RegisterImpl, void(const std::string&, const std::vector<std::string>&)); MOCK_METHOD3(SendImpl, - void(const std::string&, const std::string&, - const gcm::GCMClient::OutgoingMessage& message)); - + void(const std::string&, + const std::string&, + const gcm::OutgoingMessage& message)); // Helper function to complete a registration previously started by // Register(). @@ -153,7 +153,7 @@ TEST_F(HeartbeatSchedulerTest, ChangeHeartbeatFrequency) { const int new_delay = 1234*1000; // 1234 seconds. settings_helper_.SetInteger(chromeos::kHeartbeatFrequency, new_delay); // Now run pending heartbeat task, should send a heartbeat. - gcm::GCMClient::OutgoingMessage message; + gcm::OutgoingMessage message; EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, _)) .WillOnce(SaveArg<2>(&message)); task_runner_->RunPendingTasks(); @@ -172,7 +172,7 @@ TEST_F(HeartbeatSchedulerTest, DisableHeartbeats) { // Makes sure that we can disable heartbeats on the fly. EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); settings_helper_.SetBoolean(chromeos::kHeartbeatEnabled, true); - gcm::GCMClient::OutgoingMessage message; + gcm::OutgoingMessage message; EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, _)) .WillOnce(SaveArg<2>(&message)); gcm_driver_.CompleteRegistration( @@ -200,7 +200,7 @@ TEST_F(HeartbeatSchedulerTest, DisableHeartbeats) { } TEST_F(HeartbeatSchedulerTest, CheckMessageContents) { - gcm::GCMClient::OutgoingMessage message; + gcm::OutgoingMessage message; EXPECT_CALL(gcm_driver_, RegisterImpl(kHeartbeatGCMAppID, _)); EXPECT_CALL(gcm_driver_, SendImpl(kHeartbeatGCMAppID, _, _)) .WillOnce(SaveArg<2>(&message)); diff --git a/chrome/browser/extensions/api/gcm/gcm_api.cc b/chrome/browser/extensions/api/gcm/gcm_api.cc index 7380fad..714f3ee 100644 --- a/chrome/browser/extensions/api/gcm/gcm_api.cc +++ b/chrome/browser/extensions/api/gcm/gcm_api.cc @@ -16,6 +16,7 @@ #include "chrome/browser/services/gcm/gcm_profile_service.h" #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" #include "chrome/common/extensions/api/gcm.h" +#include "components/gcm_driver/common/gcm_messages.h" #include "components/gcm_driver/gcm_driver.h" #include "extensions/browser/event_router.h" #include "extensions/common/extension.h" @@ -159,7 +160,7 @@ bool GcmSendFunction::DoWork() { EXTENSION_FUNCTION_VALIDATE( ValidateMessageData(params->message.data.additional_properties)); - gcm::GCMClient::OutgoingMessage outgoing_message; + gcm::OutgoingMessage outgoing_message; outgoing_message.id = params->message.message_id; outgoing_message.data = params->message.data.additional_properties; if (params->message.time_to_live.get()) @@ -182,8 +183,7 @@ void GcmSendFunction::CompleteFunctionWithResult( SendResponse(gcm::GCMClient::SUCCESS == result); } -bool GcmSendFunction::ValidateMessageData( - const gcm::GCMClient::MessageData& data) const { +bool GcmSendFunction::ValidateMessageData(const gcm::MessageData& data) const { size_t total_size = 0u; for (std::map<std::string, std::string>::const_iterator iter = data.begin(); iter != data.end(); ++iter) { @@ -205,9 +205,8 @@ GcmJsEventRouter::GcmJsEventRouter(Profile* profile) : profile_(profile) { GcmJsEventRouter::~GcmJsEventRouter() { } -void GcmJsEventRouter::OnMessage( - const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) { +void GcmJsEventRouter::OnMessage(const std::string& app_id, + const gcm::IncomingMessage& message) { api::gcm::OnMessage::Message message_arg; message_arg.data.additional_properties = message.data; if (!message.sender_id.empty()) diff --git a/chrome/browser/extensions/api/gcm/gcm_api.h b/chrome/browser/extensions/api/gcm/gcm_api.h index b6b33d2..f0b3460 100644 --- a/chrome/browser/extensions/api/gcm/gcm_api.h +++ b/chrome/browser/extensions/api/gcm/gcm_api.h @@ -88,7 +88,7 @@ class GcmSendFunction : public GcmApiFunction { // Validates that message data do not carry invalid keys and fit into // allowable size limits. - bool ValidateMessageData(const gcm::GCMClient::MessageData& data) const; + bool ValidateMessageData(const gcm::MessageData& data) const; }; class GcmJsEventRouter { @@ -98,7 +98,7 @@ class GcmJsEventRouter { virtual ~GcmJsEventRouter(); void OnMessage(const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message); + const gcm::IncomingMessage& message); void OnMessagesDeleted(const std::string& app_id); void OnSendError(const std::string& app_id, const gcm::GCMClient::SendErrorDetails& send_error_details); diff --git a/chrome/browser/extensions/api/gcm/gcm_apitest.cc b/chrome/browser/extensions/api/gcm/gcm_apitest.cc index 1506241..4abce72 100644 --- a/chrome/browser/extensions/api/gcm/gcm_apitest.cc +++ b/chrome/browser/extensions/api/gcm/gcm_apitest.cc @@ -144,9 +144,8 @@ IN_PROC_BROWSER_TEST_F(GcmApiTest, SendMessageData) { ASSERT_TRUE(RunExtensionTest("gcm/functions/send_message_data")); EXPECT_EQ("destination-id", service()->last_receiver_id()); - const gcm::GCMClient::OutgoingMessage& message = - service()->last_sent_message(); - gcm::GCMClient::MessageData::const_iterator iter; + const gcm::OutgoingMessage& message = service()->last_sent_message(); + gcm::MessageData::const_iterator iter; EXPECT_EQ(100, message.time_to_live); @@ -162,11 +161,10 @@ IN_PROC_BROWSER_TEST_F(GcmApiTest, SendMessageDefaultTTL) { ASSERT_TRUE(RunExtensionTest("gcm/functions/send_message_default_ttl")); EXPECT_EQ("destination-id", service()->last_receiver_id()); - const gcm::GCMClient::OutgoingMessage& message = - service()->last_sent_message(); - gcm::GCMClient::MessageData::const_iterator iter; + const gcm::OutgoingMessage& message = service()->last_sent_message(); + gcm::MessageData::const_iterator iter; - EXPECT_EQ(gcm::GCMClient::OutgoingMessage::kMaximumTTL, message.time_to_live); + EXPECT_EQ(gcm::OutgoingMessage::kMaximumTTL, message.time_to_live); } IN_PROC_BROWSER_TEST_F(GcmApiTest, OnMessagesDeleted) { @@ -192,7 +190,7 @@ IN_PROC_BROWSER_TEST_F(GcmApiTest, OnMessage) { extensions::ExtensionGCMAppHandler app_handler(profile()); - gcm::GCMClient::IncomingMessage message; + gcm::IncomingMessage message; message.data["property1"] = "value1"; message.data["property2"] = "value2"; // First message is sent without from and collapse key. diff --git a/chrome/browser/extensions/extension_gcm_app_handler.cc b/chrome/browser/extensions/extension_gcm_app_handler.cc index 835c3d4..4d9e2ac 100644 --- a/chrome/browser/extensions/extension_gcm_app_handler.cc +++ b/chrome/browser/extensions/extension_gcm_app_handler.cc @@ -68,9 +68,8 @@ void ExtensionGCMAppHandler::ShutdownHandler() { js_event_router_.reset(); } -void ExtensionGCMAppHandler::OnMessage( - const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) { +void ExtensionGCMAppHandler::OnMessage(const std::string& app_id, + const gcm::IncomingMessage& message) { js_event_router_->OnMessage(app_id, message); } diff --git a/chrome/browser/extensions/extension_gcm_app_handler.h b/chrome/browser/extensions/extension_gcm_app_handler.h index f2a5a6c..81d6efc 100644 --- a/chrome/browser/extensions/extension_gcm_app_handler.h +++ b/chrome/browser/extensions/extension_gcm_app_handler.h @@ -12,6 +12,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/scoped_observer.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/instance_id/instance_id.h" @@ -52,7 +53,7 @@ class ExtensionGCMAppHandler : 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/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc b/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc index cf3feb4..59737ca4 100644 --- a/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc +++ b/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc @@ -140,7 +140,7 @@ class FakeExtensionGCMAppHandler : public ExtensionGCMAppHandler { ~FakeExtensionGCMAppHandler() 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 {} diff --git a/chrome/browser/push_messaging/push_messaging_browsertest.cc b/chrome/browser/push_messaging/push_messaging_browsertest.cc index 8f3cc8d..4deed16 100644 --- a/chrome/browser/push_messaging/push_messaging_browsertest.cc +++ b/chrome/browser/push_messaging/push_messaging_browsertest.cc @@ -32,6 +32,7 @@ #include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings_types.h" +#include "components/gcm_driver/common/gcm_messages.h" #include "components/gcm_driver/gcm_client.h" #include "content/public/browser/web_contents.h" #include "content/public/common/content_switches.h" @@ -162,7 +163,7 @@ class PushMessagingBrowserTest : public InProcessBrowserTest { void SendMessageAndWaitUntilHandled( const PushMessagingAppIdentifier& app_identifier, - const gcm::GCMClient::IncomingMessage& message); + const gcm::IncomingMessage& message); net::SpawnedTestServer* https_server() const { return https_server_.get(); } @@ -261,7 +262,7 @@ PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( const PushMessagingAppIdentifier& app_identifier, - const gcm::GCMClient::IncomingMessage& message) { + const gcm::IncomingMessage& message) { base::RunLoop run_loop; push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); push_service()->OnMessage(app_identifier.app_id(), message); @@ -417,7 +418,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { ASSERT_TRUE(RunScript("isControlled()", &script_result)); ASSERT_EQ("true - is controlled", script_result); - gcm::GCMClient::IncomingMessage message; + gcm::IncomingMessage message; message.sender_id = "1234567890"; message.data["data"] = "testdata"; push_service()->OnMessage(app_identifier.app_id(), message); @@ -453,7 +454,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, base::Unretained(&callback))); - gcm::GCMClient::IncomingMessage message; + gcm::IncomingMessage message; message.sender_id = "1234567890"; message.data["data"] = "testdata"; push_service()->OnMessage(app_identifier.app_id(), message); @@ -496,7 +497,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, // If the site is visible in an active tab, we should not force a notification // to be shown. Try it twice, since we allow one mistake per 10 push events. - gcm::GCMClient::IncomingMessage message; + gcm::IncomingMessage message; message.sender_id = "1234567890"; for (int n = 0; n < 2; n++) { message.data["data"] = "testdata"; @@ -599,7 +600,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, std::vector<size_t> number_of_notifications_shown; - gcm::GCMClient::IncomingMessage message; + gcm::IncomingMessage message; message.sender_id = "1234567890"; { @@ -651,7 +652,7 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, notification_manager()->SetNotificationAddedCallback( message_loop_runner->QuitClosure()); - gcm::GCMClient::IncomingMessage message; + gcm::IncomingMessage message; message.sender_id = "1234567890"; message.data["data"] = "shownotification-without-waituntil"; push_service()->OnMessage(app_identifier.app_id(), message); diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.cc b/chrome/browser/push_messaging/push_messaging_service_impl.cc index 409252f..6130044 100644 --- a/chrome/browser/push_messaging/push_messaging_service_impl.cc +++ b/chrome/browser/push_messaging/push_messaging_service_impl.cc @@ -164,9 +164,8 @@ void PushMessagingServiceImpl::ShutdownHandler() { // OnMessage methods ----------------------------------------------------------- -void PushMessagingServiceImpl::OnMessage( - const std::string& app_id, - const gcm::GCMClient::IncomingMessage& message) { +void PushMessagingServiceImpl::OnMessage(const std::string& app_id, + const gcm::IncomingMessage& message) { in_flight_message_deliveries_.insert(app_id); base::Closure message_handled_closure = @@ -214,7 +213,7 @@ void PushMessagingServiceImpl::OnMessage( // https://crbug.com/449184 if (base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnablePushMessagePayload)) { - gcm::GCMClient::MessageData::const_iterator it = message.data.find("data"); + gcm::MessageData::const_iterator it = message.data.find("data"); if (it != message.data.end()) data = it->second; } @@ -235,7 +234,7 @@ void PushMessagingServiceImpl::DeliverMessageCallback( const std::string& app_id, const GURL& requesting_origin, int64 service_worker_registration_id, - const gcm::GCMClient::IncomingMessage& message, + const gcm::IncomingMessage& message, const base::Closure& message_handled_closure, content::PushDeliveryStatus status) { // Remove a single in-flight delivery for |app_id|. This has to be done using diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.h b/chrome/browser/push_messaging/push_messaging_service_impl.h index 2e71bb6..7a1c69c 100644 --- a/chrome/browser/push_messaging/push_messaging_service_impl.h +++ b/chrome/browser/push_messaging/push_messaging_service_impl.h @@ -13,6 +13,7 @@ #include "base/memory/weak_ptr.h" #include "components/content_settings/core/browser/content_settings_observer.h" #include "components/content_settings/core/common/content_settings.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/keyed_service/core/keyed_service.h" @@ -54,7 +55,7 @@ class PushMessagingServiceImpl : public content::PushMessagingService, // 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, @@ -114,7 +115,7 @@ class PushMessagingServiceImpl : public content::PushMessagingService, void DeliverMessageCallback(const std::string& app_id, const GURL& requesting_origin, int64 service_worker_registration_id, - const gcm::GCMClient::IncomingMessage& message, + const gcm::IncomingMessage& message, const base::Closure& message_handled_closure, content::PushDeliveryStatus status); diff --git a/chrome/browser/services/gcm/fake_gcm_profile_service.cc b/chrome/browser/services/gcm/fake_gcm_profile_service.cc index cea82d8..303f545 100644 --- a/chrome/browser/services/gcm/fake_gcm_profile_service.cc +++ b/chrome/browser/services/gcm/fake_gcm_profile_service.cc @@ -42,7 +42,7 @@ class CustomFakeGCMDriver : public FakeGCMDriver { 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: FakeGCMProfileService* service_; @@ -73,7 +73,7 @@ void CustomFakeGCMDriver::UnregisterImpl(const std::string& app_id) { void CustomFakeGCMDriver::SendImpl(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) { + const OutgoingMessage& message) { base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::Bind(&FakeGCMProfileService::SendFinished, @@ -151,10 +151,9 @@ void FakeGCMProfileService::UnregisterFinished(const std::string& app_id) { unregister_callback_.Run(app_id); } -void FakeGCMProfileService::SendFinished( - const std::string& app_id, - const std::string& receiver_id, - const GCMClient::OutgoingMessage& message) { +void FakeGCMProfileService::SendFinished(const std::string& app_id, + const std::string& receiver_id, + const OutgoingMessage& message) { if (collect_) { last_sent_message_ = message; last_receiver_id_ = receiver_id; diff --git a/chrome/browser/services/gcm/fake_gcm_profile_service.h b/chrome/browser/services/gcm/fake_gcm_profile_service.h index ce5907c..499bd83 100644 --- a/chrome/browser/services/gcm/fake_gcm_profile_service.h +++ b/chrome/browser/services/gcm/fake_gcm_profile_service.h @@ -35,13 +35,13 @@ class FakeGCMProfileService : public GCMProfileService { void UnregisterFinished(const std::string& app_id); void SendFinished(const std::string& app_id, const std::string& receiver_id, - const GCMClient::OutgoingMessage& message); + const OutgoingMessage& message); void AddExpectedUnregisterResponse(GCMClient::Result result); void SetUnregisterCallback(const UnregisterCallback& callback); - const GCMClient::OutgoingMessage& last_sent_message() const { + const OutgoingMessage& last_sent_message() const { return last_sent_message_; } @@ -71,7 +71,7 @@ class FakeGCMProfileService : public GCMProfileService { std::string last_registered_app_id_; std::vector<std::string> last_registered_sender_ids_; std::list<GCMClient::Result> unregister_responses_; - GCMClient::OutgoingMessage last_sent_message_; + OutgoingMessage last_sent_message_; std::string last_receiver_id_; UnregisterCallback unregister_callback_; diff --git a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc index 8c3afb5..94f6390 100644 --- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc +++ b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc @@ -63,7 +63,7 @@ class GCMProfileServiceTest : public testing::Test { void RegisterAndWaitForCompletion(const std::vector<std::string>& sender_ids); void UnregisterAndWaitForCompletion(); - void SendAndWaitForCompletion(const GCMClient::OutgoingMessage& message); + void SendAndWaitForCompletion(const OutgoingMessage& message); void RegisterCompleted(const base::Closure& callback, const std::string& registration_id, @@ -159,7 +159,7 @@ void GCMProfileServiceTest::UnregisterAndWaitForCompletion() { } void GCMProfileServiceTest::SendAndWaitForCompletion( - const GCMClient::OutgoingMessage& message) { + const OutgoingMessage& message) { base::RunLoop run_loop; gcm_profile_service_->driver()->Send( kTestAppID, @@ -215,7 +215,7 @@ TEST_F(GCMProfileServiceTest, RegisterAndUnregister) { TEST_F(GCMProfileServiceTest, Send) { CreateGCMProfileService(); - GCMClient::OutgoingMessage message; + OutgoingMessage message; message.id = "1"; message.data["key1"] = "value1"; SendAndWaitForCompletion(message); diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 4cbe723..7906684 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -333,6 +333,7 @@ '<(DEPTH)/components/components.gyp:component_updater', '<(DEPTH)/components/components.gyp:content_settings_core_common', '<(DEPTH)/components/components.gyp:favicon_base', + '<(DEPTH)/components/components.gyp:gcm_driver_common', '<(DEPTH)/components/components.gyp:json_schema', '<(DEPTH)/components/components.gyp:metrics', '<(DEPTH)/components/components.gyp:omnibox_common', diff --git a/chrome/common/BUILD.gn b/chrome/common/BUILD.gn index db9ba99..e18fa76 100644 --- a/chrome/common/BUILD.gn +++ b/chrome/common/BUILD.gn @@ -62,6 +62,7 @@ static_library("common") { "//components/component_updater", "//components/content_settings/core/common", "//components/favicon_base", + "//components/gcm_driver:common", "//components/json_schema", "//components/metrics", "//components/omnibox/common", 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; |