diff options
author | Ben Murdoch <benm@google.com> | 2010-11-18 18:32:45 +0000 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-11-18 18:38:07 +0000 |
commit | 513209b27ff55e2841eac0e4120199c23acce758 (patch) | |
tree | aeba30bb08c5f47c57003544e378a377c297eee6 /chrome/browser/sync/tools | |
parent | 164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff) | |
download | external_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2 |
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'chrome/browser/sync/tools')
-rw-r--r-- | chrome/browser/sync/tools/sync_listen_notifications.cc | 114 |
1 files changed, 65 insertions, 49 deletions
diff --git a/chrome/browser/sync/tools/sync_listen_notifications.cc b/chrome/browser/sync/tools/sync_listen_notifications.cc index c619e14..0b20db1 100644 --- a/chrome/browser/sync/tools/sync_listen_notifications.cc +++ b/chrome/browser/sync/tools/sync_listen_notifications.cc @@ -18,17 +18,18 @@ #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,22 +99,19 @@ 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) { LOG(INFO) << "Logged in"; - notifier::NotificationMethod notification_method = - notifier::NOTIFICATION_TRANSITIONAL; std::vector<std::string> subscribed_services_list; - if (notification_method != notifier::NOTIFICATION_LEGACY) { - if (notification_method == notifier::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 base_task. notifier::SubscribeTask* subscribe_task = new notifier::SubscribeTask(base_task, subscribed_services_list); @@ -121,10 +119,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 +173,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 +210,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 +228,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 +253,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 +298,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); |