diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 00:57:31 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 00:57:31 +0000 |
commit | f32b5060275141e4b5c6b1e8a97a901353d27a8f (patch) | |
tree | b16135ff727ddd459bc2e1d1d261791afaa46fba /chrome/browser/sync/tools | |
parent | 35e987b872115dadef192071b7087ed6f3af8563 (diff) | |
download | chromium_src-f32b5060275141e4b5c6b1e8a97a901353d27a8f.zip chromium_src-f32b5060275141e4b5c6b1e8a97a901353d27a8f.tar.gz chromium_src-f32b5060275141e4b5c6b1e8a97a901353d27a8f.tar.bz2 |
[Sync] Some cleanup of sync_listen_notifications tool
Removed sync_listen_notification-only switches from chrome_switches.{h,cc}.
Renamed "cache invalidation" to "server notifier".
Made the server notifier be the default notifier.
Added option to send an initial notification for the legacy notifier
(helpful when debugging the python XMPP server).
BUG=None
TEST=Manually
Review URL: http://codereview.chromium.org/3826006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/tools')
-rw-r--r-- | chrome/browser/sync/tools/sync_listen_notifications.cc | 103 |
1 files changed, 64 insertions, 39 deletions
diff --git a/chrome/browser/sync/tools/sync_listen_notifications.cc b/chrome/browser/sync/tools/sync_listen_notifications.cc index c619e14..2431098 100644 --- a/chrome/browser/sync/tools/sync_listen_notifications.cc +++ b/chrome/browser/sync/tools/sync_listen_notifications.cc @@ -18,17 +18,19 @@ #include "chrome/browser/sync/notifier/chrome_invalidation_client.h" #include "chrome/browser/sync/notifier/chrome_system_resources.h" #include "chrome/browser/sync/sync_constants.h" -#include "chrome/common/chrome_switches.h" #include "jingle/notifier/base/notification_method.h" #include "jingle/notifier/base/xmpp_connection.h" #include "jingle/notifier/listener/listen_task.h" #include "jingle/notifier/listener/notification_constants.h" +#include "jingle/notifier/listener/notification_defines.h" +#include "jingle/notifier/listener/send_update_task.h" #include "jingle/notifier/listener/subscribe_task.h" #include "jingle/notifier/listener/xml_element_util.h" #include "net/base/ssl_config_service.h" #include "net/socket/client_socket_factory.h" #include "talk/base/cryptstring.h" #include "talk/base/logging.h" +#include "talk/base/sigslot.h" #include "talk/base/task.h" #include "talk/xmpp/jid.h" #include "talk/xmpp/xmppclientsettings.h" @@ -98,8 +100,13 @@ class XmppNotificationClient : public notifier::XmppConnection::Delegate { }; // Delegate for legacy notifications. -class LegacyNotifierDelegate : public XmppNotificationClient::Observer { +class LegacyNotifierDelegate + : public XmppNotificationClient::Observer, + public sigslot::has_slots<> { public: + explicit LegacyNotifierDelegate(bool send_initial_update) + : send_initial_update_(send_initial_update) {} + virtual ~LegacyNotifierDelegate() {} virtual void OnConnect(base::WeakPtr<talk_base::Task> base_task) { @@ -121,10 +128,29 @@ class LegacyNotifierDelegate : public XmppNotificationClient::Observer { // Owned by xmpp_client. notifier::ListenTask* listen_task = new notifier::ListenTask(base_task); + listen_task->SignalUpdateAvailable.connect( + this, &LegacyNotifierDelegate::OnUpdateAvailable); listen_task->Start(); + if (send_initial_update_) { + // Owned by xmpp_client. + notifier::SendUpdateTask* send_update_task = + new notifier::SendUpdateTask(base_task, + OutgoingNotificationData()); + send_update_task->Start(); + } } virtual void OnError() {} + + void OnUpdateAvailable( + const IncomingNotificationData& notification_data) { + LOG(INFO) << "Notification received: " + << notification_data.service_url << " " + << notification_data.service_specific_data; + } + + private: + bool send_initial_update_; }; // The actual listener for sync notifications. @@ -156,23 +182,23 @@ class ChromeInvalidationListener DISALLOW_COPY_AND_ASSIGN(ChromeInvalidationListener); }; -// Delegate for server-side notifications. -class CacheInvalidationNotifierDelegate +// Delegate for server-issued notifications. +class ServerNotifierDelegate : public XmppNotificationClient::Observer, public sync_notifier::StateWriter { public: - explicit CacheInvalidationNotifierDelegate( - const std::string& cache_invalidation_state) - : cache_invalidation_state_(cache_invalidation_state) {} + explicit ServerNotifierDelegate( + const std::string& server_notifier_state) + : server_notifier_state_(server_notifier_state) {} - virtual ~CacheInvalidationNotifierDelegate() {} + virtual ~ServerNotifierDelegate() {} virtual void OnConnect(base::WeakPtr<talk_base::Task> base_task) { LOG(INFO) << "Logged in"; // TODO(akalin): app_name should be per-client unique. const std::string kAppName = "cc_sync_listen_notifications"; - chrome_invalidation_client_.Start(kAppName, cache_invalidation_state_, + chrome_invalidation_client_.Start(kAppName, server_notifier_state_, &chrome_invalidation_listener_, this, base_task); chrome_invalidation_client_.RegisterTypes(); @@ -193,7 +219,7 @@ class CacheInvalidationNotifierDelegate // Opaque blob capturing the notifications state of a previous run // (i.e., the base64-decoded value of a string output by // WriteState()). - std::string cache_invalidation_state_; + std::string server_notifier_state_; sync_notifier::ChromeInvalidationClient chrome_invalidation_client_; }; @@ -211,24 +237,22 @@ int main(int argc, char* argv[]) { // Parse command line. const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - std::string email = command_line.GetSwitchValueASCII(switches::kSyncEmail); + std::string email = command_line.GetSwitchValueASCII("email"); if (email.empty()) { printf("Usage: %s --email=foo@bar.com [--password=mypassword] " "[--server=talk.google.com] [--port=5222] [--allow-plain] " - "[--disable-tls] [--use-cache-invalidation] [--use-ssl-tcp] " - "[--cache-invalidtion-state]\n", + "[--disable-tls] [--use-ssl-tcp] [--server-notifier-state] " + "[--use-legacy-notifier] " + "[--legacy-notifier-send-initial-update]\n", argv[0]); return -1; } - std::string password = - command_line.GetSwitchValueASCII(switches::kSyncPassword); - std::string server = - command_line.GetSwitchValueASCII(switches::kSyncServer); + std::string password = command_line.GetSwitchValueASCII("password"); + std::string server = command_line.GetSwitchValueASCII("server"); if (server.empty()) { server = "talk.google.com"; } - std::string port_str = - command_line.GetSwitchValueASCII(switches::kSyncPort); + std::string port_str = command_line.GetSwitchValueASCII("port"); int port = 5222; if (!port_str.empty()) { int port_from_port_str = std::strtol(port_str.c_str(), NULL, 10); @@ -238,22 +262,25 @@ int main(int argc, char* argv[]) { port = port_from_port_str; } } - bool allow_plain = command_line.HasSwitch(switches::kSyncAllowPlain); - bool disable_tls = command_line.HasSwitch(switches::kSyncDisableTls); - bool use_ssl_tcp = command_line.HasSwitch(switches::kSyncUseSslTcp); + bool allow_plain = command_line.HasSwitch("allow-plain"); + bool disable_tls = command_line.HasSwitch("disable-tls"); + bool use_ssl_tcp = command_line.HasSwitch("use-ssl-tcp"); if (use_ssl_tcp && (port != 443)) { - LOG(WARNING) << switches::kSyncUseSslTcp << " is set but port is " << port + LOG(WARNING) << "--use-ssl-tcp is set but port is " << port << " instead of 443"; } - std::string cache_invalidation_state; - std::string cache_invalidation_state_encoded = - command_line.GetSwitchValueASCII("cache-invalidation-state"); - if (!cache_invalidation_state_encoded.empty() && - !base::Base64Decode(cache_invalidation_state_encoded, - &cache_invalidation_state)) { + std::string server_notifier_state; + std::string server_notifier_state_encoded = + command_line.GetSwitchValueASCII("server-notifier-state"); + if (!server_notifier_state_encoded.empty() && + !base::Base64Decode(server_notifier_state_encoded, + &server_notifier_state)) { LOG(ERROR) << "Could not decode state: " - << cache_invalidation_state_encoded; + << server_notifier_state_encoded; } + bool use_legacy_notifier = command_line.HasSwitch("use-legacy-notifier"); + bool legacy_notifier_send_initial_update = + command_line.HasSwitch("legacy-notifier-send-initial-update"); // Build XMPP client settings. buzz::XmppClientSettings xmpp_client_settings; @@ -280,18 +307,16 @@ int main(int argc, char* argv[]) { MessageLoopForIO message_loop; // Connect and listen. - LegacyNotifierDelegate legacy_notifier_delegate; - CacheInvalidationNotifierDelegate cache_invalidation_notifier_delegate( - cache_invalidation_state); + ServerNotifierDelegate server_notifier_delegate( + server_notifier_state); + LegacyNotifierDelegate legacy_notifier_delegate( + legacy_notifier_send_initial_update); std::vector<XmppNotificationClient::Observer*> observers; - // TODO(akalin): Add switch to listen to both. - if (command_line.HasSwitch(switches::kSyncUseCacheInvalidation)) { - observers.push_back(&cache_invalidation_notifier_delegate); - } else { + if (use_legacy_notifier) { observers.push_back(&legacy_notifier_delegate); + } else { + observers.push_back(&server_notifier_delegate); } - // TODO(akalin): Revert the move of all switches in this file into - // chrome_switches.h. XmppNotificationClient xmpp_notification_client( observers.begin(), observers.end()); xmpp_notification_client.Run(xmpp_client_settings); |