diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 17:12:08 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 17:12:08 +0000 |
commit | 0590a140d2291f2aebfb54179f1282d798faa6a8 (patch) | |
tree | cc8eba1baa094554d03b3727d12cf1f3ab1f95fc /jingle | |
parent | 37b01e6d24bf3c251708cff470b65b2574c582b5 (diff) | |
download | chromium_src-0590a140d2291f2aebfb54179f1282d798faa6a8.zip chromium_src-0590a140d2291f2aebfb54179f1282d798faa6a8.tar.gz chromium_src-0590a140d2291f2aebfb54179f1282d798faa6a8.tar.bz2 |
[Sync] Merged MediatorThread and PushNotificationsThread
Removed most of the legacy XMPP notification code.
Simplified notification structs and calls a bit.
BUG=76130
TEST=
Review URL: http://codereview.chromium.org/6693007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78385 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
32 files changed, 317 insertions, 1039 deletions
diff --git a/jingle/jingle.gyp b/jingle/jingle.gyp index fbc1b72..06e27f9 100644 --- a/jingle/jingle.gyp +++ b/jingle/jingle.gyp @@ -46,25 +46,18 @@ 'notifier/communicator/single_login_attempt.h', 'notifier/communicator/xmpp_connection_generator.cc', 'notifier/communicator/xmpp_connection_generator.h', - 'notifier/listener/listen_task.cc', - 'notifier/listener/listen_task.h', 'notifier/listener/mediator_thread.h', 'notifier/listener/mediator_thread_impl.cc', 'notifier/listener/mediator_thread_impl.h', 'notifier/listener/notification_constants.cc', 'notifier/listener/notification_constants.h', - 'notifier/listener/notification_defines.cc', 'notifier/listener/notification_defines.h', 'notifier/listener/push_notifications_listen_task.cc', 'notifier/listener/push_notifications_listen_task.h', + 'notifier/listener/push_notifications_send_update_task.cc', + 'notifier/listener/push_notifications_send_update_task.h', 'notifier/listener/push_notifications_subscribe_task.cc', 'notifier/listener/push_notifications_subscribe_task.h', - 'notifier/listener/push_notifications_thread.cc', - 'notifier/listener/push_notifications_thread.h', - 'notifier/listener/send_update_task.cc', - 'notifier/listener/send_update_task.h', - 'notifier/listener/subscribe_task.cc', - 'notifier/listener/subscribe_task.h', 'notifier/listener/talk_mediator.h', 'notifier/listener/talk_mediator_impl.cc', 'notifier/listener/talk_mediator_impl.h', @@ -118,10 +111,9 @@ 'notifier/communicator/xmpp_connection_generator_unittest.cc', 'notifier/listener/mediator_thread_mock.cc', 'notifier/listener/mediator_thread_mock.h', + 'notifier/listener/push_notifications_send_update_task_unittest.cc', 'notifier/listener/push_notifications_subscribe_task_unittest.cc', 'notifier/listener/talk_mediator_unittest.cc', - 'notifier/listener/send_update_task_unittest.cc', - 'notifier/listener/subscribe_task_unittest.cc', 'notifier/listener/xml_element_util_unittest.cc', ], 'include_dirs': [ diff --git a/jingle/notifier/listener/listen_task.cc b/jingle/notifier/listener/listen_task.cc deleted file mode 100644 index 01fb26c..0000000 --- a/jingle/notifier/listener/listen_task.cc +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2010 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 "jingle/notifier/listener/listen_task.h" - -#include "base/logging.h" -#include "jingle/notifier/listener/notification_constants.h" -#include "jingle/notifier/listener/xml_element_util.h" -#include "talk/base/task.h" -#include "talk/xmllite/qname.h" -#include "talk/xmllite/xmlelement.h" -#include "talk/xmpp/xmppclient.h" -#include "talk/xmpp/constants.h" -#include "talk/xmpp/xmppengine.h" - -namespace notifier { - -ListenTask::ListenTask(Task* parent) - : buzz::XmppTask(parent, buzz::XmppEngine::HL_TYPE) { -} - -ListenTask::~ListenTask() { -} - -int ListenTask::ProcessStart() { - VLOG(1) << "P2P: Listener task started."; - return STATE_RESPONSE; -} - -int ListenTask::ProcessResponse() { - VLOG(1) << "P2P: Listener response received."; - const buzz::XmlElement* stanza = NextStanza(); - if (stanza == NULL) - return STATE_BLOCKED; - // Acknowledge receipt of the notification to the buzz server. - scoped_ptr<buzz::XmlElement> response_stanza(MakeIqResult(stanza)); - SendStanza(response_stanza.get()); - - // TODO(akalin): Write unittests to cover this. - // Extract the service URL and service-specific data from the stanza. - // The response stanza has the following format. - // <iq from="{bare_jid}" to="{full_jid}" id="#" type="set"> - // <not:getAll xmlns:not="google:notifier"> - // <Timestamp long="#" xmlns=""/> - // <Result xmlns=""> - // <Id> - // <ServiceUrl data="{service_url}"/> - // <ServiceId data="{service_id}"/> - // </Id> - // <Timestamp long="#"/> - // <Content> - // <Priority int="#"/> - // <ServiceSpecificData data="{service_specific_data}"/> - // <RequireSubscription bool="true"/> - // </Content> - // <State> - // <Type int="#"/> - // <Read bool="{true/false}"/> - // </State> - // <ClientActive bool="{true/false}"/> - // </Result> - // </not:getAll> - // </iq> " - // Note that there can be multiple "Result" elements, so we need to loop - // through all of them. - bool update_signaled = false; - const buzz::QName kQnNotifierGetAll(kNotifierNamespace, "getAll"); - const buzz::XmlElement* get_all_element = - stanza->FirstNamed(kQnNotifierGetAll); - if (get_all_element) { - const buzz::XmlElement* result_element = - get_all_element->FirstNamed( - buzz::QName(buzz::STR_EMPTY, "Result")); - while (result_element) { - IncomingNotificationData notification_data; - const buzz::XmlElement* id_element = - result_element->FirstNamed(buzz::QName(buzz::STR_EMPTY, "Id")); - if (id_element) { - const buzz::XmlElement* service_url_element = - id_element->FirstNamed( - buzz::QName(buzz::STR_EMPTY, "ServiceUrl")); - if (service_url_element) { - notification_data.service_url = service_url_element->Attr( - buzz::QName(buzz::STR_EMPTY, "data")); - } - } - const buzz::XmlElement* content_element = - result_element->FirstNamed( - buzz::QName(buzz::STR_EMPTY, "Content")); - if (content_element) { - const buzz::XmlElement* service_data_element = - content_element->FirstNamed( - buzz::QName(buzz::STR_EMPTY, "ServiceSpecificData")); - if (service_data_element) { - notification_data.service_specific_data = service_data_element->Attr( - buzz::QName(buzz::STR_EMPTY, "data")); - } - } - // Inform listeners that a notification has been received. - SignalUpdateAvailable(notification_data); - update_signaled = true; - // Now go to the next Result element - result_element = result_element->NextNamed( - buzz::QName(buzz::STR_EMPTY, "Result")); - } - } - if (!update_signaled) { - LOG(WARNING) << - "No getAll element or Result element found in response stanza"; - // Signal an empty update to preserve old behavior - SignalUpdateAvailable(IncomingNotificationData()); - } - return STATE_RESPONSE; -} - -bool ListenTask::HandleStanza(const buzz::XmlElement* stanza) { - VLOG(1) << "P2P: Stanza received: " << XmlElementToString(*stanza); - // TODO(akalin): Do more verification on stanza depending on - // the sync notification method - if (IsValidNotification(stanza)) { - QueueStanza(stanza); - return true; - } - return false; -} - -bool ListenTask::IsValidNotification(const buzz::XmlElement* stanza) { - // An update notificaiton has the following form. - // <cli:iq from="{bare_jid}" to="{full_jid}" - // id="#" type="set" xmlns:cli="jabber:client"> - // <not:getAll xmlns:not="google:notifier"> - // <Timestamp long="#" xmlns=""/> - // </not:getAll> - // </cli:iq> - // - // We deliberately minimize the verification we do here, though: see - // http://crbug.com/71285 . - const buzz::QName kQnNotifierGetAll(kNotifierNamespace, "getAll"); - return MatchRequestIq(stanza, buzz::STR_SET, kQnNotifierGetAll); -} - -} // namespace notifier diff --git a/jingle/notifier/listener/listen_task.h b/jingle/notifier/listener/listen_task.h deleted file mode 100644 index 6a86775..0000000 --- a/jingle/notifier/listener/listen_task.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2009 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. -// -// This class listens for notifications from the talk service, and signals when -// they arrive. It checks all incoming stanza's to see if they look like -// notifications, and filters out those which are not valid. -// -// The task is deleted automatically by the buzz::XmppClient. This occurs in the -// destructor of TaskRunner, which is a superclass of buzz::XmppClient. - -#ifndef JINGLE_NOTIFIER_LISTENER_LISTEN_TASK_H_ -#define JINGLE_NOTIFIER_LISTENER_LISTEN_TASK_H_ - -#include "jingle/notifier/listener/notification_defines.h" -#include "talk/xmpp/xmpptask.h" - -namespace buzz { -class XmlElement; -class Jid; -} - -namespace notifier { - -class ListenTask : public buzz::XmppTask { - public: - explicit ListenTask(Task* parent); - virtual ~ListenTask(); - - // Overriden from buzz::XmppTask. - virtual int ProcessStart(); - virtual int ProcessResponse(); - virtual bool HandleStanza(const buzz::XmlElement* stanza); - - // Signal callback upon receipt of a notification. - // SignalUpdateAvailable(const IncomingNotificationData& data); - sigslot::signal1<const IncomingNotificationData&> SignalUpdateAvailable; - - private: - // Decide whether a notification should start a sync. We only validate that - // this notification came from our own Jid(). - bool IsValidNotification(const buzz::XmlElement* stanza); - - DISALLOW_COPY_AND_ASSIGN(ListenTask); -}; - -} // namespace notifier - -#endif // JINGLE_NOTIFIER_LISTENER_LISTEN_TASK_H_ diff --git a/jingle/notifier/listener/mediator_thread.h b/jingle/notifier/listener/mediator_thread.h index a0047f5..74b4838d 100644 --- a/jingle/notifier/listener/mediator_thread.h +++ b/jingle/notifier/listener/mediator_thread.h @@ -31,8 +31,7 @@ class MediatorThread { virtual void OnSubscriptionStateChange(bool subscribed) = 0; - virtual void OnIncomingNotification( - const IncomingNotificationData& notification_data) = 0; + virtual void OnIncomingNotification(const Notification& notification) = 0; virtual void OnOutgoingNotification() = 0; }; @@ -47,10 +46,9 @@ class MediatorThread { virtual void Login(const buzz::XmppClientSettings& settings) = 0; virtual void Logout() = 0; virtual void Start() = 0; - virtual void SubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list) = 0; + virtual void SubscribeForUpdates(const SubscriptionList& subscriptions) = 0; virtual void ListenForUpdates() = 0; - virtual void SendNotification(const OutgoingNotificationData& data) = 0; + virtual void SendNotification(const Notification& data) = 0; }; } // namespace notifier diff --git a/jingle/notifier/listener/mediator_thread_impl.cc b/jingle/notifier/listener/mediator_thread_impl.cc index c7b5e5c..72a4707 100644 --- a/jingle/notifier/listener/mediator_thread_impl.cc +++ b/jingle/notifier/listener/mediator_thread_impl.cc @@ -10,9 +10,7 @@ #include "jingle/notifier/communicator/connection_options.h" #include "jingle/notifier/communicator/const_communicator.h" #include "jingle/notifier/communicator/xmpp_connection_generator.h" -#include "jingle/notifier/listener/listen_task.h" -#include "jingle/notifier/listener/send_update_task.h" -#include "jingle/notifier/listener/subscribe_task.h" +#include "jingle/notifier/listener/push_notifications_send_update_task.h" #include "net/base/cert_verifier.h" #include "net/base/host_port_pair.h" #include "net/base/host_resolver.h" @@ -20,7 +18,8 @@ namespace notifier { -MediatorThreadImpl::MediatorThreadImpl(const NotifierOptions& notifier_options) +MediatorThreadImpl::MediatorThreadImpl( + const NotifierOptions& notifier_options) : observers_(new ObserverListThreadSafe<Observer>()), parent_message_loop_(MessageLoop::current()), notifier_options_(notifier_options), @@ -78,20 +77,23 @@ void MediatorThreadImpl::ListenForUpdates() { DCHECK_EQ(MessageLoop::current(), parent_message_loop_); worker_message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &MediatorThreadImpl::DoListenForUpdates)); + NewRunnableMethod(this, + &MediatorThreadImpl::ListenForPushNotifications)); } void MediatorThreadImpl::SubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list) { + const SubscriptionList& subscriptions) { DCHECK_EQ(MessageLoop::current(), parent_message_loop_); worker_message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &MediatorThreadImpl::DoSubscribeForUpdates, - subscribed_services_list)); + NewRunnableMethod( + this, + &MediatorThreadImpl::SubscribeForPushNotifications, + subscriptions)); } void MediatorThreadImpl::SendNotification( - const OutgoingNotificationData& data) { + const Notification& data) { DCHECK_EQ(MessageLoop::current(), parent_message_loop_); worker_message_loop()->PostTask( FROM_HERE, @@ -170,59 +172,58 @@ void MediatorThreadImpl::DoDisconnect() { base_task_.reset(); } -void MediatorThreadImpl::DoSubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list) { +void MediatorThreadImpl::ListenForPushNotifications() { DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - if (!base_task_.get()) { + if (!base_task_.get()) return; - } - // Owned by |base_task_|. - SubscribeTask* subscription = - new SubscribeTask(base_task_, subscribed_services_list); - subscription->SignalStatusUpdate.connect( - this, - &MediatorThreadImpl::OnSubscriptionStateChange); - subscription->Start(); + PushNotificationsListenTask* listener = + new PushNotificationsListenTask(base_task_, this); + listener->Start(); } -void MediatorThreadImpl::DoListenForUpdates() { +void MediatorThreadImpl::SubscribeForPushNotifications( + const SubscriptionList& subscriptions) { DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - if (!base_task_.get()) { + if (!base_task_.get()) return; - } - // Owned by |base_task_|. - ListenTask* listener = new ListenTask(base_task_); - listener->SignalUpdateAvailable.connect( - this, - &MediatorThreadImpl::OnIncomingNotification); - listener->Start(); + DCHECK_EQ(MessageLoop::current(), worker_message_loop()); + PushNotificationsSubscribeTask* subscribe_task = + new PushNotificationsSubscribeTask(base_task_, subscriptions, this); + subscribe_task->Start(); +} + +void MediatorThreadImpl::OnSubscribed() { + DCHECK_EQ(MessageLoop::current(), worker_message_loop()); + observers_->Notify(&Observer::OnSubscriptionStateChange, true); +} + +void MediatorThreadImpl::OnSubscriptionError() { + DCHECK_EQ(MessageLoop::current(), worker_message_loop()); + observers_->Notify(&Observer::OnSubscriptionStateChange, false); +} + +void MediatorThreadImpl::OnNotificationReceived( + const Notification& notification) { + OnIncomingNotification(notification); } void MediatorThreadImpl::DoSendNotification( - const OutgoingNotificationData& data) { + const Notification& data) { DCHECK_EQ(MessageLoop::current(), worker_message_loop()); if (!base_task_.get()) { return; } // Owned by |base_task_|. - SendUpdateTask* task = new SendUpdateTask(base_task_, data); - task->SignalStatusUpdate.connect( - this, - &MediatorThreadImpl::OnOutgoingNotification); + PushNotificationsSendUpdateTask* task = + new PushNotificationsSendUpdateTask(base_task_, data); task->Start(); + observers_->Notify(&Observer::OnOutgoingNotification); } void MediatorThreadImpl::OnIncomingNotification( - const IncomingNotificationData& notification_data) { - DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - observers_->Notify(&Observer::OnIncomingNotification, notification_data); -} - -void MediatorThreadImpl::OnOutgoingNotification(bool success) { + const Notification& notification) { DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - if (success) { - observers_->Notify(&Observer::OnOutgoingNotification); - } + observers_->Notify(&Observer::OnIncomingNotification, notification); } void MediatorThreadImpl::OnConnect(base::WeakPtr<talk_base::Task> base_task) { @@ -237,9 +238,4 @@ void MediatorThreadImpl::OnDisconnect() { observers_->Notify(&Observer::OnConnectionStateChange, false); } -void MediatorThreadImpl::OnSubscriptionStateChange(bool success) { - DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - observers_->Notify(&Observer::OnSubscriptionStateChange, success); -} - } // namespace notifier diff --git a/jingle/notifier/listener/mediator_thread_impl.h b/jingle/notifier/listener/mediator_thread_impl.h index 548a307..aeacb32 100644 --- a/jingle/notifier/listener/mediator_thread_impl.h +++ b/jingle/notifier/listener/mediator_thread_impl.h @@ -33,7 +33,8 @@ #include "jingle/notifier/base/notifier_options.h" #include "jingle/notifier/communicator/login.h" #include "jingle/notifier/listener/mediator_thread.h" -#include "talk/base/sigslot.h" +#include "jingle/notifier/listener/push_notifications_listen_task.h" +#include "jingle/notifier/listener/push_notifications_subscribe_task.h" class MessageLoop; @@ -52,7 +53,8 @@ namespace notifier { typedef Login::Delegate LoginDelegate; class MediatorThreadImpl : public MediatorThread, public LoginDelegate, - public sigslot::has_slots<> { + public PushNotificationsListenTaskDelegate, + public PushNotificationsSubscribeTaskDelegate { public: explicit MediatorThreadImpl(const NotifierOptions& notifier_options); virtual ~MediatorThreadImpl(); @@ -68,14 +70,20 @@ class MediatorThreadImpl : public MediatorThread, public LoginDelegate, virtual void Login(const buzz::XmppClientSettings& settings); virtual void Logout(); virtual void ListenForUpdates(); - virtual void SubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list); - virtual void SendNotification(const OutgoingNotificationData& data); + virtual void SubscribeForUpdates(const SubscriptionList& subscriptions); + virtual void SendNotification(const Notification& data); // Login::Delegate implementation. virtual void OnConnect(base::WeakPtr<talk_base::Task> base_task); virtual void OnDisconnect(); + // PushNotificationsListenTaskDelegate implementation. + virtual void OnNotificationReceived( + const Notification& notification); + // PushNotificationsSubscribeTaskDelegate implementation. + virtual void OnSubscribed(); + virtual void OnSubscriptionError(); + protected: // Should only be called after Start(). MessageLoop* worker_message_loop(); @@ -84,8 +92,7 @@ class MediatorThreadImpl : public MediatorThread, public LoginDelegate, // world. These are all called from the worker thread. They are protected // so they can be used by subclasses. void OnIncomingNotification( - const IncomingNotificationData& notification_data); - void OnOutgoingNotification(bool success); + const Notification& notification); void OnSubscriptionStateChange(bool success); scoped_refptr<ObserverListThreadSafe<Observer> > observers_; @@ -95,11 +102,14 @@ class MediatorThreadImpl : public MediatorThread, public LoginDelegate, private: void DoLogin(const buzz::XmppClientSettings& settings); void DoDisconnect(); - void DoSubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list); - void DoListenForUpdates(); + + // Helpers invoked on worker thread. + void ListenForPushNotifications(); + void SubscribeForPushNotifications( + const SubscriptionList& subscriptions); + void DoSendNotification( - const OutgoingNotificationData& data); + const Notification& data); const NotifierOptions notifier_options_; diff --git a/jingle/notifier/listener/mediator_thread_mock.cc b/jingle/notifier/listener/mediator_thread_mock.cc index 92543dd..e161986 100644 --- a/jingle/notifier/listener/mediator_thread_mock.cc +++ b/jingle/notifier/listener/mediator_thread_mock.cc @@ -51,7 +51,7 @@ void MockMediatorThread::Start() { } void MockMediatorThread::SubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list) { + const SubscriptionList& subscriptions) { subscribe_calls++; if (observer_) { observer_->OnSubscriptionStateChange(true); @@ -62,7 +62,7 @@ void MockMediatorThread::ListenForUpdates() { listen_calls++; } -void MockMediatorThread::SendNotification(const OutgoingNotificationData &) { +void MockMediatorThread::SendNotification(const Notification &) { send_calls++; if (observer_) { observer_->OnOutgoingNotification(); @@ -70,7 +70,7 @@ void MockMediatorThread::SendNotification(const OutgoingNotificationData &) { } void MockMediatorThread::ReceiveNotification( - const IncomingNotificationData& data) { + const Notification& data) { if (observer_) { observer_->OnIncomingNotification(data); } diff --git a/jingle/notifier/listener/mediator_thread_mock.h b/jingle/notifier/listener/mediator_thread_mock.h index 897570a..1f4ae76 100644 --- a/jingle/notifier/listener/mediator_thread_mock.h +++ b/jingle/notifier/listener/mediator_thread_mock.h @@ -39,14 +39,13 @@ class MockMediatorThread : public MediatorThread { virtual void Start(); - virtual void SubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list); + virtual void SubscribeForUpdates(const SubscriptionList& subscriptions); virtual void ListenForUpdates(); - virtual void SendNotification(const OutgoingNotificationData &); + virtual void SendNotification(const Notification &); - void ReceiveNotification(const IncomingNotificationData& data); + void ReceiveNotification(const Notification& data); Observer* observer_; // Internal State diff --git a/jingle/notifier/listener/notification_constants.cc b/jingle/notifier/listener/notification_constants.cc index 33d402e..28edc84 100644 --- a/jingle/notifier/listener/notification_constants.cc +++ b/jingle/notifier/listener/notification_constants.cc @@ -6,7 +6,6 @@ namespace notifier { -const char kNotifierNamespace[] = "google:notifier"; const char kPushNotificationsNamespace[] = "google:push"; } // namespace notifier diff --git a/jingle/notifier/listener/notification_constants.h b/jingle/notifier/listener/notification_constants.h index 43d386f..7b0bbfa 100644 --- a/jingle/notifier/listener/notification_constants.h +++ b/jingle/notifier/listener/notification_constants.h @@ -7,7 +7,6 @@ namespace notifier { -extern const char kNotifierNamespace[]; extern const char kPushNotificationsNamespace[]; } // namespace notifier diff --git a/jingle/notifier/listener/notification_defines.cc b/jingle/notifier/listener/notification_defines.cc deleted file mode 100644 index c5e7ac3..0000000 --- a/jingle/notifier/listener/notification_defines.cc +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2011 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 "jingle/notifier/listener/notification_defines.h" - -OutgoingNotificationData::OutgoingNotificationData() - : send_content(false), - priority(0), - require_subscription(false), - write_to_cache_only(false) { -} - -OutgoingNotificationData::~OutgoingNotificationData() {} diff --git a/jingle/notifier/listener/notification_defines.h b/jingle/notifier/listener/notification_defines.h index 0e644d2..5cf9f72 100644 --- a/jingle/notifier/listener/notification_defines.h +++ b/jingle/notifier/listener/notification_defines.h @@ -6,28 +6,28 @@ #define JINGLE_NOTIFIER_LISTENER_NOTIFICATION_DEFINES_H_ #include <string> +#include <vector> -struct IncomingNotificationData { - std::string service_url; - std::string service_specific_data; +namespace notifier { + +struct Subscription { + // The name of the channel to subscribe to; usually but not always + // a URL. + std::string channel; + // A sender, which could be a domain or a bare JID, from which we + // will accept pushes. + std::string from; }; -struct OutgoingNotificationData { - OutgoingNotificationData(); - ~OutgoingNotificationData(); - - // Id values - std::string service_url; - std::string service_id; - // This bool signifies whether the content fields should be - // sent with the outgoing data. - bool send_content; - // Content values. - std::string service_specific_data; - int priority; - bool require_subscription; - bool write_to_cache_only; +typedef std::vector<Subscription> SubscriptionList; + +struct Notification { + // The channel the notification is coming in on. + std::string channel; + // The notification data payload. + std::string data; }; -#endif // JINGLE_NOTIFIER_LISTENER_NOTIFICATION_DEFINES_H_ +} // namespace notifier +#endif // JINGLE_NOTIFIER_LISTENER_NOTIFICATION_DEFINES_H_ diff --git a/jingle/notifier/listener/push_notifications_listen_task.cc b/jingle/notifier/listener/push_notifications_listen_task.cc index 90b5c0a..8617f84 100644 --- a/jingle/notifier/listener/push_notifications_listen_task.cc +++ b/jingle/notifier/listener/push_notifications_listen_task.cc @@ -56,16 +56,16 @@ int PushNotificationsListenTask::ProcessResponse() { const buzz::XmlElement* push_element = stanza->FirstNamed(buzz::QName(kPushNotificationsNamespace, "push")); if (push_element) { - IncomingNotificationData notification_data; - notification_data.service_url = + Notification notification; + notification.channel = push_element->Attr(buzz::QName(buzz::STR_EMPTY, "channel")); const buzz::XmlElement* data_element = push_element->FirstNamed( buzz::QName(kPushNotificationsNamespace, "data")); if (data_element) { base::Base64Decode(data_element->BodyText(), - ¬ification_data.service_specific_data); + ¬ification.data); } - delegate_->OnNotificationReceived(notification_data); + delegate_->OnNotificationReceived(notification); } else { LOG(WARNING) << "Push notifications: No push element found in response stanza"; diff --git a/jingle/notifier/listener/push_notifications_listen_task.h b/jingle/notifier/listener/push_notifications_listen_task.h index 341ddf1..8eb764e 100644 --- a/jingle/notifier/listener/push_notifications_listen_task.h +++ b/jingle/notifier/listener/push_notifications_listen_task.h @@ -19,17 +19,17 @@ namespace buzz { class XmlElement; } -struct IncomingNotificationData; - namespace notifier { +struct Notification; + class PushNotificationsListenTask : public buzz::XmppTask { public: class Delegate { public: virtual ~Delegate() {} virtual void OnNotificationReceived( - const IncomingNotificationData& notification) = 0; + const Notification& notification) = 0; }; explicit PushNotificationsListenTask(Task* parent, Delegate* delegate); diff --git a/jingle/notifier/listener/push_notifications_send_update_task.cc b/jingle/notifier/listener/push_notifications_send_update_task.cc new file mode 100644 index 0000000..d55fc34 --- /dev/null +++ b/jingle/notifier/listener/push_notifications_send_update_task.cc @@ -0,0 +1,73 @@ +// Copyright (c) 2010 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 "jingle/notifier/listener/push_notifications_send_update_task.h" + +#include <string> + +#include "base/base64.h" +#include "base/logging.h" +#include "base/scoped_ptr.h" +#include "jingle/notifier/listener/notification_constants.h" +#include "jingle/notifier/listener/xml_element_util.h" +#include "talk/xmllite/qname.h" +#include "talk/xmllite/xmlelement.h" +#include "talk/xmpp/constants.h" +#include "talk/xmpp/jid.h" +#include "talk/xmpp/xmppclient.h" + +namespace notifier { + +PushNotificationsSendUpdateTask::PushNotificationsSendUpdateTask( + TaskParent* parent, const Notification& notification) + : XmppTask(parent), notification_(notification) {} + +PushNotificationsSendUpdateTask::~PushNotificationsSendUpdateTask() {} + +int PushNotificationsSendUpdateTask::ProcessStart() { + scoped_ptr<buzz::XmlElement> stanza( + MakeUpdateMessage(notification_, + GetClient()->jid().BareJid())); + VLOG(1) << "P2P: Sending notification: " << XmlElementToString(*stanza); + if (SendStanza(stanza.get()) != buzz::XMPP_RETURN_OK) { + LOG(WARNING) << "Could not send: " << XmlElementToString(*stanza); + } + return STATE_DONE; +} + +buzz::XmlElement* PushNotificationsSendUpdateTask::MakeUpdateMessage( + const Notification& notification, + const buzz::Jid& to_jid_bare) { + DCHECK(to_jid_bare.IsBare()); + const buzz::QName kQnPush(kPushNotificationsNamespace, "push"); + const buzz::QName kQnChannel(buzz::STR_EMPTY, "channel"); + const buzz::QName kQnData(buzz::STR_EMPTY, "data"); + + // Create our update stanza. The message is constructed as: + // <message from='{fullJid}' to='{bareJid}' type='headline'> + // <push xmlns='google:push' channel='{channel}'> + // <data>{base-64 encoded data}</data> + // </push> + // </message> + + buzz::XmlElement* message = new buzz::XmlElement(buzz::QN_MESSAGE); + message->AddAttr(buzz::QN_TO, to_jid_bare.Str()); + message->AddAttr(buzz::QN_TYPE, "headline"); + + buzz::XmlElement* push = new buzz::XmlElement(kQnPush, true); + push->AddAttr(kQnChannel, notification.channel); + message->AddElement(push); + + buzz::XmlElement* data = new buzz::XmlElement(kQnData, true); + std::string base64_data; + if (!base::Base64Encode(notification.data, &base64_data)) { + LOG(WARNING) << "Could not encode data: " << notification.data; + } + data->SetBodyText(base64_data); + push->AddElement(data); + + return message; +} + +} // namespace notifier diff --git a/jingle/notifier/listener/push_notifications_send_update_task.h b/jingle/notifier/listener/push_notifications_send_update_task.h new file mode 100644 index 0000000..40aa7dc --- /dev/null +++ b/jingle/notifier/listener/push_notifications_send_update_task.h @@ -0,0 +1,46 @@ +// Copyright (c) 2009 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. +// +// Methods for sending the update stanza to notify peers via xmpp. + +#ifndef JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SEND_UPDATE_TASK_H_ +#define JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SEND_UPDATE_TASK_H_ + +#include "base/basictypes.h" +#include "base/gtest_prod_util.h" +#include "jingle/notifier/listener/notification_defines.h" +#include "talk/xmpp/xmpptask.h" + +namespace buzz { +class Jid; +class XmlElement; +} // namespace + +namespace notifier { + +class PushNotificationsSendUpdateTask : public buzz::XmppTask { + public: + PushNotificationsSendUpdateTask( + TaskParent* parent, const Notification& notification); + virtual ~PushNotificationsSendUpdateTask(); + + // Overridden from buzz::XmppTask. + virtual int ProcessStart(); + + private: + // Allocates and constructs an buzz::XmlElement containing the update stanza. + static buzz::XmlElement* MakeUpdateMessage( + const Notification& notification, const buzz::Jid& to_jid_bare); + + const Notification notification_; + + FRIEND_TEST_ALL_PREFIXES(PushNotificationsSendUpdateTaskTest, + MakeUpdateMessage); + + DISALLOW_COPY_AND_ASSIGN(PushNotificationsSendUpdateTask); +}; + +} // namespace notifier + +#endif // JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_SEND_UPDATE_TASK_H_ diff --git a/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc b/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc new file mode 100644 index 0000000..b4269a2 --- /dev/null +++ b/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc @@ -0,0 +1,58 @@ +// Copyright (c) 2010 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 "jingle/notifier/listener/push_notifications_send_update_task.h" + +#include "base/base64.h" +#include "base/scoped_ptr.h" +#include "base/string_util.h" +#include "jingle/notifier/listener/xml_element_util.h" +#include "talk/xmpp/jid.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace buzz { +class XmlElement; +} + +namespace notifier { + +class PushNotificationsSendUpdateTaskTest : public testing::Test { + public: + PushNotificationsSendUpdateTaskTest() : to_jid_bare_("to@jid.com") { + EXPECT_EQ(to_jid_bare_.Str(), to_jid_bare_.BareJid().Str()); + } + + protected: + const buzz::Jid to_jid_bare_; + + private: + DISALLOW_COPY_AND_ASSIGN(PushNotificationsSendUpdateTaskTest); +}; + +TEST_F(PushNotificationsSendUpdateTaskTest, MakeUpdateMessage) { + Notification notification; + notification.channel = "test_channel"; + notification.data = "test_data"; + + std::string base64_data; + EXPECT_TRUE(base::Base64Encode(notification.data, &base64_data)); + + scoped_ptr<buzz::XmlElement> message( + PushNotificationsSendUpdateTask::MakeUpdateMessage( + notification, to_jid_bare_)); + + std::string expected_xml_string = + StringPrintf( + "<cli:message to=\"%s\" type=\"headline\" " + "xmlns:cli=\"jabber:client\">" + "<push xmlns=\"google:push\" channel=\"%s\">" + "<data xmlns=\"\">%s</data>" + "</push>" + "</cli:message>", + to_jid_bare_.Str().c_str(), notification.channel.c_str(), + base64_data.c_str()); + EXPECT_EQ(expected_xml_string, XmlElementToString(*message)); +} + +} // namespace notifier diff --git a/jingle/notifier/listener/push_notifications_subscribe_task.cc b/jingle/notifier/listener/push_notifications_subscribe_task.cc index d63c775..d8453ca 100644 --- a/jingle/notifier/listener/push_notifications_subscribe_task.cc +++ b/jingle/notifier/listener/push_notifications_subscribe_task.cc @@ -20,10 +20,10 @@ namespace notifier { PushNotificationsSubscribeTask::PushNotificationsSubscribeTask( TaskParent* parent, - const std::vector<PushSubscriptionInfo>& channels_list, + const SubscriptionList& subscriptions, Delegate* delegate) : XmppTask(parent, buzz::XmppEngine::HL_SINGLE), - channels_list_(channels_list), delegate_(delegate) { + subscriptions_(subscriptions), delegate_(delegate) { } PushNotificationsSubscribeTask::~PushNotificationsSubscribeTask() { @@ -40,7 +40,7 @@ bool PushNotificationsSubscribeTask::HandleStanza( int PushNotificationsSubscribeTask::ProcessStart() { VLOG(1) << "Push notifications: Subscription task started."; scoped_ptr<buzz::XmlElement> iq_stanza( - MakeSubscriptionMessage(channels_list_, GetClient()->jid(), + MakeSubscriptionMessage(subscriptions_, GetClient()->jid(), task_id())); std::string stanza_str = XmlElementToString(*iq_stanza.get()); VLOG(1) << "Push notifications: Subscription stanza: " @@ -77,7 +77,7 @@ int PushNotificationsSubscribeTask::ProcessResponse() { } buzz::XmlElement* PushNotificationsSubscribeTask::MakeSubscriptionMessage( - const std::vector<PushSubscriptionInfo>& channels_list, + const SubscriptionList& subscriptions, const buzz::Jid& jid, const std::string& task_id) { DCHECK(jid.IsFull()); static const buzz::QName kQnSubscribe( @@ -95,8 +95,8 @@ buzz::XmlElement* PushNotificationsSubscribeTask::MakeSubscriptionMessage( buzz::XmlElement* subscribe = new buzz::XmlElement(kQnSubscribe, true); iq->AddElement(subscribe); - for (std::vector<PushSubscriptionInfo>::const_iterator iter = - channels_list.begin(); iter != channels_list.end(); ++iter) { + for (SubscriptionList::const_iterator iter = + subscriptions.begin(); iter != subscriptions.end(); ++iter) { buzz::XmlElement* item = new buzz::XmlElement( buzz::QName(kPushNotificationsNamespace, "item")); item->AddAttr(buzz::QName(buzz::STR_EMPTY, "channel"), diff --git a/jingle/notifier/listener/push_notifications_subscribe_task.h b/jingle/notifier/listener/push_notifications_subscribe_task.h index 5dbdb32..8dd4699 100644 --- a/jingle/notifier/listener/push_notifications_subscribe_task.h +++ b/jingle/notifier/listener/push_notifications_subscribe_task.h @@ -11,6 +11,7 @@ #include <vector> #include "base/gtest_prod_util.h" +#include "jingle/notifier/listener/notification_defines.h" #include "talk/xmllite/xmlelement.h" #include "talk/xmpp/xmpptask.h" @@ -24,13 +25,8 @@ class PushNotificationsSubscribeTask : public buzz::XmppTask { virtual void OnSubscriptionError() = 0; }; - struct PushSubscriptionInfo { - std::string channel; - std::string from; - }; - PushNotificationsSubscribeTask(TaskParent* parent, - const std::vector<PushSubscriptionInfo>& channels_list, + const SubscriptionList& subscriptions, Delegate* delegate); virtual ~PushNotificationsSubscribeTask(); @@ -42,10 +38,10 @@ class PushNotificationsSubscribeTask : public buzz::XmppTask { private: // Assembles an Xmpp stanza which can be sent to subscribe to notifications. static buzz::XmlElement* MakeSubscriptionMessage( - const std::vector<PushSubscriptionInfo>& channels_list, + const SubscriptionList& subscriptions, const buzz::Jid& jid, const std::string& task_id); - std::vector<PushSubscriptionInfo> channels_list_; + SubscriptionList subscriptions_; Delegate* delegate_; FRIEND_TEST_ALL_PREFIXES(PushNotificationsSubscribeTaskTest, diff --git a/jingle/notifier/listener/push_notifications_subscribe_task_unittest.cc b/jingle/notifier/listener/push_notifications_subscribe_task_unittest.cc index 752c762..c9ce499 100644 --- a/jingle/notifier/listener/push_notifications_subscribe_task_unittest.cc +++ b/jingle/notifier/listener/push_notifications_subscribe_task_unittest.cc @@ -32,19 +32,18 @@ class PushNotificationsSubscribeTaskTest : public testing::Test { }; TEST_F(PushNotificationsSubscribeTaskTest, MakeSubscriptionMessage) { - std::vector<PushNotificationsSubscribeTask::PushSubscriptionInfo> - subscription_list; + SubscriptionList subscriptions; - PushNotificationsSubscribeTask::PushSubscriptionInfo subscription; + Subscription subscription; subscription.channel = "test_channel1"; subscription.from = "from.test.com"; - subscription_list.push_back(subscription); + subscriptions.push_back(subscription); subscription.channel = "test_channel2"; subscription.from = "from.test2.com"; - subscription_list.push_back(subscription); + subscriptions.push_back(subscription); scoped_ptr<buzz::XmlElement> message( PushNotificationsSubscribeTask::MakeSubscriptionMessage( - subscription_list, jid_, task_id_)); + subscriptions, jid_, task_id_)); std::string expected_xml_string = StringPrintf( "<cli:iq type=\"set\" to=\"%s\" id=\"%s\" " diff --git a/jingle/notifier/listener/push_notifications_thread.cc b/jingle/notifier/listener/push_notifications_thread.cc deleted file mode 100644 index 4c927ee..0000000 --- a/jingle/notifier/listener/push_notifications_thread.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2010 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 "jingle/notifier/listener/push_notifications_thread.h" - -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/task.h" -#include "jingle/notifier/listener/notification_defines.h" -#include "talk/xmpp/xmppclient.h" - -namespace notifier { - -PushNotificationsThread::PushNotificationsThread( - const NotifierOptions& notifier_options, const std::string& from) - : MediatorThreadImpl(notifier_options), from_(from) { -} - -PushNotificationsThread::~PushNotificationsThread() { - DCHECK_EQ(MessageLoop::current(), parent_message_loop_); -} - -void PushNotificationsThread::ListenForUpdates() { - DCHECK_EQ(MessageLoop::current(), parent_message_loop_); - worker_message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, - &PushNotificationsThread::ListenForPushNotifications)); -} - -void PushNotificationsThread::SubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list) { - DCHECK_EQ(MessageLoop::current(), parent_message_loop_); - worker_message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, - &PushNotificationsThread::SubscribeForPushNotifications, - subscribed_services_list)); -} - -void PushNotificationsThread::SendNotification( - const OutgoingNotificationData& data) { - DCHECK_EQ(MessageLoop::current(), parent_message_loop_); -} - -void PushNotificationsThread::ListenForPushNotifications() { - DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - if (!base_task_.get()) - return; - PushNotificationsListenTask* listener = - new PushNotificationsListenTask(base_task_, this); - listener->Start(); -} - -void PushNotificationsThread::SubscribeForPushNotifications( - const std::vector<std::string>& subscribed_services_list) { - DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - if (!base_task_.get()) - return; - std::vector<PushNotificationsSubscribeTask::PushSubscriptionInfo> - channels_list; - for (std::vector<std::string>::const_iterator iter = - subscribed_services_list.begin(); - iter != subscribed_services_list.end(); iter++) { - PushNotificationsSubscribeTask::PushSubscriptionInfo subscription; - subscription.channel = *iter; - subscription.from = from_; - channels_list.push_back(subscription); - } - DCHECK_EQ(MessageLoop::current(), worker_message_loop()); - PushNotificationsSubscribeTask* subscription = - new PushNotificationsSubscribeTask(base_task_, channels_list, this); - subscription->Start(); -} - -void PushNotificationsThread::OnSubscribed() { - OnSubscriptionStateChange(true); -} - -void PushNotificationsThread::OnSubscriptionError() { - OnSubscriptionStateChange(false); -} - -void PushNotificationsThread::OnNotificationReceived( - const IncomingNotificationData& notification) { - OnIncomingNotification(notification); -} - -} // namespace notifier - diff --git a/jingle/notifier/listener/push_notifications_thread.h b/jingle/notifier/listener/push_notifications_thread.h deleted file mode 100644 index 74af76b..0000000 --- a/jingle/notifier/listener/push_notifications_thread.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2010 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. -// -// An implementaion of MediatorThreadImpl to subscribe and listen for -// notifications using the new Google Push notifications service. - -#ifndef JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_THREAD_H_ -#define JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_THREAD_H_ - -#include <string> -#include <vector> - -#include "jingle/notifier/listener/mediator_thread_impl.h" -#include "jingle/notifier/listener/push_notifications_listen_task.h" -#include "jingle/notifier/listener/push_notifications_subscribe_task.h" - -namespace notifier { - -class PushNotificationsThread - : public MediatorThreadImpl, - public PushNotificationsListenTaskDelegate, - public PushNotificationsSubscribeTaskDelegate { - public: - explicit PushNotificationsThread( - const NotifierOptions& notifier_options, const std::string& from); - virtual ~PushNotificationsThread(); - - // MediatorThreadImpl overrides. - virtual void ListenForUpdates(); - // TODO(sanjeevr): Because we are using the MediatorThread interface which - // was designed for the old notifications scheme, this class is limited to - // subscribing to multiple channels from the same source (the |from| c'tor - // argument). We need to extend the interface to handle the new push - // notifications service. - virtual void SubscribeForUpdates( - const std::vector<std::string>& subscribed_services_list); - virtual void SendNotification(const OutgoingNotificationData& data); - - // PushNotificationsListenTaskDelegate implementation. - virtual void OnNotificationReceived( - const IncomingNotificationData& notification); - // PushNotificationsSubscribeTaskDelegate implementation. - virtual void OnSubscribed(); - virtual void OnSubscriptionError(); - - private: - // Helpers invoked on worker thread. - void ListenForPushNotifications(); - void SubscribeForPushNotifications( - const std::vector<std::string>& subscribed_services_list); - - std::string from_; - - DISALLOW_COPY_AND_ASSIGN(PushNotificationsThread); -}; - -} // namespace notifier - -DISABLE_RUNNABLE_METHOD_REFCOUNT(notifier::PushNotificationsThread); - -#endif // JINGLE_NOTIFIER_LISTENER_PUSH_NOTIFICATIONS_THREAD_H_ - diff --git a/jingle/notifier/listener/send_update_task.cc b/jingle/notifier/listener/send_update_task.cc deleted file mode 100644 index 313b63f..0000000 --- a/jingle/notifier/listener/send_update_task.cc +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2010 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 "jingle/notifier/listener/send_update_task.h" - -#include <string> - -#include "base/logging.h" -#include "base/scoped_ptr.h" -#include "jingle/notifier/listener/notification_constants.h" -#include "jingle/notifier/listener/xml_element_util.h" -#include "talk/xmllite/qname.h" -#include "talk/xmpp/xmppclient.h" -#include "talk/xmpp/constants.h" - -namespace notifier { - -SendUpdateTask::SendUpdateTask(TaskParent* parent, - const OutgoingNotificationData& data) - : XmppTask(parent, buzz::XmppEngine::HL_SINGLE), // Watch for one reply. - notification_data_(data) { -} - -SendUpdateTask::~SendUpdateTask() { -} - -bool SendUpdateTask::HandleStanza(const buzz::XmlElement* stanza) { - if (!MatchResponseIq(stanza, GetClient()->jid().BareJid(), task_id())) - return false; - QueueStanza(stanza); - return true; -} - -int SendUpdateTask::ProcessStart() { - VLOG(1) << "P2P: Notification task started."; - scoped_ptr<buzz::XmlElement> stanza( - MakeUpdateMessage(notification_data_, - GetClient()->jid().BareJid(), task_id())); - VLOG(1) << "P2P: Notification stanza: " << XmlElementToString(*stanza.get()); - - if (SendStanza(stanza.get()) != buzz::XMPP_RETURN_OK) { - // TODO(brg) : Retry on error. - // TODO(akalin): Or maybe immediately return STATE_ERROR and let - // retries happen a higher level. In any case, STATE_ERROR should - // eventually be returned. - SignalStatusUpdate(false); - return STATE_DONE; - } - return STATE_RESPONSE; -} - -int SendUpdateTask::ProcessResponse() { - VLOG(1) << "P2P: Notification response received."; - const buzz::XmlElement* stanza = NextStanza(); - if (stanza == NULL) { - return STATE_BLOCKED; - } - VLOG(1) << "P2P: Notification response: " << XmlElementToString(*stanza); - if (stanza->HasAttr(buzz::QN_TYPE) && - stanza->Attr(buzz::QN_TYPE) == buzz::STR_RESULT) { - // Notify listeners of success. - SignalStatusUpdate(true); - return STATE_DONE; - } - - // An error response was received. - // TODO(brg) : Error handling. - SignalStatusUpdate(false); - // TODO(akalin): This should be STATE_ERROR. - return STATE_DONE; -} - -buzz::XmlElement* SendUpdateTask::MakeUpdateMessage( - const OutgoingNotificationData& notification_data, - const buzz::Jid& to_jid_bare, const std::string& task_id) { - DCHECK(to_jid_bare.IsBare()); - static const buzz::QName kQnNotifierSet(kNotifierNamespace, "set"); - static const buzz::QName kQnId(buzz::STR_EMPTY, "Id"); - static const buzz::QName kQnContent(buzz::STR_EMPTY, "Content"); - - // Create our update stanza. The message is constructed as: - // <iq type='get' from='{fullJid}' to='{bareJid}' id='{#}'> - // <gn:set xmlns:gn="google:notifier" xmlns=""> - // <Id> - // <ServiceUrl data="{Service_Url}" /> - // <ServiceId data="{Service_Id}" /> - // </Id> - // If content needs to be sent, then the below element is added - // <Content> - // <Priority int="{Priority}" /> - // <RequireSubscription bool="{true/false}" /> - // <ServiceSpecificData data="{ServiceData}" /> - // <WriteToCacheOnly bool="{true/false}" /> - // </Content> - // </set> - // </iq> - buzz::XmlElement* iq = MakeIq(buzz::STR_GET, to_jid_bare, task_id); - buzz::XmlElement* set = new buzz::XmlElement(kQnNotifierSet, true); - buzz::XmlElement* id = new buzz::XmlElement(kQnId, true); - iq->AddElement(set); - set->AddElement(id); - - id->AddElement(MakeStringXmlElement("ServiceUrl", - notification_data.service_url.c_str())); - id->AddElement(MakeStringXmlElement("ServiceId", - notification_data.service_id.c_str())); - - if (notification_data.send_content) { - buzz::XmlElement* content = new buzz::XmlElement(kQnContent, true); - set->AddElement(content); - content->AddElement(MakeIntXmlElement("Priority", - notification_data.priority)); - content->AddElement( - MakeBoolXmlElement("RequireSubscription", - notification_data.require_subscription)); - if (!notification_data.service_specific_data.empty()) { - content->AddElement( - MakeStringXmlElement("ServiceSpecificData", - notification_data.service_specific_data.c_str())); - } - content->AddElement( - MakeBoolXmlElement("WriteToCacheOnly", - notification_data.write_to_cache_only)); - } - return iq; -} - -} // namespace notifier diff --git a/jingle/notifier/listener/send_update_task.h b/jingle/notifier/listener/send_update_task.h deleted file mode 100644 index ea71857..0000000 --- a/jingle/notifier/listener/send_update_task.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2009 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. -// -// Methods for sending the update stanza to notify peers via xmpp. - -#ifndef JINGLE_NOTIFIER_LISTENER_SEND_UPDATE_TASK_H_ -#define JINGLE_NOTIFIER_LISTENER_SEND_UPDATE_TASK_H_ - -#include <string> - -#include "base/gtest_prod_util.h" -#include "jingle/notifier/listener/notification_defines.h" -#include "talk/xmllite/xmlelement.h" -#include "talk/xmpp/xmpptask.h" - -namespace notifier { - -class SendUpdateTask : public buzz::XmppTask { - public: - SendUpdateTask(TaskParent* parent, const OutgoingNotificationData& data); - virtual ~SendUpdateTask(); - - // Overridden from buzz::XmppTask. - virtual int ProcessStart(); - virtual int ProcessResponse(); - virtual bool HandleStanza(const buzz::XmlElement* stanza); - - // Signal callback upon subscription success. - sigslot::signal1<bool> SignalStatusUpdate; - - private: - // Allocates and constructs an buzz::XmlElement containing the update stanza. - static buzz::XmlElement* MakeUpdateMessage( - const OutgoingNotificationData& notification_data, - const buzz::Jid& to_jid_bare, const std::string& task_id); - - OutgoingNotificationData notification_data_; - - FRIEND_TEST_ALL_PREFIXES(SendUpdateTaskTest, MakeUpdateMessage); - - DISALLOW_COPY_AND_ASSIGN(SendUpdateTask); -}; - -} // namespace notifier - -#endif // JINGLE_NOTIFIER_LISTENER_SEND_UPDATE_TASK_H_ diff --git a/jingle/notifier/listener/send_update_task_unittest.cc b/jingle/notifier/listener/send_update_task_unittest.cc deleted file mode 100644 index 82d3a83..0000000 --- a/jingle/notifier/listener/send_update_task_unittest.cc +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2010 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 "jingle/notifier/listener/send_update_task.h" - -#include "base/scoped_ptr.h" -#include "base/string_util.h" -#include "jingle/notifier/listener/xml_element_util.h" -#include "talk/xmpp/jid.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace buzz { -class XmlElement; -} - -namespace notifier { - -class SendUpdateTaskTest : public testing::Test { - public: - SendUpdateTaskTest() : to_jid_bare_("to@jid.com"), task_id_("taskid") { - EXPECT_EQ(to_jid_bare_.Str(), to_jid_bare_.BareJid().Str()); - } - - protected: - const buzz::Jid to_jid_bare_; - const std::string task_id_; - - private: - DISALLOW_COPY_AND_ASSIGN(SendUpdateTaskTest); -}; - -TEST_F(SendUpdateTaskTest, MakeUpdateMessage) { - OutgoingNotificationData data; - data.service_id = "test_service_id"; - data.service_url = "test_service_url"; - data.send_content = false; - data.priority = 200; - data.write_to_cache_only = true; - data.require_subscription = false; - - scoped_ptr<buzz::XmlElement> message_without_content( - SendUpdateTask::MakeUpdateMessage(data, to_jid_bare_, task_id_)); - - std::string expected_xml_string = - StringPrintf( - "<cli:iq type=\"get\" to=\"%s\" id=\"%s\" " - "xmlns:cli=\"jabber:client\">" - "<set xmlns=\"google:notifier\">" - "<Id xmlns=\"\">" - "<ServiceUrl xmlns=\"\" data=\"test_service_url\"/>" - "<ServiceId xmlns=\"\" data=\"test_service_id\"/>" - "</Id>" - "</set>" - "</cli:iq>", - to_jid_bare_.Str().c_str(), task_id_.c_str()); - EXPECT_EQ(expected_xml_string, XmlElementToString(*message_without_content)); - - data.send_content = true; - - expected_xml_string = - StringPrintf( - "<cli:iq type=\"get\" to=\"%s\" id=\"%s\" " - "xmlns:cli=\"jabber:client\">" - "<set xmlns=\"google:notifier\">" - "<Id xmlns=\"\">" - "<ServiceUrl xmlns=\"\" " - "data=\"test_service_url\"/>" - "<ServiceId xmlns=\"\" data=\"test_service_id\"/>" - "</Id>" - "<Content xmlns=\"\">" - "<Priority xmlns=\"\" int=\"200\"/>" - "<RequireSubscription xmlns=\"\" bool=\"false\"/>" - "<WriteToCacheOnly xmlns=\"\" bool=\"true\"/>" - "</Content>" - "</set>" - "</cli:iq>", - to_jid_bare_.Str().c_str(), task_id_.c_str()); - - scoped_ptr<buzz::XmlElement> message_with_content( - SendUpdateTask::MakeUpdateMessage(data, to_jid_bare_, task_id_)); - - EXPECT_EQ(expected_xml_string, XmlElementToString(*message_with_content)); - - data.service_specific_data = "test_service_specific_data"; - data.require_subscription = true; - - expected_xml_string = - StringPrintf( - "<cli:iq type=\"get\" to=\"%s\" id=\"%s\" " - "xmlns:cli=\"jabber:client\">" - "<set xmlns=\"google:notifier\">" - "<Id xmlns=\"\">" - "<ServiceUrl xmlns=\"\" " - "data=\"test_service_url\"/>" - "<ServiceId xmlns=\"\" data=\"test_service_id\"/>" - "</Id>" - "<Content xmlns=\"\">" - "<Priority xmlns=\"\" int=\"200\"/>" - "<RequireSubscription xmlns=\"\" bool=\"true\"/>" - "<ServiceSpecificData xmlns=\"\" " - "data=\"test_service_specific_data\"/>" - "<WriteToCacheOnly xmlns=\"\" bool=\"true\"/>" - "</Content>" - "</set>" - "</cli:iq>", - to_jid_bare_.Str().c_str(), task_id_.c_str()); - - scoped_ptr<buzz::XmlElement> message_with_data( - SendUpdateTask::MakeUpdateMessage(data, to_jid_bare_, task_id_)); - - EXPECT_EQ(expected_xml_string, XmlElementToString(*message_with_data)); -} - -} // namespace notifier diff --git a/jingle/notifier/listener/subscribe_task.cc b/jingle/notifier/listener/subscribe_task.cc deleted file mode 100644 index ea36047..0000000 --- a/jingle/notifier/listener/subscribe_task.cc +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2010 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 "jingle/notifier/listener/subscribe_task.h" - -#include <string> - -#include "base/logging.h" -#include "jingle/notifier/listener/notification_constants.h" -#include "jingle/notifier/listener/xml_element_util.h" -#include "talk/base/task.h" -#include "talk/xmllite/qname.h" -#include "talk/xmllite/xmlelement.h" -#include "talk/xmpp/xmppclient.h" -#include "talk/xmpp/constants.h" -#include "talk/xmpp/xmppengine.h" - -namespace notifier { - -SubscribeTask::SubscribeTask( - TaskParent* parent, - const std::vector<std::string>& subscribed_services_list) - : XmppTask(parent, buzz::XmppEngine::HL_SINGLE), - subscribed_services_list_(subscribed_services_list) { -} - -SubscribeTask::~SubscribeTask() { -} - -bool SubscribeTask::HandleStanza(const buzz::XmlElement* stanza) { - if (!MatchResponseIq(stanza, GetClient()->jid().BareJid(), task_id())) - return false; - QueueStanza(stanza); - return true; -} - -int SubscribeTask::ProcessStart() { - VLOG(1) << "P2P: Subscription task started."; - scoped_ptr<buzz::XmlElement> iq_stanza( - MakeSubscriptionMessage(subscribed_services_list_, - GetClient()->jid().BareJid(), task_id())); - VLOG(1) << "P2P: Subscription stanza: " - << XmlElementToString(*iq_stanza.get()); - - if (SendStanza(iq_stanza.get()) != buzz::XMPP_RETURN_OK) { - SignalStatusUpdate(false); - // TODO(akalin): This should be STATE_ERROR. - return STATE_DONE; - } - return STATE_RESPONSE; -} - -int SubscribeTask::ProcessResponse() { - VLOG(1) << "P2P: Subscription response received."; - const buzz::XmlElement* stanza = NextStanza(); - if (stanza == NULL) { - return STATE_BLOCKED; - } - VLOG(1) << "P2P: Subscription response: " << XmlElementToString(*stanza); - // We've receieved a response to our subscription request. - if (stanza->HasAttr(buzz::QN_TYPE) && - stanza->Attr(buzz::QN_TYPE) == buzz::STR_RESULT) { - SignalStatusUpdate(true); - return STATE_DONE; - } - // An error response was received. - // TODO(brg) : Error handling. - SignalStatusUpdate(false); - // TODO(akalin): This should be STATE_ERROR. - return STATE_DONE; -} - -buzz::XmlElement* SubscribeTask::MakeSubscriptionMessage( - const std::vector<std::string>& subscribed_services_list, - const buzz::Jid& to_jid_bare, const std::string& task_id) { - DCHECK(to_jid_bare.IsBare()); - static const buzz::QName kQnNotifierGetAll( - kNotifierNamespace, "getAll"); - - // Create the subscription stanza using the notifications protocol. - // <iq type='get' from='{fullJid}' to='{bareJid}' id='{#}'> - // <gn:getAll xmlns:gn="google:notifier" xmlns=""> - // <ClientActive bool="true" /> - // <!-- present only if subscribed_services_list is not empty --> - // <SubscribedServiceUrl data="google:notifier"> - // <SubscribedServiceUrl data="http://www.google.com/chrome/sync"> - // <FilterNonSubscribed bool="true" /> - // </gn:getAll> - // </iq> - - buzz::XmlElement* iq = MakeIq(buzz::STR_GET, to_jid_bare, task_id); - buzz::XmlElement* get_all = new buzz::XmlElement(kQnNotifierGetAll, true); - iq->AddElement(get_all); - - get_all->AddElement(MakeBoolXmlElement("ClientActive", true)); - for (std::vector<std::string>::const_iterator iter = - subscribed_services_list.begin(); - iter != subscribed_services_list.end(); ++iter) { - get_all->AddElement( - MakeStringXmlElement("SubscribedServiceUrl", iter->c_str())); - } - if (!subscribed_services_list.empty()) { - get_all->AddElement(MakeBoolXmlElement("FilterNonSubscribed", true)); - } - return iq; -} - -} // namespace notifier diff --git a/jingle/notifier/listener/subscribe_task.h b/jingle/notifier/listener/subscribe_task.h deleted file mode 100644 index 857b921..0000000 --- a/jingle/notifier/listener/subscribe_task.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2009 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. -// -// This class handles subscribing to talk notifications. It does the getAll iq -// stanza which establishes the endpoint and directs future notifications to be -// pushed. - -#ifndef JINGLE_NOTIFIER_LISTENER_SUBSCRIBE_TASK_H_ -#define JINGLE_NOTIFIER_LISTENER_SUBSCRIBE_TASK_H_ - -#include <string> -#include <vector> - -#include "base/gtest_prod_util.h" -#include "talk/xmllite/xmlelement.h" -#include "talk/xmpp/xmpptask.h" - -namespace notifier { - -class SubscribeTask : public buzz::XmppTask { - public: - SubscribeTask(TaskParent* parent, - const std::vector<std::string>& subscribed_services_list); - virtual ~SubscribeTask(); - - // Overridden from XmppTask. - virtual int ProcessStart(); - virtual int ProcessResponse(); - virtual bool HandleStanza(const buzz::XmlElement* stanza); - - // Signal callback upon subscription success. - sigslot::signal1<bool> SignalStatusUpdate; - - private: - // Assembles an Xmpp stanza which can be sent to subscribe to notifications. - static buzz::XmlElement* MakeSubscriptionMessage( - const std::vector<std::string>& subscribed_services_list, - const buzz::Jid& to_jid_bare, const std::string& task_id); - - std::vector<std::string> subscribed_services_list_; - - FRIEND_TEST_ALL_PREFIXES(SubscribeTaskTest, MakeSubscriptionMessage); - - DISALLOW_COPY_AND_ASSIGN(SubscribeTask); -}; - -} // namespace notifier - -#endif // JINGLE_NOTIFIER_LISTENER_SUBSCRIBE_TASK_H_ diff --git a/jingle/notifier/listener/subscribe_task_unittest.cc b/jingle/notifier/listener/subscribe_task_unittest.cc deleted file mode 100644 index 24cc106..0000000 --- a/jingle/notifier/listener/subscribe_task_unittest.cc +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2010 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 "jingle/notifier/listener/subscribe_task.h" - -#include "base/scoped_ptr.h" -#include "base/string_util.h" -#include "jingle/notifier/listener/xml_element_util.h" -#include "talk/xmpp/jid.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace buzz { -class XmlElement; -} - -namespace notifier { - -class SubscribeTaskTest : public testing::Test { - public: - SubscribeTaskTest() : to_jid_bare_("to@jid.com"), task_id_("taskid") { - EXPECT_EQ(to_jid_bare_.Str(), to_jid_bare_.BareJid().Str()); - } - - protected: - const buzz::Jid to_jid_bare_; - const std::string task_id_; - - private: - DISALLOW_COPY_AND_ASSIGN(SubscribeTaskTest); -}; - -TEST_F(SubscribeTaskTest, MakeSubscriptionMessage) { - std::vector<std::string> subscribed_services_list; - - scoped_ptr<buzz::XmlElement> message_without_services( - SubscribeTask::MakeSubscriptionMessage(subscribed_services_list, - to_jid_bare_, task_id_)); - std::string expected_xml_string = - StringPrintf( - "<cli:iq type=\"get\" to=\"%s\" id=\"%s\" " - "xmlns:cli=\"jabber:client\">" - "<getAll xmlns=\"google:notifier\">" - "<ClientActive xmlns=\"\" bool=\"true\"/>" - "</getAll>" - "</cli:iq>", - to_jid_bare_.Str().c_str(), task_id_.c_str()); - EXPECT_EQ(expected_xml_string, XmlElementToString(*message_without_services)); - - subscribed_services_list.push_back("test_service_url1"); - subscribed_services_list.push_back("test_service_url2"); - scoped_ptr<buzz::XmlElement> message_with_services( - SubscribeTask::MakeSubscriptionMessage(subscribed_services_list, - to_jid_bare_, task_id_)); - expected_xml_string = - StringPrintf( - "<cli:iq type=\"get\" to=\"%s\" id=\"%s\" " - "xmlns:cli=\"jabber:client\">" - "<getAll xmlns=\"google:notifier\">" - "<ClientActive xmlns=\"\" bool=\"true\"/>" - "<SubscribedServiceUrl " - "xmlns=\"\" data=\"test_service_url1\"/>" - "<SubscribedServiceUrl " - "xmlns=\"\" data=\"test_service_url2\"/>" - "<FilterNonSubscribed xmlns=\"\" bool=\"true\"/>" - "</getAll>" - "</cli:iq>", - to_jid_bare_.Str().c_str(), task_id_.c_str()); - - EXPECT_EQ(expected_xml_string, XmlElementToString(*message_with_services)); -} - -} // namespace notifier diff --git a/jingle/notifier/listener/talk_mediator.h b/jingle/notifier/listener/talk_mediator.h index dfdc260..4851df8 100644 --- a/jingle/notifier/listener/talk_mediator.h +++ b/jingle/notifier/listener/talk_mediator.h @@ -31,11 +31,9 @@ class TalkMediator { public: virtual ~Delegate() {} - virtual void OnNotificationStateChange( - bool notifications_enabled) = 0; + virtual void OnNotificationStateChange(bool notifications_enabled) = 0; - virtual void OnIncomingNotification( - const IncomingNotificationData& notification_data) = 0; + virtual void OnIncomingNotification(const Notification& notification) = 0; virtual void OnOutgoingNotification() = 0; }; @@ -52,10 +50,10 @@ class TalkMediator { // Method for the owner of this object to notify peers that an update has // occurred. - virtual bool SendNotification(const OutgoingNotificationData& data) = 0; + virtual bool SendNotification(const Notification& data) = 0; - // Add a URL to subscribe to for notifications. - virtual void AddSubscribedServiceUrl(const std::string& service_url) = 0; + // Add a subscription to subscribe to. + virtual void AddSubscription(const Subscription& subscription) = 0; }; } // namespace notifier diff --git a/jingle/notifier/listener/talk_mediator_impl.cc b/jingle/notifier/listener/talk_mediator_impl.cc index fb0cc2a..5e7320b 100644 --- a/jingle/notifier/listener/talk_mediator_impl.cc +++ b/jingle/notifier/listener/talk_mediator_impl.cc @@ -59,7 +59,7 @@ bool TalkMediatorImpl::Logout() { return false; } -bool TalkMediatorImpl::SendNotification(const OutgoingNotificationData& data) { +bool TalkMediatorImpl::SendNotification(const Notification& data) { DCHECK(non_thread_safe_.CalledOnValidThread()); if (state_.logged_in && state_.subscribed) { mediator_thread_->SendNotification(data); @@ -101,13 +101,12 @@ bool TalkMediatorImpl::SetAuthToken(const std::string& email, return true; } -void TalkMediatorImpl::AddSubscribedServiceUrl( - const std::string& service_url) { +void TalkMediatorImpl::AddSubscription(const Subscription& subscription) { DCHECK(non_thread_safe_.CalledOnValidThread()); - subscribed_services_list_.push_back(service_url); + subscriptions_.push_back(subscription); if (state_.logged_in) { VLOG(1) << "Resubscribing for updates, a new service got added"; - mediator_thread_->SubscribeForUpdates(subscribed_services_list_); + mediator_thread_->SubscribeForUpdates(subscriptions_); } } @@ -122,7 +121,7 @@ void TalkMediatorImpl::OnConnectionStateChange(bool logged_in) { // SubscribeForUpdates. mediator_thread_->ListenForUpdates(); // Now subscribe for updates to all the services we are interested in - mediator_thread_->SubscribeForUpdates(subscribed_services_list_); + mediator_thread_->SubscribeForUpdates(subscriptions_); } else { VLOG(1) << "P2P: Logged off."; OnSubscriptionStateChange(false); @@ -138,11 +137,11 @@ void TalkMediatorImpl::OnSubscriptionStateChange(bool subscribed) { } void TalkMediatorImpl::OnIncomingNotification( - const IncomingNotificationData& notification_data) { + const Notification& notification) { DCHECK(non_thread_safe_.CalledOnValidThread()); VLOG(1) << "P2P: Updates are available on the server."; if (delegate_) - delegate_->OnIncomingNotification(notification_data); + delegate_->OnIncomingNotification(notification); } void TalkMediatorImpl::OnOutgoingNotification() { diff --git a/jingle/notifier/listener/talk_mediator_impl.h b/jingle/notifier/listener/talk_mediator_impl.h index 7af2721..d52541b 100644 --- a/jingle/notifier/listener/talk_mediator_impl.h +++ b/jingle/notifier/listener/talk_mediator_impl.h @@ -43,9 +43,9 @@ class TalkMediatorImpl virtual bool Login(); virtual bool Logout(); - virtual bool SendNotification(const OutgoingNotificationData& data); + virtual bool SendNotification(const Notification& data); - virtual void AddSubscribedServiceUrl(const std::string& service_url); + virtual void AddSubscription(const Subscription& subscription); // MediatorThread::Delegate implementation. @@ -53,8 +53,7 @@ class TalkMediatorImpl virtual void OnSubscriptionStateChange(bool subscribed); - virtual void OnIncomingNotification( - const IncomingNotificationData& notification_data); + virtual void OnIncomingNotification(const Notification& notification); virtual void OnOutgoingNotification(); @@ -90,7 +89,7 @@ class TalkMediatorImpl const bool invalidate_xmpp_auth_token_; const bool allow_insecure_connection_; - std::vector<std::string> subscribed_services_list_; + SubscriptionList subscriptions_; FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, SetAuthTokenWithBadInput); FRIEND_TEST_ALL_PREFIXES(TalkMediatorImplTest, SetAuthTokenWithGoodInput); diff --git a/jingle/notifier/listener/talk_mediator_unittest.cc b/jingle/notifier/listener/talk_mediator_unittest.cc index 0d0f9e3..4c983ae1 100644 --- a/jingle/notifier/listener/talk_mediator_unittest.cc +++ b/jingle/notifier/listener/talk_mediator_unittest.cc @@ -26,7 +26,7 @@ class MockTalkMediatorDelegate : public TalkMediator::Delegate { MOCK_METHOD1(OnNotificationStateChange, void(bool notification_changed)); MOCK_METHOD1(OnIncomingNotification, - void(const IncomingNotificationData& data)); + void(const Notification& data)); MOCK_METHOD0(OnOutgoingNotification, void()); private: @@ -126,7 +126,7 @@ TEST_F(TalkMediatorImplTest, SendNotification) { scoped_ptr<TalkMediatorImpl> talk1(NewMockedTalkMediator(mock)); // Failure due to not being logged in. - OutgoingNotificationData data; + Notification data; EXPECT_FALSE(talk1->SendNotification(data)); EXPECT_EQ(0, mock->send_calls); @@ -175,13 +175,13 @@ TEST_F(TalkMediatorImplTest, MediatorThreadCallbacks) { // After subscription success is receieved, the talk mediator will allow // sending of notifications. - OutgoingNotificationData outgoing_data; + Notification outgoing_data; EXPECT_TRUE(talk1->SendNotification(outgoing_data)); EXPECT_EQ(1, mock->send_calls); - IncomingNotificationData incoming_data; - incoming_data.service_url = "service_url"; - incoming_data.service_specific_data = "service_data"; + Notification incoming_data; + incoming_data.channel = "service_url"; + incoming_data.data = "service_data"; mock->ReceiveNotification(incoming_data); // Shouldn't trigger a call to the delegate since we disconnect |