summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-30 19:52:35 +0000
committersanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-30 19:52:35 +0000
commit50c5beddbb7839e02367542a58b7d43132f392f7 (patch)
tree5a0d11c695052adeaf4d55dc73c977f540d0b84c
parentf21cf2cfe34186333a591ee0788072889c2eaa3e (diff)
downloadchromium_src-50c5beddbb7839e02367542a58b7d43132f392f7.zip
chromium_src-50c5beddbb7839e02367542a58b7d43132f392f7.tar.gz
chromium_src-50c5beddbb7839e02367542a58b7d43132f392f7.tar.bz2
More refactoring of TalkMediator and related classes to make them generic. There is only one functional change in this changelist. This is the removal of the mediator_thread_->SendNotification call from TalkMediatorImpl::OnSubscriptionSuccess. Please review this part extra carefully.
BUG=None TEST=Test Bookmarks Sync, sync unit-tests have been modified. Review URL: http://codereview.chromium.org/1790004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46109 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/sync/engine/auth_watcher.cc5
-rw-r--r--chrome/browser/sync/engine/auth_watcher_unittest.cc3
-rw-r--r--chrome/browser/sync/engine/syncapi.cc73
-rw-r--r--chrome/browser/sync/notifier/communicator/ssl_socket_adapter.cc2
-rw-r--r--chrome/browser/sync/notifier/listener/listen_task.cc12
-rw-r--r--chrome/browser/sync/notifier/listener/listen_task.h9
-rw-r--r--chrome/browser/sync/notifier/listener/mediator_thread.h10
-rw-r--r--chrome/browser/sync/notifier/listener/mediator_thread_impl.cc39
-rw-r--r--chrome/browser/sync/notifier/listener/mediator_thread_impl.h22
-rw-r--r--chrome/browser/sync/notifier/listener/mediator_thread_mock.h6
-rw-r--r--chrome/browser/sync/notifier/listener/notification_constants.cc6
-rw-r--r--chrome/browser/sync/notifier/listener/notification_constants.h6
-rw-r--r--chrome/browser/sync/notifier/listener/notification_defines.h20
-rw-r--r--chrome/browser/sync/notifier/listener/send_update_task.cc112
-rw-r--r--chrome/browser/sync/notifier/listener/send_update_task.h17
-rw-r--r--chrome/browser/sync/notifier/listener/send_update_task_unittest.cc96
-rw-r--r--chrome/browser/sync/notifier/listener/subscribe_task.cc68
-rw-r--r--chrome/browser/sync/notifier/listener/subscribe_task.h14
-rw-r--r--chrome/browser/sync/notifier/listener/subscribe_task_unittest.cc70
-rw-r--r--chrome/browser/sync/notifier/listener/talk_mediator.h10
-rw-r--r--chrome/browser/sync/notifier/listener/talk_mediator_impl.cc31
-rw-r--r--chrome/browser/sync/notifier/listener/talk_mediator_impl.h12
-rw-r--r--chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc57
-rw-r--r--chrome/browser/sync/sync_constants.cc17
-rw-r--r--chrome/browser/sync/sync_constants.h20
-rw-r--r--chrome/browser/sync/tools/sync_listen_notifications.cc18
-rw-r--r--chrome/browser/sync/tools/sync_tools.gyp5
-rw-r--r--chrome/chrome_browser.gypi2
28 files changed, 350 insertions, 412 deletions
diff --git a/chrome/browser/sync/engine/auth_watcher.cc b/chrome/browser/sync/engine/auth_watcher.cc
index ab93f51..b8a06da 100644
--- a/chrome/browser/sync/engine/auth_watcher.cc
+++ b/chrome/browser/sync/engine/auth_watcher.cc
@@ -107,7 +107,8 @@ void AuthWatcher::DoRenewAuthToken(const std::string& updated_token) {
LOG(INFO) << "Updating auth token:" << updated_token;
scm_->set_auth_token(updated_token);
gaia_->RenewAuthToken(updated_token); // Must be on AuthWatcher thread
- talk_mediator_->SetAuthToken(user_settings_->email(), updated_token);
+ talk_mediator_->SetAuthToken(user_settings_->email(), updated_token,
+ SYNC_SERVICE_NAME);
// TODO(akalin): to see if we need to call Login() here, too.
user_settings_->SetAuthTokenForService(user_settings_->email(),
@@ -170,7 +171,7 @@ void AuthWatcher::DoAuthenticateWithToken(const std::string& gaia_email,
user_settings_->SwitchUser(email);
// Set the authentication token for notifications
- talk_mediator_->SetAuthToken(email, auth_token);
+ talk_mediator_->SetAuthToken(email, auth_token, SYNC_SERVICE_NAME);
talk_mediator_->Login();
scm_->set_auth_token(auth_token);
diff --git a/chrome/browser/sync/engine/auth_watcher_unittest.cc b/chrome/browser/sync/engine/auth_watcher_unittest.cc
index 1b78ec9..ee56525 100644
--- a/chrome/browser/sync/engine/auth_watcher_unittest.cc
+++ b/chrome/browser/sync/engine/auth_watcher_unittest.cc
@@ -98,8 +98,7 @@ class AuthWatcherTest : public testing::Test {
FilePath user_settings_path = temp_dir_.path().Append(kUserSettingsDB);
user_settings_->Init(user_settings_path);
gaia_auth_ = new GaiaAuthMockForAuthWatcher();
- talk_mediator_.reset(new TalkMediatorImpl(
- browser_sync::kDefaultNotificationMethod, false));
+ talk_mediator_.reset(new TalkMediatorImpl(false));
auth_watcher_ = new AuthWatcher(metadb_.manager(), connection_.get(),
allstatus_.get(), kTestUserAgent, kTestServiceId, kTestGaiaURL,
user_settings_.get(), gaia_auth_, talk_mediator_.get());
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc
index 4a4af2f..acf4474 100644
--- a/chrome/browser/sync/engine/syncapi.cc
+++ b/chrome/browser/sync/engine/syncapi.cc
@@ -37,6 +37,7 @@
#include "base/string_util.h"
#include "base/task.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/sync/sync_constants.h"
#include "chrome/browser/sync/engine/all_status.h"
#include "chrome/browser/sync/engine/auth_watcher.h"
#include "chrome/browser/sync/engine/change_reorder_buffer.h"
@@ -83,6 +84,7 @@ using browser_sync::SyncerThread;
using browser_sync::UserSettings;
using browser_sync::TalkMediator;
using browser_sync::TalkMediatorImpl;
+using browser_sync::TalkMediatorEvent;
using browser_sync::sessions::SyncSessionContext;
using std::list;
using std::hex;
@@ -994,7 +996,8 @@ class SyncManager::SyncInternal {
address_watch_thread_("SyncEngine_AddressWatcher"),
registrar_(NULL),
notification_pending_(false),
- initialized_(false) {
+ initialized_(false),
+ notification_method_(browser_sync::kDefaultNotificationMethod) {
}
~SyncInternal() { }
@@ -1056,6 +1059,10 @@ class SyncManager::SyncInternal {
// on startup, to serve our UI needs.
void HandleAuthWatcherEvent(const AuthWatcherEvent& event);
+ // We listen to TalkMediator events so that we can send an
+ // XMPP notification when subscriptions are on.
+ void HandleTalkMediatorEvent(const TalkMediatorEvent& event);
+
// Accessors for the private members.
DirectoryManager* dir_manager() { return share_.dir_manager.get(); }
SyncAPIServerConnectionManager* connection_manager() {
@@ -1147,6 +1154,8 @@ class SyncManager::SyncInternal {
// already initialized, this is a no-op.
void MarkAndNotifyInitializationComplete();
+ bool SendXMPPNotification();
+
// Determine if the parents or predecessors differ between the old and new
// versions of an entry stored in |a| and |b|. Note that a node's index may
// change without its NEXT_ID changing if the node at NEXT_ID also moved (but
@@ -1221,6 +1230,9 @@ class SyncManager::SyncInternal {
// Notification (xmpp) handler.
scoped_ptr<TalkMediator> talk_mediator_;
+ // XMPP notifications event handler
+ scoped_ptr<EventListenerHookup> talk_mediator_hookup_;
+
// A multi-purpose status watch object that aggregates stats from various
// sync components.
AllStatus allstatus_;
@@ -1275,6 +1287,8 @@ class SyncManager::SyncInternal {
// as it can get read/set by both the SyncerThread and the AuthWatcherThread.
bool initialized_;
mutable Lock initialized_mutex_;
+
+ browser_sync::NotificationMethod notification_method_;
};
const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200;
const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000;
@@ -1356,6 +1370,7 @@ bool SyncManager::SyncInternal::Init(
const char* user_agent,
const std::string& lsid,
browser_sync::NotificationMethod notification_method) {
+ notification_method_ = notification_method;
// Set up UserSettings, creating the db if necessary. We need this to
// instantiate a URLFactory to give to the Syncer.
FilePath settings_db_file =
@@ -1409,15 +1424,22 @@ bool SyncManager::SyncInternal::Init(
const char* service_id = gaia_service_id ?
gaia_service_id : SYNC_SERVICE_NAME;
- talk_mediator_.reset(new TalkMediatorImpl(notification_method,
- invalidate_xmpp_auth_token));
- if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) {
- talk_mediator_->AddSubscribedServiceUrl(
- browser_sync::kSyncLegacyServiceUrl);
+ talk_mediator_.reset(new TalkMediatorImpl(invalidate_xmpp_auth_token));
+ if (notification_method != browser_sync::NOTIFICATION_LEGACY) {
+ if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) {
+ talk_mediator_->AddSubscribedServiceUrl(
+ browser_sync::kSyncLegacyServiceUrl);
+ }
+ talk_mediator_->AddSubscribedServiceUrl(browser_sync::kSyncServiceUrl);
}
- talk_mediator_->AddSubscribedServiceUrl(browser_sync::kSyncServiceUrl);
allstatus()->WatchTalkMediator(talk_mediator());
+ // Listen to TalkMediator events ourselves
+ talk_mediator_hookup_.reset(
+ NewEventListenerHookup(talk_mediator_->channel(),
+ this,
+ &SyncInternal::HandleTalkMediatorEvent));
+
BridgedGaiaAuthenticator* gaia_auth = new BridgedGaiaAuthenticator(
gaia_source, service_id, gaia_url, auth_post_factory);
@@ -1491,6 +1513,29 @@ void SyncManager::SyncInternal::MarkAndNotifyInitializationComplete() {
observer_->OnInitializationComplete();
}
+bool SyncManager::SyncInternal::SendXMPPNotification() {
+ OutgoingNotificationData notification_data;
+ if (notification_method_ == browser_sync::NOTIFICATION_LEGACY) {
+ notification_data.service_id = browser_sync::kSyncLegacyServiceId;
+ notification_data.service_url = browser_sync::kSyncLegacyServiceUrl;
+ notification_data.send_content = false;
+ } else {
+ notification_data.service_id = browser_sync::kSyncServiceId;
+ notification_data.service_url = browser_sync::kSyncServiceUrl;
+ notification_data.send_content = true;
+ notification_data.priority = browser_sync::kSyncPriority;
+ notification_data.write_to_cache_only = true;
+ if (notification_method_ == browser_sync::NOTIFICATION_NEW) {
+ notification_data.service_specific_data =
+ browser_sync::kSyncServiceSpecificData;
+ notification_data.require_subscription = true;
+ } else {
+ notification_data.require_subscription = false;
+ }
+ }
+ return talk_mediator()->SendNotification(notification_data);
+}
+
void SyncManager::SyncInternal::Authenticate(const std::string& username,
const std::string& password,
const std::string& captcha) {
@@ -1842,7 +1887,7 @@ void SyncManager::SyncInternal::HandleSyncerEvent(const SyncerEvent& event) {
// TODO(brg): Move this to TalkMediatorImpl as a SyncerThread event hook.
if (notification_pending_ && talk_mediator()) {
LOG(INFO) << "Sending XMPP notification...";
- bool success = talk_mediator()->SendNotification();
+ bool success = SendXMPPNotification();
if (success) {
notification_pending_ = false;
LOG(INFO) << "Sent XMPP notification";
@@ -1947,6 +1992,18 @@ void SyncManager::SyncInternal::HandleAuthWatcherEvent(
observer_->OnAuthError(AuthError(auth_problem_));
}
+void SyncManager::SyncInternal::HandleTalkMediatorEvent(
+ const TalkMediatorEvent& event) {
+ // Send a notification as soon as subscriptions are on.
+ // This is to fix Bug 38563.
+ // See http://code.google.com/p/chromium/issues/detail?id=38563.
+ // This was originally fixed in http://codereview.chromium.org/1545024
+ // but it got moved here when the refactoring of TalkMediator happened.
+ if (event.what_happened == TalkMediatorEvent::SUBSCRIPTIONS_ON) {
+ SendXMPPNotification();
+ }
+}
+
SyncManager::Status::Summary SyncManager::GetStatusSummary() const {
return data_->ComputeAggregatedStatusSummary();
}
diff --git a/chrome/browser/sync/notifier/communicator/ssl_socket_adapter.cc b/chrome/browser/sync/notifier/communicator/ssl_socket_adapter.cc
index cd3e5f0..b0b7776 100644
--- a/chrome/browser/sync/notifier/communicator/ssl_socket_adapter.cc
+++ b/chrome/browser/sync/notifier/communicator/ssl_socket_adapter.cc
@@ -6,8 +6,6 @@
#include "base/compiler_specific.h"
#include "base/message_loop.h"
-#include "chrome/browser/net/url_request_context_getter.h"
-#include "chrome/browser/profile.h"
#include "net/base/address_list.h"
#include "net/base/net_errors.h"
#include "net/base/ssl_config_service.h"
diff --git a/chrome/browser/sync/notifier/listener/listen_task.cc b/chrome/browser/sync/notifier/listener/listen_task.cc
index 06f7ff2..e0f0a814 100644
--- a/chrome/browser/sync/notifier/listener/listen_task.cc
+++ b/chrome/browser/sync/notifier/listener/listen_task.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/sync/notifier/listener/listen_task.h"
#include "base/logging.h"
-#include "chrome/browser/sync/notification_method.h"
#include "chrome/browser/sync/notifier/listener/notification_constants.h"
#include "chrome/browser/sync/notifier/listener/xml_element_util.h"
#include "talk/base/task.h"
@@ -17,9 +16,8 @@
namespace browser_sync {
-ListenTask::ListenTask(Task* parent, NotificationMethod notification_method)
- : buzz::XmppTask(parent, buzz::XmppEngine::HL_TYPE),
- notification_method_(notification_method) {
+ListenTask::ListenTask(Task* parent)
+ : buzz::XmppTask(parent, buzz::XmppEngine::HL_TYPE) {
}
ListenTask::~ListenTask() {
@@ -75,7 +73,7 @@ int ListenTask::ProcessResponse() {
get_all_element->FirstNamed(
buzz::QName(true, buzz::STR_EMPTY, "Result"));
while (result_element) {
- NotificationData notification_data;
+ IncomingNotificationData notification_data;
const buzz::XmlElement* id_element =
result_element->FirstNamed(buzz::QName(true, buzz::STR_EMPTY, "Id"));
if (id_element) {
@@ -111,7 +109,7 @@ int ListenTask::ProcessResponse() {
LOG(WARNING) <<
"No getAll element or Result element found in response stanza";
// Signal an empty update to preserve old behavior
- SignalUpdateAvailable(NotificationData());
+ SignalUpdateAvailable(IncomingNotificationData());
}
return STATE_RESPONSE;
}
@@ -119,7 +117,7 @@ int ListenTask::ProcessResponse() {
bool ListenTask::HandleStanza(const buzz::XmlElement* stanza) {
LOG(INFO) << "P2P: Stanza received: " << XmlElementToString(*stanza);
// TODO(akalin): Do more verification on stanza depending on
- // notification_method_.
+ // the sync notification method
if (IsValidNotification(stanza)) {
QueueStanza(stanza);
return true;
diff --git a/chrome/browser/sync/notifier/listener/listen_task.h b/chrome/browser/sync/notifier/listener/listen_task.h
index cd2f40d..1ac575b 100644
--- a/chrome/browser/sync/notifier/listener/listen_task.h
+++ b/chrome/browser/sync/notifier/listener/listen_task.h
@@ -12,7 +12,6 @@
#ifndef CHROME_BROWSER_SYNC_NOTIFIER_LISTENER_LISTEN_TASK_H_
#define CHROME_BROWSER_SYNC_NOTIFIER_LISTENER_LISTEN_TASK_H_
-#include "chrome/browser/sync/notification_method.h"
#include "chrome/browser/sync/notifier/listener/notification_defines.h"
#include "talk/xmpp/xmpptask.h"
@@ -25,7 +24,7 @@ namespace browser_sync {
class ListenTask : public buzz::XmppTask {
public:
- ListenTask(Task* parent, NotificationMethod notification_method);
+ explicit ListenTask(Task* parent);
virtual ~ListenTask();
// Overriden from buzz::XmppTask.
@@ -34,16 +33,14 @@ class ListenTask : public buzz::XmppTask {
virtual bool HandleStanza(const buzz::XmlElement* stanza);
// Signal callback upon receipt of a notification.
- // SignalUpdateAvailable(const NotificationData& data);
- sigslot::signal1<const NotificationData&> SignalUpdateAvailable;
+ // 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);
- NotificationMethod notification_method_;
-
DISALLOW_COPY_AND_ASSIGN(ListenTask);
};
diff --git a/chrome/browser/sync/notifier/listener/mediator_thread.h b/chrome/browser/sync/notifier/listener/mediator_thread.h
index 20ff1a0..8ff2cf7e 100644
--- a/chrome/browser/sync/notifier/listener/mediator_thread.h
+++ b/chrome/browser/sync/notifier/listener/mediator_thread.h
@@ -12,7 +12,6 @@
#include <vector>
#include "base/logging.h"
-#include "chrome/browser/sync/notification_method.h"
#include "chrome/browser/sync/notifier/listener/notification_defines.h"
#include "talk/base/sigslot.h"
#include "talk/xmpp/xmppclientsettings.h"
@@ -37,18 +36,15 @@ class MediatorThread {
virtual void SubscribeForUpdates(
const std::vector<std::string>& subscribed_services_list) = 0;
virtual void ListenForUpdates() = 0;
- virtual void SendNotification() = 0;
+ virtual void SendNotification(const OutgoingNotificationData& data) = 0;
// Connect to this for messages about talk events (except notifications).
sigslot::signal1<MediatorMessage> SignalStateChange;
// Connect to this for notifications
- sigslot::signal1<const NotificationData&> SignalNotificationReceived;
+ sigslot::signal1<const IncomingNotificationData&> SignalNotificationReceived;
protected:
- explicit MediatorThread(NotificationMethod notification_method)
- : notification_method_(notification_method) {}
-
- const NotificationMethod notification_method_;
+ MediatorThread() {}
private:
DISALLOW_COPY_AND_ASSIGN(MediatorThread);
diff --git a/chrome/browser/sync/notifier/listener/mediator_thread_impl.cc b/chrome/browser/sync/notifier/listener/mediator_thread_impl.cc
index b0645bf..adbf0e0 100644
--- a/chrome/browser/sync/notifier/listener/mediator_thread_impl.cc
+++ b/chrome/browser/sync/notifier/listener/mediator_thread_impl.cc
@@ -7,7 +7,6 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/platform_thread.h"
-#include "chrome/browser/sync/engine/net/gaia_authenticator.h"
#include "chrome/browser/sync/notifier/base/async_dns_lookup.h"
#include "chrome/browser/sync/notifier/base/task_pump.h"
#include "chrome/browser/sync/notifier/communicator/connection_options.h"
@@ -16,7 +15,6 @@
#include "chrome/browser/sync/notifier/listener/listen_task.h"
#include "chrome/browser/sync/notifier/listener/send_update_task.h"
#include "chrome/browser/sync/notifier/listener/subscribe_task.h"
-#include "chrome/browser/sync/protocol/service_constants.h"
#include "talk/base/thread.h"
#include "talk/xmpp/xmppclient.h"
#include "talk/xmpp/xmppclientsettings.h"
@@ -25,9 +23,7 @@ using std::string;
namespace browser_sync {
-MediatorThreadImpl::MediatorThreadImpl(
- NotificationMethod notification_method)
- : MediatorThread(notification_method) {}
+MediatorThreadImpl::MediatorThreadImpl() {}
MediatorThreadImpl::~MediatorThreadImpl() {
}
@@ -37,13 +33,10 @@ void MediatorThreadImpl::Start() {
}
void MediatorThreadImpl::Run() {
- PlatformThread::SetName("SyncEngine_MediatorThread");
+ PlatformThread::SetName("Notifier_MediatorThread");
// For win32, this sets up the win32socketserver. Note that it needs to
// dispatch windows messages since that is what the win32 socket server uses.
- LOG(INFO) << "Running mediator thread with notification method "
- << NotificationMethodToString(notification_method_);
-
MessageLoop message_loop;
Post(this, CMD_PUMP_AUXILIARY_LOOPS);
@@ -87,8 +80,9 @@ void MediatorThreadImpl::SubscribeForUpdates(
new SubscriptionData(subscribed_services_list));
}
-void MediatorThreadImpl::SendNotification() {
- Post(this, CMD_SEND_NOTIFICATION);
+void MediatorThreadImpl::SendNotification(
+ const OutgoingNotificationData& data) {
+ Post(this, CMD_SEND_NOTIFICATION, new OutgoingNotificationMessageData(data));
}
void MediatorThreadImpl::ProcessMessages(int milliseconds) {
@@ -109,9 +103,13 @@ void MediatorThreadImpl::OnMessage(talk_base::Message* msg) {
case CMD_LISTEN_FOR_UPDATES:
DoListenForUpdates();
break;
- case CMD_SEND_NOTIFICATION:
- DoSendNotification();
+ case CMD_SEND_NOTIFICATION: {
+ DCHECK(msg->pdata);
+ scoped_ptr<OutgoingNotificationMessageData> data(
+ reinterpret_cast<OutgoingNotificationMessageData*>(msg->pdata));
+ DoSendNotification(*data);
break;
+ }
case CMD_SUBSCRIBE_FOR_UPDATES: {
DCHECK(msg->pdata);
scoped_ptr<SubscriptionData> subscription_data(
@@ -132,9 +130,6 @@ void MediatorThreadImpl::DoLogin(LoginData* login_data) {
LOG(INFO) << "P2P: Thread logging into talk network.";
buzz::XmppClientSettings& user_settings = login_data->user_settings;
- // Set our service id.
- user_settings.set_token_service(SYNC_SERVICE_NAME);
-
// Start a new pump for the login.
login_.reset();
pump_.reset(new notifier::TaskPump());
@@ -213,8 +208,7 @@ void MediatorThreadImpl::DoSubscribeForUpdates(
return;
}
SubscribeTask* subscription =
- new SubscribeTask(client, notification_method_,
- subscription_data.subscribed_services_list);
+ new SubscribeTask(client, subscription_data.subscribed_services_list);
subscription->SignalStatusUpdate.connect(
this,
&MediatorThreadImpl::OnSubscriptionStateChange);
@@ -227,20 +221,21 @@ void MediatorThreadImpl::DoListenForUpdates() {
if (!client) {
return;
}
- ListenTask* listener = new ListenTask(client, notification_method_);
+ ListenTask* listener = new ListenTask(client);
listener->SignalUpdateAvailable.connect(
this,
&MediatorThreadImpl::OnUpdateListenerMessage);
listener->Start();
}
-void MediatorThreadImpl::DoSendNotification() {
+void MediatorThreadImpl::DoSendNotification(
+ const OutgoingNotificationMessageData& data) {
buzz::XmppClient* client = xmpp_client();
// If there isn't an active xmpp client, return.
if (!client) {
return;
}
- SendUpdateTask* task = new SendUpdateTask(client, notification_method_);
+ SendUpdateTask* task = new SendUpdateTask(client, data.notification_data);
task->SignalStatusUpdate.connect(
this,
&MediatorThreadImpl::OnUpdateNotificationSent);
@@ -248,7 +243,7 @@ void MediatorThreadImpl::DoSendNotification() {
}
void MediatorThreadImpl::OnUpdateListenerMessage(
- const NotificationData& notification_data) {
+ const IncomingNotificationData& notification_data) {
SignalNotificationReceived(notification_data);
}
diff --git a/chrome/browser/sync/notifier/listener/mediator_thread_impl.h b/chrome/browser/sync/notifier/listener/mediator_thread_impl.h
index cc40308..8455009 100644
--- a/chrome/browser/sync/notifier/listener/mediator_thread_impl.h
+++ b/chrome/browser/sync/notifier/listener/mediator_thread_impl.h
@@ -77,13 +77,25 @@ struct SubscriptionData : public talk_base::MessageData {
std::vector<std::string> subscribed_services_list;
};
+// Used to pass outgoing notification information from the mediator to the
+// thread. Use new to allocate it on the heap, the thread will delete it
+// for you.
+struct OutgoingNotificationMessageData : public talk_base::MessageData {
+ explicit OutgoingNotificationMessageData(
+ const OutgoingNotificationData& data) : notification_data(data) {
+ }
+ virtual ~OutgoingNotificationMessageData() {}
+
+ OutgoingNotificationData notification_data;
+};
+
class MediatorThreadImpl
: public MediatorThread,
public sigslot::has_slots<>,
public talk_base::MessageHandler,
public talk_base::Thread {
public:
- explicit MediatorThreadImpl(NotificationMethod notification_method);
+ explicit MediatorThreadImpl();
virtual ~MediatorThreadImpl();
// Start the thread.
@@ -98,7 +110,7 @@ class MediatorThreadImpl
void ListenForUpdates();
void SubscribeForUpdates(
const std::vector<std::string>& subscribed_services_list);
- void SendNotification();
+ void SendNotification(const OutgoingNotificationData& data);
void LogStanzas();
private:
@@ -109,12 +121,14 @@ class MediatorThreadImpl
void DoDisconnect();
void DoSubscribeForUpdates(const SubscriptionData& subscription_data);
void DoListenForUpdates();
- void DoSendNotification();
+ void DoSendNotification(
+ const OutgoingNotificationMessageData& data);
void DoStanzaLogging();
void PumpAuxiliaryLoops();
// These handle messages indicating an event happened in the outside world.
- void OnUpdateListenerMessage(const NotificationData& notification_data);
+ void OnUpdateListenerMessage(
+ const IncomingNotificationData& notification_data);
void OnUpdateNotificationSent(bool success);
void OnLoginFailureMessage(const notifier::LoginFailure& failure);
void OnClientStateChangeMessage(notifier::Login::ConnectionState state);
diff --git a/chrome/browser/sync/notifier/listener/mediator_thread_mock.h b/chrome/browser/sync/notifier/listener/mediator_thread_mock.h
index 172e154..7a8b0f2 100644
--- a/chrome/browser/sync/notifier/listener/mediator_thread_mock.h
+++ b/chrome/browser/sync/notifier/listener/mediator_thread_mock.h
@@ -20,7 +20,7 @@ namespace browser_sync {
class MockMediatorThread : public MediatorThread {
public:
- MockMediatorThread() : MediatorThread(kDefaultNotificationMethod) {
+ MockMediatorThread() : MediatorThread() {
Reset();
}
~MockMediatorThread() {}
@@ -56,7 +56,7 @@ class MockMediatorThread : public MediatorThread {
listen_calls++;
}
- virtual void SendNotification() {
+ virtual void SendNotification(const OutgoingNotificationData &) {
send_calls++;
}
@@ -64,7 +64,7 @@ class MockMediatorThread : public MediatorThread {
void ChangeState(MediatorThread::MediatorMessage message) {
SignalStateChange(message);
}
- void Notify(const NotificationData& data) {
+ void Notify(const IncomingNotificationData& data) {
SignalNotificationReceived(data);
}
diff --git a/chrome/browser/sync/notifier/listener/notification_constants.cc b/chrome/browser/sync/notifier/listener/notification_constants.cc
index bd253e5..aa21640 100644
--- a/chrome/browser/sync/notifier/listener/notification_constants.cc
+++ b/chrome/browser/sync/notifier/listener/notification_constants.cc
@@ -7,11 +7,5 @@
namespace browser_sync {
const char kNotifierNamespace[] = "google:notifier";
-const char kSyncLegacyServiceUrl[] = "google:notifier";
-const char kSyncServiceUrl[] = "http://www.google.com/chrome/sync";
-const char kSyncLegacyServiceId[] = "notification";
-const char kSyncServiceId[] = "sync-ping";
-const int kSyncPriority = 200;
-const char kSyncServiceSpecificData[] = "sync-ping-p2p";
} // namespace browser_sync
diff --git a/chrome/browser/sync/notifier/listener/notification_constants.h b/chrome/browser/sync/notifier/listener/notification_constants.h
index afb40d2..e365e16 100644
--- a/chrome/browser/sync/notifier/listener/notification_constants.h
+++ b/chrome/browser/sync/notifier/listener/notification_constants.h
@@ -8,12 +8,6 @@
namespace browser_sync {
extern const char kNotifierNamespace[];
-extern const char kSyncLegacyServiceUrl[];
-extern const char kSyncServiceUrl[];
-extern const char kSyncLegacyServiceId[];
-extern const char kSyncServiceId[];
-extern const int kSyncPriority;
-extern const char kSyncServiceSpecificData[];
} // namespace browser_sync
diff --git a/chrome/browser/sync/notifier/listener/notification_defines.h b/chrome/browser/sync/notifier/listener/notification_defines.h
index 5ea4d25..8bdc852 100644
--- a/chrome/browser/sync/notifier/listener/notification_defines.h
+++ b/chrome/browser/sync/notifier/listener/notification_defines.h
@@ -7,10 +7,28 @@
#include <string>
-struct NotificationData {
+struct IncomingNotificationData {
std::string service_url;
std::string service_specific_data;
};
+struct OutgoingNotificationData {
+ OutgoingNotificationData() : send_content(false), priority(0),
+ require_subscription(false),
+ write_to_cache_only(false) {
+ }
+ // 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;
+};
+
#endif // CHROME_BROWSER_SYNC_NOTIFIER_LISTENER_NOTIFICATION_DEFINES_H_
diff --git a/chrome/browser/sync/notifier/listener/send_update_task.cc b/chrome/browser/sync/notifier/listener/send_update_task.cc
index 6204310..b97b965 100644
--- a/chrome/browser/sync/notifier/listener/send_update_task.cc
+++ b/chrome/browser/sync/notifier/listener/send_update_task.cc
@@ -17,9 +17,9 @@
namespace browser_sync {
SendUpdateTask::SendUpdateTask(Task* parent,
- NotificationMethod notification_method)
+ const OutgoingNotificationData& data)
: XmppTask(parent, buzz::XmppEngine::HL_SINGLE), // Watch for one reply.
- notification_method_(notification_method) {
+ notification_data_(data) {
}
SendUpdateTask::~SendUpdateTask() {
@@ -35,7 +35,7 @@ bool SendUpdateTask::HandleStanza(const buzz::XmlElement* stanza) {
int SendUpdateTask::ProcessStart() {
LOG(INFO) << "P2P: Notification task started.";
scoped_ptr<buzz::XmlElement> stanza(
- MakeUpdateMessage(notification_method_,
+ MakeUpdateMessage(notification_data_,
GetClient()->jid().BareJid(), task_id()));
LOG(INFO) << "P2P: Notification stanza: "
<< XmlElementToString(*stanza.get());
@@ -73,108 +73,58 @@ int SendUpdateTask::ProcessResponse() {
}
buzz::XmlElement* SendUpdateTask::MakeUpdateMessage(
- NotificationMethod notification_method,
- const buzz::Jid& to_jid_bare, const std::string& task_id) {
- switch (notification_method) {
- case NOTIFICATION_LEGACY:
- return MakeLegacyUpdateMessage(to_jid_bare, task_id);
- case NOTIFICATION_TRANSITIONAL:
- return MakeNonLegacyUpdateMessage(true, to_jid_bare, task_id);
- case NOTIFICATION_NEW:
- return MakeNonLegacyUpdateMessage(false, to_jid_bare, task_id);
- }
- NOTREACHED();
- return NULL;
-}
-
-// TODO(akalin): Remove this once we get all clients on at least
-// NOTIFICATION_TRANSITIONAL.
-
-buzz::XmlElement* SendUpdateTask::MakeLegacyUpdateMessage(
- const buzz::Jid& to_jid_bare, const std::string& task_id) {
- DCHECK(to_jid_bare.IsBare());
- static const buzz::QName kQnNotifierSet(true, kNotifierNamespace, "set");
- static const buzz::QName kQnId(true, buzz::STR_EMPTY, "Id");
- static const buzz::QName kQnServiceUrl(true, buzz::STR_EMPTY, "ServiceUrl");
- static const buzz::QName kQnData(true, buzz::STR_EMPTY, "data");
- static const buzz::QName kQnServiceId(true, buzz::STR_EMPTY, "ServiceId");
-
- // Create our update stanza. In the future this may include the revision id,
- // but at the moment simply does a p2p ping. The message is constructed as:
- // <iq type='get' from='{fullJid}' to='{bareJid}' id='{#}'>
- // <set xmlns="google:notifier">
- // <Id xmlns="">
- // <ServiceUrl xmlns="" data="google:notifier"/>
- // <ServiceId xmlns="" data="notification"/>
- // </Id>
- // </set>
- // </iq>
- buzz::XmlElement* stanza = MakeIq(buzz::STR_GET, to_jid_bare, task_id);
- buzz::XmlElement* notifier_set = new buzz::XmlElement(kQnNotifierSet, true);
- stanza->AddElement(notifier_set);
-
- buzz::XmlElement* id = new buzz::XmlElement(kQnId, true);
- notifier_set->AddElement(id);
-
- buzz::XmlElement* service_url = new buzz::XmlElement(kQnServiceUrl, true);
- service_url->AddAttr(kQnData, kSyncLegacyServiceUrl);
- id->AddElement(service_url);
-
- buzz::XmlElement* service_id = new buzz::XmlElement(kQnServiceId, true);
- service_id->AddAttr(kQnData, kSyncLegacyServiceId);
- id->AddElement(service_id);
- return stanza;
-}
-
-// TODO(akalin): Remove the is_transitional switch once we get all
-// clients on at least NOTIFICATION_NEW.
-
-buzz::XmlElement* SendUpdateTask::MakeNonLegacyUpdateMessage(
- bool is_transitional,
+ 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(true, kNotifierNamespace, "set");
static const buzz::QName kQnId(true, buzz::STR_EMPTY, "Id");
static const buzz::QName kQnContent(true, buzz::STR_EMPTY, "Content");
- // Create our update stanza. In the future this may include the revision id,
- // but at the moment simply does a p2p ping. The message is constructed as:
+ // 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="http://www.google.com/chrome/sync" />
- // <ServiceId data="sync-ping" />
+ // <ServiceUrl data="{Service_Url}" />
+ // <ServiceId data="{Service_Id}" />
// </Id>
+ // If content needs to be sent, then the below element is added
// <Content>
- // <Priority int="200" />
- // <!-- If is_transitional is not set, the bool value is "true". -->
- // <RequireSubscription bool="false" />
+ // <Priority int="{Priority}" />
+ // <RequireSubscription bool="{true/false}" />
// <!-- If is_transitional is set, this is omitted. -->
- // <ServiceSpecificData data="sync-ping-p2p" />
- // <WriteToCacheOnly bool="true" />
+ // <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);
- buzz::XmlElement* content = new buzz::XmlElement(kQnContent, true);
iq->AddElement(set);
set->AddElement(id);
- set->AddElement(content);
- id->AddElement(MakeStringXmlElement("ServiceUrl", kSyncServiceUrl));
- id->AddElement(MakeStringXmlElement("ServiceId", kSyncServiceId));
+ id->AddElement(MakeStringXmlElement("ServiceUrl",
+ notification_data.service_url.c_str()));
+ id->AddElement(MakeStringXmlElement("ServiceId",
+ notification_data.service_id.c_str()));
- content->AddElement(MakeIntXmlElement("Priority", kSyncPriority));
- content->AddElement(
- MakeBoolXmlElement("RequireSubscription", !is_transitional));
- if (!is_transitional) {
+ 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", kSyncServiceSpecificData));
+ MakeStringXmlElement("ServiceSpecificData",
+ notification_data.service_specific_data.c_str()));
+ }
+ content->AddElement(
+ MakeBoolXmlElement("WriteToCacheOnly",
+ notification_data.write_to_cache_only));
}
- content->AddElement(MakeBoolXmlElement("WriteToCacheOnly", true));
-
return iq;
}
diff --git a/chrome/browser/sync/notifier/listener/send_update_task.h b/chrome/browser/sync/notifier/listener/send_update_task.h
index ae422af..2cf8fbd 100644
--- a/chrome/browser/sync/notifier/listener/send_update_task.h
+++ b/chrome/browser/sync/notifier/listener/send_update_task.h
@@ -9,7 +9,7 @@
#include <string>
-#include "chrome/browser/sync/notification_method.h"
+#include "chrome/browser/sync/notifier/listener/notification_defines.h"
#include "talk/xmllite/xmlelement.h"
#include "talk/xmpp/xmpptask.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
@@ -18,7 +18,7 @@ namespace browser_sync {
class SendUpdateTask : public buzz::XmppTask {
public:
- SendUpdateTask(Task* parent, NotificationMethod notification_method);
+ SendUpdateTask(Task* parent, const OutgoingNotificationData& data);
virtual ~SendUpdateTask();
// Overridden from buzz::XmppTask.
@@ -32,21 +32,12 @@ class SendUpdateTask : public buzz::XmppTask {
private:
// Allocates and constructs an buzz::XmlElement containing the update stanza.
static buzz::XmlElement* MakeUpdateMessage(
- NotificationMethod notification_method,
+ const OutgoingNotificationData& notification_data,
const buzz::Jid& to_jid_bare, const std::string& task_id);
- static buzz::XmlElement* MakeLegacyUpdateMessage(
- const buzz::Jid& to_jid_bare, const std::string& task_id);
-
- static buzz::XmlElement* MakeNonLegacyUpdateMessage(
- bool is_transitional,
- const buzz::Jid& to_jid_bare, const std::string& task_id);
-
- NotificationMethod notification_method_;
+ OutgoingNotificationData notification_data_;
FRIEND_TEST(SendUpdateTaskTest, MakeUpdateMessage);
- FRIEND_TEST(SendUpdateTaskTest, MakeLegacyUpdateMessage);
- FRIEND_TEST(SendUpdateTaskTest, MakeNonLegacyUpdateMessage);
DISALLOW_COPY_AND_ASSIGN(SendUpdateTask);
};
diff --git a/chrome/browser/sync/notifier/listener/send_update_task_unittest.cc b/chrome/browser/sync/notifier/listener/send_update_task_unittest.cc
index 50dd379..0d06a3d 100644
--- a/chrome/browser/sync/notifier/listener/send_update_task_unittest.cc
+++ b/chrome/browser/sync/notifier/listener/send_update_task_unittest.cc
@@ -7,7 +7,6 @@
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
-#include "chrome/browser/sync/notification_method.h"
#include "chrome/browser/sync/notifier/listener/xml_element_util.h"
#include "talk/xmpp/jid.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -32,101 +31,86 @@ class SendUpdateTaskTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(SendUpdateTaskTest);
};
-TEST_F(SendUpdateTaskTest, MakeLegacyUpdateMessage) {
- scoped_ptr<buzz::XmlElement> message(
- SendUpdateTask::MakeLegacyUpdateMessage(to_jid_bare_, task_id_));
- const std::string expected_xml_string =
+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=\"google:notifier\"/>"
- "<ServiceId xmlns=\"\" data=\"notification\"/>"
+ "<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));
-}
+ EXPECT_EQ(expected_xml_string, XmlElementToString(*message_without_content));
+
+ data.send_content = true;
-TEST_F(SendUpdateTaskTest, MakeNonLegacyUpdateMessage) {
- scoped_ptr<buzz::XmlElement> new_message(
- SendUpdateTask::MakeNonLegacyUpdateMessage(false, to_jid_bare_,
- task_id_));
- const std::string expected_new_xml_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=\"http://www.google.com/chrome/sync\"/>"
- "<ServiceId xmlns=\"\" data=\"sync-ping\"/>"
+ "data=\"test_service_url\"/>"
+ "<ServiceId xmlns=\"\" data=\"test_service_id\"/>"
"</Id>"
"<Content xmlns=\"\">"
"<Priority xmlns=\"\" int=\"200\"/>"
- "<RequireSubscription xmlns=\"\" bool=\"true\"/>"
- "<ServiceSpecificData xmlns=\"\" "
- "data=\"sync-ping-p2p\"/>"
+ "<RequireSubscription xmlns=\"\" bool=\"false\"/>"
"<WriteToCacheOnly xmlns=\"\" bool=\"true\"/>"
"</Content>"
"</set>"
"</cli:iq>",
to_jid_bare_.Str().c_str(), task_id_.c_str());
- EXPECT_EQ(expected_new_xml_string, XmlElementToString(*new_message));
- scoped_ptr<buzz::XmlElement> transitional_message(
- SendUpdateTask::MakeNonLegacyUpdateMessage(true, to_jid_bare_,
- task_id_));
- const std::string expected_transitional_xml_string =
+ 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=\"http://www.google.com/chrome/sync\"/>"
- "<ServiceId xmlns=\"\" data=\"sync-ping\"/>"
+ "data=\"test_service_url\"/>"
+ "<ServiceId xmlns=\"\" data=\"test_service_id\"/>"
"</Id>"
"<Content xmlns=\"\">"
"<Priority xmlns=\"\" int=\"200\"/>"
- "<RequireSubscription xmlns=\"\" bool=\"false\"/>"
+ "<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());
- EXPECT_EQ(expected_transitional_xml_string,
- XmlElementToString(*transitional_message));
-}
-TEST_F(SendUpdateTaskTest, MakeUpdateMessage) {
- scoped_ptr<buzz::XmlElement> expected_legacy_message(
- SendUpdateTask::MakeLegacyUpdateMessage(to_jid_bare_, task_id_));
- scoped_ptr<buzz::XmlElement> legacy_message(
- SendUpdateTask::MakeUpdateMessage(NOTIFICATION_LEGACY,
- to_jid_bare_, task_id_));
- EXPECT_EQ(XmlElementToString(*expected_legacy_message),
- XmlElementToString(*legacy_message));
-
- scoped_ptr<buzz::XmlElement> expected_transitional_message(
- SendUpdateTask::MakeNonLegacyUpdateMessage(true,
- to_jid_bare_, task_id_));
- scoped_ptr<buzz::XmlElement> transitional_message(
- SendUpdateTask::MakeUpdateMessage(NOTIFICATION_TRANSITIONAL,
- to_jid_bare_, task_id_));
- EXPECT_EQ(XmlElementToString(*expected_transitional_message),
- XmlElementToString(*transitional_message));
-
- scoped_ptr<buzz::XmlElement> expected_new_message(
- SendUpdateTask::MakeNonLegacyUpdateMessage(false,
- to_jid_bare_, task_id_));
- scoped_ptr<buzz::XmlElement> new_message(
- SendUpdateTask::MakeUpdateMessage(NOTIFICATION_NEW,
- to_jid_bare_, task_id_));
- EXPECT_EQ(XmlElementToString(*expected_new_message),
- XmlElementToString(*new_message));
+ 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 browser_sync
diff --git a/chrome/browser/sync/notifier/listener/subscribe_task.cc b/chrome/browser/sync/notifier/listener/subscribe_task.cc
index de26466..332513c 100644
--- a/chrome/browser/sync/notifier/listener/subscribe_task.cc
+++ b/chrome/browser/sync/notifier/listener/subscribe_task.cc
@@ -19,10 +19,9 @@
namespace browser_sync {
SubscribeTask::SubscribeTask(
- Task* parent, NotificationMethod notification_method,
+ Task* parent,
const std::vector<std::string>& subscribed_services_list)
: XmppTask(parent, buzz::XmppEngine::HL_SINGLE),
- notification_method_(notification_method),
subscribed_services_list_(subscribed_services_list) {
}
@@ -39,8 +38,7 @@ bool SubscribeTask::HandleStanza(const buzz::XmlElement* stanza) {
int SubscribeTask::ProcessStart() {
LOG(INFO) << "P2P: Subscription task started.";
scoped_ptr<buzz::XmlElement> iq_stanza(
- MakeSubscriptionMessage(notification_method_,
- subscribed_services_list_,
+ MakeSubscriptionMessage(subscribed_services_list_,
GetClient()->jid().BareJid(), task_id()));
LOG(INFO) << "P2P: Subscription stanza: "
<< XmlElementToString(*iq_stanza.get());
@@ -74,61 +72,6 @@ int SubscribeTask::ProcessResponse() {
}
buzz::XmlElement* SubscribeTask::MakeSubscriptionMessage(
- NotificationMethod notification_method,
- const std::vector<std::string>& subscribed_services_list,
- const buzz::Jid& to_jid_bare, const std::string& task_id) {
- switch (notification_method) {
- case NOTIFICATION_LEGACY:
- return MakeLegacySubscriptionMessage(to_jid_bare, task_id);
- case NOTIFICATION_TRANSITIONAL:
- case NOTIFICATION_NEW:
- return MakeNonLegacySubscriptionMessage(subscribed_services_list,
- to_jid_bare,
- task_id);
- }
- NOTREACHED();
- return NULL;
-}
-
-// TODO(akalin): Remove this once we get all clients on at least
-// NOTIFICATION_TRANSITIONAL.
-
-buzz::XmlElement* SubscribeTask::MakeLegacySubscriptionMessage(
- const buzz::Jid& to_jid_bare, const std::string& task_id) {
- DCHECK(to_jid_bare.IsBare());
- static const buzz::QName kQnNotifierGetAll(
- true, kNotifierNamespace, "getAll");
- static const buzz::QName kQnNotifierClientActive(true,
- buzz::STR_EMPTY,
- "ClientActive");
- static const buzz::QName kQnBool(true, buzz::STR_EMPTY, "bool");
- static const std::string kTrueString("true");
-
- // 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'/>
- // </gn:getAll>
- // </iq>
- buzz::XmlElement* get_all_request =
- MakeIq(buzz::STR_GET, to_jid_bare, task_id);
-
- buzz::XmlElement* notifier_get =
- new buzz::XmlElement(kQnNotifierGetAll, true);
- get_all_request->AddElement(notifier_get);
-
- buzz::XmlElement* client_active =
- new buzz::XmlElement(kQnNotifierClientActive, true);
- client_active->AddAttr(kQnBool, kTrueString);
- notifier_get->AddElement(client_active);
-
- return get_all_request;
-}
-
-// TODO(akalin): Remove the is_transitional switch once we get all
-// clients on at least NOTIFICATION_NEW.
-
-buzz::XmlElement* SubscribeTask::MakeNonLegacySubscriptionMessage(
const std::vector<std::string>& subscribed_services_list,
const buzz::Jid& to_jid_bare, const std::string& task_id) {
DCHECK(to_jid_bare.IsBare());
@@ -139,7 +82,7 @@ buzz::XmlElement* SubscribeTask::MakeNonLegacySubscriptionMessage(
// <iq type='get' from='{fullJid}' to='{bareJid}' id='{#}'>
// <gn:getAll xmlns:gn="google:notifier" xmlns="">
// <ClientActive bool="true" />
- // <!-- present only if is_transitional is set -->
+ // <!-- present only if subscribed_services_list is not empty -->
// <SubscribedServiceUrl data="google:notifier">
// <SubscribedServiceUrl data="http://www.google.com/chrome/sync">
// <FilterNonSubscribed bool="true" />
@@ -157,8 +100,9 @@ buzz::XmlElement* SubscribeTask::MakeNonLegacySubscriptionMessage(
get_all->AddElement(
MakeStringXmlElement("SubscribedServiceUrl", iter->c_str()));
}
- get_all->AddElement(MakeBoolXmlElement("FilterNonSubscribed", true));
-
+ if (!subscribed_services_list.empty()) {
+ get_all->AddElement(MakeBoolXmlElement("FilterNonSubscribed", true));
+ }
return iq;
}
diff --git a/chrome/browser/sync/notifier/listener/subscribe_task.h b/chrome/browser/sync/notifier/listener/subscribe_task.h
index 32a563b..15dd134 100644
--- a/chrome/browser/sync/notifier/listener/subscribe_task.h
+++ b/chrome/browser/sync/notifier/listener/subscribe_task.h
@@ -12,7 +12,6 @@
#include <string>
#include <vector>
-#include "chrome/browser/sync/notification_method.h"
#include "talk/xmllite/xmlelement.h"
#include "talk/xmpp/xmpptask.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
@@ -22,7 +21,7 @@ namespace browser_sync {
// in this class and any other class that uses notification_method.
class SubscribeTask : public buzz::XmppTask {
public:
- SubscribeTask(Task* parent, NotificationMethod notification_method,
+ SubscribeTask(Task* parent,
const std::vector<std::string>& subscribed_services_list);
virtual ~SubscribeTask();
@@ -37,22 +36,11 @@ class SubscribeTask : public buzz::XmppTask {
private:
// Assembles an Xmpp stanza which can be sent to subscribe to notifications.
static buzz::XmlElement* MakeSubscriptionMessage(
- NotificationMethod notification_method,
const std::vector<std::string>& subscribed_services_list,
const buzz::Jid& to_jid_bare, const std::string& task_id);
- static buzz::XmlElement* MakeLegacySubscriptionMessage(
- const buzz::Jid& to_jid_bare, const std::string& task_id);
-
- static buzz::XmlElement* MakeNonLegacySubscriptionMessage(
- const std::vector<std::string>& subscribed_services_list,
- const buzz::Jid& to_jid_bare, const std::string& task_id);
-
- NotificationMethod notification_method_;
std::vector<std::string> subscribed_services_list_;
- FRIEND_TEST(SubscribeTaskTest, MakeLegacySubscriptionMessage);
- FRIEND_TEST(SubscribeTaskTest, MakeNonLegacySubscriptionMessage);
FRIEND_TEST(SubscribeTaskTest, MakeSubscriptionMessage);
DISALLOW_COPY_AND_ASSIGN(SubscribeTask);
diff --git a/chrome/browser/sync/notifier/listener/subscribe_task_unittest.cc b/chrome/browser/sync/notifier/listener/subscribe_task_unittest.cc
index d58d6e1..800b57d 100644
--- a/chrome/browser/sync/notifier/listener/subscribe_task_unittest.cc
+++ b/chrome/browser/sync/notifier/listener/subscribe_task_unittest.cc
@@ -8,7 +8,6 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "chrome/browser/sync/notification_method.h"
-#include "chrome/browser/sync/notifier/listener/notification_constants.h"
#include "chrome/browser/sync/notifier/listener/xml_element_util.h"
#include "talk/xmpp/jid.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -33,10 +32,12 @@ class SubscribeTaskTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(SubscribeTaskTest);
};
-TEST_F(SubscribeTaskTest, MakeLegacySubscriptionMessage) {
- scoped_ptr<buzz::XmlElement> message(
- SubscribeTask::MakeLegacySubscriptionMessage(to_jid_bare_, task_id_));
- const std::string expected_xml_string =
+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\">"
@@ -45,66 +46,29 @@ TEST_F(SubscribeTaskTest, MakeLegacySubscriptionMessage) {
"</getAll>"
"</cli:iq>",
to_jid_bare_.Str().c_str(), task_id_.c_str());
- EXPECT_EQ(expected_xml_string, XmlElementToString(*message));
-}
+ EXPECT_EQ(expected_xml_string, XmlElementToString(*message_without_services));
-TEST_F(SubscribeTaskTest, MakeNonLegacySubscriptionMessage) {
- std::vector<std::string> subscribed_services_list;
- subscribed_services_list.push_back(kSyncLegacyServiceUrl);
- subscribed_services_list.push_back(kSyncServiceUrl);
- scoped_ptr<buzz::XmlElement> new_message(
- SubscribeTask::MakeNonLegacySubscriptionMessage(subscribed_services_list,
- to_jid_bare_,
- task_id_));
- const std::string expected_xml_string =
+ 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=\"google:notifier\"/>"
"<SubscribedServiceUrl "
- "xmlns=\"\" data=\"http://www.google.com/chrome/sync\"/>"
+ "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(*new_message));
-}
-TEST_F(SubscribeTaskTest, MakeSubscriptionMessage) {
- std::vector<std::string> subscribed_services_list;
- subscribed_services_list.push_back(kSyncLegacyServiceUrl);
- subscribed_services_list.push_back(kSyncServiceUrl);
-
- scoped_ptr<buzz::XmlElement> expected_legacy_message(
- SubscribeTask::MakeLegacySubscriptionMessage(to_jid_bare_, task_id_));
- scoped_ptr<buzz::XmlElement> legacy_message(
- SubscribeTask::MakeSubscriptionMessage(NOTIFICATION_LEGACY,
- subscribed_services_list,
- to_jid_bare_, task_id_));
- EXPECT_EQ(XmlElementToString(*expected_legacy_message),
- XmlElementToString(*legacy_message));
-
- scoped_ptr<buzz::XmlElement> expected_transitional_message(
- SubscribeTask::MakeNonLegacySubscriptionMessage(subscribed_services_list,
- to_jid_bare_, task_id_));
- scoped_ptr<buzz::XmlElement> transitional_message(
- SubscribeTask::MakeSubscriptionMessage(NOTIFICATION_TRANSITIONAL,
- subscribed_services_list,
- to_jid_bare_, task_id_));
- EXPECT_EQ(XmlElementToString(*expected_transitional_message),
- XmlElementToString(*transitional_message));
-
- scoped_ptr<buzz::XmlElement> expected_new_message(
- SubscribeTask::MakeNonLegacySubscriptionMessage(subscribed_services_list,
- to_jid_bare_, task_id_));
- scoped_ptr<buzz::XmlElement> new_message(
- SubscribeTask::MakeSubscriptionMessage(NOTIFICATION_NEW,
- subscribed_services_list,
- to_jid_bare_, task_id_));
- EXPECT_EQ(XmlElementToString(*expected_new_message),
- XmlElementToString(*new_message));
+ EXPECT_EQ(expected_xml_string, XmlElementToString(*message_with_services));
}
} // namespace browser_sync
diff --git a/chrome/browser/sync/notifier/listener/talk_mediator.h b/chrome/browser/sync/notifier/listener/talk_mediator.h
index 854ddbe..a898113 100644
--- a/chrome/browser/sync/notifier/listener/talk_mediator.h
+++ b/chrome/browser/sync/notifier/listener/talk_mediator.h
@@ -8,7 +8,7 @@
// Example usage:
//
// TalkMediator mediator();
-// mediator.SetAuthToken("email", "token");
+// mediator.SetAuthToken("email", "token", "service_id");
// mediator.Login();
// ...
// mediator.Logout();
@@ -19,6 +19,7 @@
#include <string>
#include "chrome/browser/sync/notifier/listener/notification_defines.h"
+#include "chrome/common/deprecated/event_sys.h"
namespace browser_sync {
@@ -42,7 +43,7 @@ struct TalkMediatorEvent {
WhatHappened what_happened;
// Data in the case of a NOTIFICATION_RECEIVED event
- NotificationData notification_data;
+ IncomingNotificationData notification_data;
};
typedef EventChannel<TalkMediatorEvent, Lock> TalkMediatorChannel;
@@ -54,13 +55,14 @@ class TalkMediator {
// The following methods are for authorizaiton of the xmpp client.
virtual bool SetAuthToken(const std::string& email,
- const std::string& token) = 0;
+ const std::string& token,
+ const std::string& token_service) = 0;
virtual bool Login() = 0;
virtual bool Logout() = 0;
// Method for the owner of this object to notify peers that an update has
// occurred.
- virtual bool SendNotification() = 0;
+ virtual bool SendNotification(const OutgoingNotificationData& data) = 0;
// Channel by which talk mediator events are signaled.
virtual TalkMediatorChannel* channel() const = 0;
diff --git a/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc b/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc
index 3c1628a..7e5fc22 100644
--- a/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc
+++ b/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc
@@ -39,9 +39,8 @@ class SslInitializationSingleton {
DISALLOW_COPY_AND_ASSIGN(SslInitializationSingleton);
};
-TalkMediatorImpl::TalkMediatorImpl(NotificationMethod notification_method,
- bool invalidate_xmpp_auth_token)
- : mediator_thread_(new MediatorThreadImpl(notification_method)),
+TalkMediatorImpl::TalkMediatorImpl(bool invalidate_xmpp_auth_token)
+ : mediator_thread_(new MediatorThreadImpl()),
invalidate_xmpp_auth_token_(invalidate_xmpp_auth_token) {
// Ensure the SSL library is initialized.
SslInitializationSingleton::GetInstance()->RegisterClient();
@@ -118,10 +117,10 @@ bool TalkMediatorImpl::Logout() {
return false;
}
-bool TalkMediatorImpl::SendNotification() {
+bool TalkMediatorImpl::SendNotification(const OutgoingNotificationData& data) {
AutoLock lock(mutex_);
if (state_.logged_in && state_.subscribed) {
- mediator_thread_->SendNotification();
+ mediator_thread_->SendNotification(data);
return true;
}
return false;
@@ -132,7 +131,8 @@ TalkMediatorChannel* TalkMediatorImpl::channel() const {
}
bool TalkMediatorImpl::SetAuthToken(const std::string& email,
- const std::string& token) {
+ const std::string& token,
+ const std::string& token_service) {
AutoLock lock(mutex_);
// Verify that we can create a JID from the email provided.
@@ -148,6 +148,7 @@ bool TalkMediatorImpl::SetAuthToken(const std::string& email,
xmpp_settings_.set_use_tls(true);
xmpp_settings_.set_auth_cookie(invalidate_xmpp_auth_token_ ?
token + "bogus" : token);
+ xmpp_settings_.set_token_service(token_service);
state_.initialized = 1;
return true;
@@ -189,7 +190,7 @@ void TalkMediatorImpl::MediatorThreadMessageHandler(
}
void TalkMediatorImpl::MediatorThreadNotificationHandler(
- const NotificationData& notification_data) {
+ const IncomingNotificationData& notification_data) {
LOG(INFO) << "P2P: Updates are available on the server.";
AutoLock lock(mutex_);
TalkMediatorEvent event = { TalkMediatorEvent::NOTIFICATION_RECEIVED };
@@ -224,15 +225,17 @@ void TalkMediatorImpl::OnLogout() {
void TalkMediatorImpl::OnSubscriptionSuccess() {
LOG(INFO) << "P2P: Update subscription active.";
- AutoLock lock(mutex_);
- state_.subscribed = 1;
+ {
+ AutoLock lock(mutex_);
+ state_.subscribed = 1;
+ }
+ // The above scope exists so that we can release the lock before
+ // notifying listeners. In theory we should do this for all methods.
+ // Notifying listeners with a lock held can cause the lock to be
+ // recursively taken if the listener decides to call back into us
+ // in the event handler.
TalkMediatorEvent event = { TalkMediatorEvent::SUBSCRIPTIONS_ON };
channel_->NotifyListeners(event);
- // Send an initial nudge when we connect. This is to deal with the
- // case that there are unsynced changes when Chromium starts up. This would
- // caused changes to be submitted before p2p is enabled, and therefore
- // the notification won't get sent out.
- mediator_thread_->SendNotification();
}
void TalkMediatorImpl::OnSubscriptionFailure() {
diff --git a/chrome/browser/sync/notifier/listener/talk_mediator_impl.h b/chrome/browser/sync/notifier/listener/talk_mediator_impl.h
index 53fec06..8488b5f 100644
--- a/chrome/browser/sync/notifier/listener/talk_mediator_impl.h
+++ b/chrome/browser/sync/notifier/listener/talk_mediator_impl.h
@@ -14,8 +14,6 @@
#include "base/lock.h"
#include "base/scoped_ptr.h"
-#include "chrome/browser/sync/engine/auth_watcher.h"
-#include "chrome/browser/sync/notification_method.h"
#include "chrome/browser/sync/notifier/listener/mediator_thread.h"
#include "chrome/browser/sync/notifier/listener/talk_mediator.h"
#include "talk/base/sigslot.h"
@@ -30,18 +28,18 @@ class TalkMediatorImpl
: public TalkMediator,
public sigslot::has_slots<> {
public:
- TalkMediatorImpl(NotificationMethod notification_method,
- bool invalidate_xmpp_auth_token);
+ explicit TalkMediatorImpl(bool invalidate_xmpp_auth_token);
explicit TalkMediatorImpl(MediatorThread* thread);
virtual ~TalkMediatorImpl();
// Overriden from TalkMediator.
virtual bool SetAuthToken(const std::string& email,
- const std::string& token);
+ const std::string& token,
+ const std::string& token_service);
virtual bool Login();
virtual bool Logout();
- virtual bool SendNotification();
+ virtual bool SendNotification(const OutgoingNotificationData& data);
TalkMediatorChannel* channel() const;
@@ -71,7 +69,7 @@ class TalkMediatorImpl
// Callbacks for the mediator thread.
void MediatorThreadMessageHandler(MediatorThread::MediatorMessage message);
void MediatorThreadNotificationHandler(
- const NotificationData& notification_data);
+ const IncomingNotificationData& notification_data);
// Responses to messages from the MediatorThread.
void OnNotificationSent();
diff --git a/chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc b/chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc
index 3c32448..7e4c0d6 100644
--- a/chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc
+++ b/chrome/browser/sync/notifier/listener/talk_mediator_unittest.cc
@@ -36,42 +36,44 @@ class TalkMediatorImplTest : public testing::Test {
TEST_F(TalkMediatorImplTest, ConstructionOfTheClass) {
// Constructing a single talk mediator enables SSL through the singleton.
- scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(
- browser_sync::kDefaultNotificationMethod, false));
+ scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(false));
talk1.reset(NULL);
}
TEST_F(TalkMediatorImplTest, SetAuthTokenWithBadInput) {
scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(
new MockMediatorThread()));
- ASSERT_FALSE(talk1->SetAuthToken("@missinguser.com", ""));
+ ASSERT_FALSE(talk1->SetAuthToken("@missinguser.com", "", "fake_service"));
ASSERT_TRUE(talk1->state_.initialized == 0);
scoped_ptr<TalkMediatorImpl> talk2(new TalkMediatorImpl(
new MockMediatorThread()));
- ASSERT_FALSE(talk2->SetAuthToken("", "1234567890"));
+ ASSERT_FALSE(talk2->SetAuthToken("", "1234567890", "fake_service"));
ASSERT_TRUE(talk2->state_.initialized == 0);
scoped_ptr<TalkMediatorImpl> talk3(new TalkMediatorImpl(
new MockMediatorThread()));
- ASSERT_FALSE(talk3->SetAuthToken("missingdomain", "abcde"));
+ ASSERT_FALSE(talk3->SetAuthToken("missingdomain", "abcde", "fake_service"));
ASSERT_TRUE(talk3->state_.initialized == 0);
}
TEST_F(TalkMediatorImplTest, SetAuthTokenWithGoodInput) {
scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(
new MockMediatorThread()));
- ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token"));
+ ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token",
+ "fake_service"));
ASSERT_TRUE(talk1->state_.initialized == 1);
scoped_ptr<TalkMediatorImpl> talk2(new TalkMediatorImpl(
new MockMediatorThread()));
- ASSERT_TRUE(talk2->SetAuthToken("chromium@mail.google.com", "token"));
+ ASSERT_TRUE(talk2->SetAuthToken("chromium@mail.google.com", "token",
+ "fake_service"));
ASSERT_TRUE(talk2->state_.initialized == 1);
scoped_ptr<TalkMediatorImpl> talk3(new TalkMediatorImpl(
new MockMediatorThread()));
- ASSERT_TRUE(talk3->SetAuthToken("chromium@chromium.org", "token"));
+ ASSERT_TRUE(talk3->SetAuthToken("chromium@chromium.org", "token",
+ "fake_service"));
ASSERT_TRUE(talk3->state_.initialized == 1);
}
@@ -84,7 +86,8 @@ TEST_F(TalkMediatorImplTest, LoginWiring) {
ASSERT_TRUE(talk1->Login() == false);
ASSERT_TRUE(mock->login_calls == 0);
- ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token") == true);
+ ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token",
+ "fake_service") == true);
ASSERT_TRUE(talk1->Login() == true);
ASSERT_TRUE(mock->login_calls == 1);
@@ -107,32 +110,34 @@ TEST_F(TalkMediatorImplTest, SendNotification) {
scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(mock));
// Failure due to not being logged in.
- ASSERT_TRUE(talk1->SendNotification() == false);
+ OutgoingNotificationData data;
+ ASSERT_TRUE(talk1->SendNotification(data) == false);
ASSERT_TRUE(mock->send_calls == 0);
- ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token") == true);
+ ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token",
+ "fake_service") == true);
ASSERT_TRUE(talk1->Login() == true);
talk1->OnLogin();
ASSERT_TRUE(mock->login_calls == 1);
// Failure due to not being subscribed.
- ASSERT_TRUE(talk1->SendNotification() == false);
+ ASSERT_TRUE(talk1->SendNotification(data) == false);
ASSERT_TRUE(mock->send_calls == 0);
// Fake subscription
talk1->OnSubscriptionSuccess();
ASSERT_TRUE(talk1->state_.subscribed == 1);
- ASSERT_TRUE(talk1->SendNotification() == true);
+ ASSERT_TRUE(talk1->SendNotification(data) == true);
+ ASSERT_TRUE(mock->send_calls == 1);
+ ASSERT_TRUE(talk1->SendNotification(data) == true);
ASSERT_TRUE(mock->send_calls == 2);
- ASSERT_TRUE(talk1->SendNotification() == true);
- ASSERT_TRUE(mock->send_calls == 3);
ASSERT_TRUE(talk1->Logout() == true);
ASSERT_TRUE(mock->logout_calls == 1);
// Failure due to being logged out.
- ASSERT_TRUE(talk1->SendNotification() == false);
- ASSERT_TRUE(mock->send_calls == 3);
+ ASSERT_TRUE(talk1->SendNotification(data) == false);
+ ASSERT_TRUE(mock->send_calls == 2);
}
TEST_F(TalkMediatorImplTest, MediatorThreadCallbacks) {
@@ -143,7 +148,8 @@ TEST_F(TalkMediatorImplTest, MediatorThreadCallbacks) {
scoped_ptr<EventListenerHookup> callback(NewEventListenerHookup(
talk1->channel(), this, &TalkMediatorImplTest::HandleTalkMediatorEvent));
- ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token") == true);
+ ASSERT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token",
+ "fake_service") == true);
ASSERT_TRUE(talk1->Login() == true);
ASSERT_TRUE(mock->login_calls == 1);
@@ -161,13 +167,14 @@ TEST_F(TalkMediatorImplTest, MediatorThreadCallbacks) {
// After subscription success is receieved, the talk mediator will allow
// sending of notifications.
- ASSERT_TRUE(talk1->SendNotification() == true);
- ASSERT_TRUE(mock->send_calls == 2);
-
- NotificationData data;
- data.service_url = "service_url";
- data.service_specific_data = "service_data";
- mock->Notify(data);
+ OutgoingNotificationData outgoing_data;
+ ASSERT_TRUE(talk1->SendNotification(outgoing_data) == true);
+ ASSERT_TRUE(mock->send_calls == 1);
+
+ IncomingNotificationData incoming_data;
+ incoming_data.service_url = "service_url";
+ incoming_data.service_specific_data = "service_data";
+ mock->Notify(incoming_data);
ASSERT_TRUE(last_message_ == TalkMediatorEvent::NOTIFICATION_RECEIVED);
// A |TALKMEDIATOR_DESTROYED| message is received during tear down.
diff --git a/chrome/browser/sync/sync_constants.cc b/chrome/browser/sync/sync_constants.cc
new file mode 100644
index 0000000..923d2b3
--- /dev/null
+++ b/chrome/browser/sync/sync_constants.cc
@@ -0,0 +1,17 @@
+// 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 "chrome/browser/sync/sync_constants.h"
+
+namespace browser_sync {
+
+const char kSyncLegacyServiceUrl[] = "google:notifier";
+const char kSyncServiceUrl[] = "http://www.google.com/chrome/sync";
+const char kSyncLegacyServiceId[] = "notification";
+const char kSyncServiceId[] = "sync-ping";
+const int kSyncPriority = 200;
+const char kSyncServiceSpecificData[] = "sync-ping-p2p";
+
+} // namespace browser_sync
+
diff --git a/chrome/browser/sync/sync_constants.h b/chrome/browser/sync/sync_constants.h
new file mode 100644
index 0000000..efca382
--- /dev/null
+++ b/chrome/browser/sync/sync_constants.h
@@ -0,0 +1,20 @@
+// 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.
+
+#ifndef CHROME_BROWSER_SYNC_SYNC_CONSTANTS_H_
+#define CHROME_BROWSER_SYNC_SYNC_CONSTANTS_H_
+
+namespace browser_sync {
+
+extern const char kSyncLegacyServiceUrl[];
+extern const char kSyncServiceUrl[];
+extern const char kSyncLegacyServiceId[];
+extern const char kSyncServiceId[];
+extern const int kSyncPriority;
+extern const char kSyncServiceSpecificData[];
+
+} // namespace browser_sync
+
+#endif // CHROME_BROWSER_SYNC_SYNC_CONSTANTS_H_
+
diff --git a/chrome/browser/sync/tools/sync_listen_notifications.cc b/chrome/browser/sync/tools/sync_listen_notifications.cc
index cb5540e..dea8471 100644
--- a/chrome/browser/sync/tools/sync_listen_notifications.cc
+++ b/chrome/browser/sync/tools/sync_listen_notifications.cc
@@ -11,6 +11,7 @@
#include "base/message_loop.h"
#include "base/platform_thread.h"
#include "chrome/browser/sync/notification_method.h"
+#include "chrome/browser/sync/sync_constants.h"
#include "chrome/browser/sync/notifier/base/task_pump.h"
#include "chrome/browser/sync/notifier/communicator/xmpp_socket_adapter.h"
#include "chrome/browser/sync/notifier/listener/listen_task.h"
@@ -87,20 +88,21 @@ class XmppNotificationClient : public sigslot::has_slots<> {
browser_sync::NotificationMethod notification_method =
browser_sync::NOTIFICATION_TRANSITIONAL;
std::vector<std::string> subscribed_services_list;
- if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) {
- subscribed_services_list.push_back(
- browser_sync::kSyncLegacyServiceUrl);
+ if (notification_method != browser_sync::NOTIFICATION_LEGACY) {
+ if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) {
+ subscribed_services_list.push_back(
+ browser_sync::kSyncLegacyServiceUrl);
+ }
+ subscribed_services_list.push_back(browser_sync::kSyncServiceUrl);
}
- subscribed_services_list.push_back(browser_sync::kSyncServiceUrl);
// Owned by task_pump_.
browser_sync::SubscribeTask* subscribe_task =
- new browser_sync::SubscribeTask(
- xmpp_client_, notification_method, subscribed_services_list);
+ new browser_sync::SubscribeTask(xmpp_client_,
+ subscribed_services_list);
subscribe_task->Start();
// Owned by task_pump_.
browser_sync::ListenTask* listen_task =
- new browser_sync::ListenTask(
- xmpp_client_, notification_method);
+ new browser_sync::ListenTask(xmpp_client_);
listen_task->Start();
break;
}
diff --git a/chrome/browser/sync/tools/sync_tools.gyp b/chrome/browser/sync/tools/sync_tools.gyp
index 6759248..33111f5 100644
--- a/chrome/browser/sync/tools/sync_tools.gyp
+++ b/chrome/browser/sync/tools/sync_tools.gyp
@@ -13,6 +13,11 @@
'type': 'executable',
'sources': [
'sync_listen_notifications.cc',
+ # We are directly including the sync_constants.cc and h files to avoid
+ # pulling in browser.lib.
+ # TODO(akalin): Fix this.
+ '<(DEPTH)/chrome/browser/sync/sync_constants.cc',
+ '<(DEPTH)/chrome/browser/sync/sync_constants.h',
],
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 2f7fdba..8e636d3 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2052,6 +2052,8 @@
'browser/sync/profile_sync_factory.h',
'browser/sync/profile_sync_factory_impl.cc',
'browser/sync/profile_sync_factory_impl.h',
+ 'browser/sync/sync_constants.cc',
+ 'browser/sync/sync_constants.h',
'browser/sync/sync_setup_flow.cc',
'browser/sync/sync_setup_flow.h',
'browser/sync/sync_setup_wizard.cc',