diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-27 05:29:09 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-27 05:29:09 +0000 |
commit | 2f15fd0e5c1c711e2ef01b4b956b853e4af10909 (patch) | |
tree | 5eb61281e5afd751a0d4741de8256228a6339c16 /jingle/notifier | |
parent | 45d6f5a0db176c2b562b147618c21e15285d723a (diff) | |
download | chromium_src-2f15fd0e5c1c711e2ef01b4b956b853e4af10909.zip chromium_src-2f15fd0e5c1c711e2ef01b4b956b853e4af10909.tar.gz chromium_src-2f15fd0e5c1c711e2ef01b4b956b853e4af10909.tar.bz2 |
[Sync] Make P2PNotifier behave more like InvalidationNotifier
Encode the changed types into the XMPP push message and nudge only for those data types.
Filter out notifications sent from the originating client.
Instead of calling observers directly, synthesize a notification and send it to the server with target = self only.
BUG=92928
TEST=
Review URL: http://codereview.chromium.org/7745040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98551 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle/notifier')
3 files changed, 32 insertions, 32 deletions
diff --git a/jingle/notifier/listener/push_notifications_listen_task.cc b/jingle/notifier/listener/push_notifications_listen_task.cc index 8617f84..328bbe2 100644 --- a/jingle/notifier/listener/push_notifications_listen_task.cc +++ b/jingle/notifier/listener/push_notifications_listen_task.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -29,16 +29,17 @@ PushNotificationsListenTask::~PushNotificationsListenTask() { } int PushNotificationsListenTask::ProcessStart() { - VLOG(1) << "Push notifications: Listener task started."; return STATE_RESPONSE; } int PushNotificationsListenTask::ProcessResponse() { - VLOG(1) << "Push notifications: Listener response received."; const buzz::XmlElement* stanza = NextStanza(); if (stanza == NULL) { return STATE_BLOCKED; } + + VLOG(1) << "Received stanza " << XmlElementToString(*stanza); + // The push notifications service does not need us to acknowledge receipt of // the notification to the buzz server. @@ -46,36 +47,41 @@ int PushNotificationsListenTask::ProcessResponse() { // Extract the service URL and service-specific data from the stanza. // Note that we treat the channel name as service URL. // The response stanza has the following format. - // <message from=’someservice.google.com’ to={full_jid}> - // <push xmlns=’google:push’ channel={channel name}> - // <recipient to={bare_jid}>{base-64 encoded data}</recipient> - // <data>{base-64 data}</data> + // <message from="{url or bare jid}" to={full jid}> + // <push xmlns="google:push" channel={channel name}> + // <recipient to={bare jid}>{base-64 encoded data}</recipient> + // <data>{base-64 encoded data}</data> // </push> // </message> - const buzz::XmlElement* push_element = - stanza->FirstNamed(buzz::QName(kPushNotificationsNamespace, "push")); + const buzz::QName kQnPush(kPushNotificationsNamespace, "push"); + const buzz::QName kQnChannel(buzz::STR_EMPTY, "channel"); + const buzz::QName kQnData(kPushNotificationsNamespace, "data"); + + const buzz::XmlElement* push_element = stanza->FirstNamed(kQnPush); if (push_element) { 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")); + notification.channel = push_element->Attr(kQnChannel); + const buzz::XmlElement* data_element = push_element->FirstNamed(kQnData); if (data_element) { - base::Base64Decode(data_element->BodyText(), - ¬ification.data); + const std::string& base64_encoded_data = data_element->BodyText(); + if (!base::Base64Decode(base64_encoded_data, ¬ification.data)) { + LOG(WARNING) << "Could not base64-decode " << base64_encoded_data; + } + } else { + LOG(WARNING) << "No data element found in push element " + << XmlElementToString(*push_element); } + VLOG(1) << "Received notification " << notification.ToString(); delegate_->OnNotificationReceived(notification); } else { - LOG(WARNING) << - "Push notifications: No push element found in response stanza"; + LOG(WARNING) << "No push element found in stanza " + << XmlElementToString(*stanza); } return STATE_RESPONSE; } bool PushNotificationsListenTask::HandleStanza(const buzz::XmlElement* stanza) { - VLOG(1) << "Push notifications: Stanza received: " - << XmlElementToString(*stanza); if (IsValidNotification(stanza)) { QueueStanza(stanza); return true; @@ -85,13 +91,6 @@ bool PushNotificationsListenTask::HandleStanza(const buzz::XmlElement* stanza) { bool PushNotificationsListenTask::IsValidNotification( const buzz::XmlElement* stanza) { - // An update notification has the following form. - // <message from=’someservice.google.com’ to={full_jid}> - // <push xmlns=’google:push’ channel={channel name}> - // <recipient to={bare_jid}>{base-64 encoded data}</recipient> - // <data>{base-64 data}</data> - // </push> - // </message> // We don't do much validation here, just check if the stanza is a message // stanza. return (stanza->Name() == buzz::QN_MESSAGE); diff --git a/jingle/notifier/listener/push_notifications_send_update_task.cc b/jingle/notifier/listener/push_notifications_send_update_task.cc index 3e05a31..5cef1b5 100644 --- a/jingle/notifier/listener/push_notifications_send_update_task.cc +++ b/jingle/notifier/listener/push_notifications_send_update_task.cc @@ -29,9 +29,10 @@ int PushNotificationsSendUpdateTask::ProcessStart() { scoped_ptr<buzz::XmlElement> stanza( MakeUpdateMessage(notification_, GetClient()->jid().BareJid())); - VLOG(1) << "P2P: Sending notification: " << XmlElementToString(*stanza); + VLOG(1) << "Sending notification " << notification_.ToString() + << " as stanza " << XmlElementToString(*stanza); if (SendStanza(stanza.get()) != buzz::XMPP_RETURN_OK) { - LOG(WARNING) << "Could not send: " << XmlElementToString(*stanza); + LOG(WARNING) << "Could not send stanza " << XmlElementToString(*stanza); } return STATE_DONE; } @@ -42,10 +43,10 @@ buzz::XmlElement* PushNotificationsSendUpdateTask::MakeUpdateMessage( 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"); + const buzz::QName kQnData(kPushNotificationsNamespace, "data"); // Create our update stanza. The message is constructed as: - // <message from='{fullJid}' to='{bareJid}' type='headline'> + // <message from='{full jid}' to='{bare jid}' type='headline'> // <push xmlns='google:push' channel='{channel}'> // <data>{base-64 encoded data}</data> // </push> @@ -62,7 +63,7 @@ buzz::XmlElement* PushNotificationsSendUpdateTask::MakeUpdateMessage( 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; + LOG(WARNING) << "Could not encode data " << notification.data; } data->SetBodyText(base64_data); push->AddElement(data); diff --git a/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc b/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc index 811b888..3fa424ee 100644 --- a/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc +++ b/jingle/notifier/listener/push_notifications_send_update_task_unittest.cc @@ -47,7 +47,7 @@ TEST_F(PushNotificationsSendUpdateTaskTest, MakeUpdateMessage) { "<cli:message to=\"%s\" type=\"headline\" " "xmlns:cli=\"jabber:client\">" "<push xmlns=\"google:push\" channel=\"%s\">" - "<data xmlns=\"\">%s</data>" + "<data xmlns=\"google:push\">%s</data>" "</push>" "</cli:message>", to_jid_bare_.Str().c_str(), notification.channel.c_str(), |