diff options
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host.cc | 62 | ||||
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host.h | 2 | ||||
-rw-r--r-- | chrome/browser/sync/notifier/sync_notifier_factory.cc | 89 | ||||
-rw-r--r-- | chrome/browser/sync/notifier/sync_notifier_factory.h | 17 | ||||
-rw-r--r-- | chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc | 32 | ||||
-rw-r--r-- | chrome/browser/sync/test/integration/sync_test.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/tools/sync_listen_notifications.cc | 79 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 2 |
9 files changed, 155 insertions, 137 deletions
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index 4328cbf..0525d2f 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -42,6 +42,10 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" #include "content/public/common/content_client.h" +#include "jingle/notifier/base/notification_method.h" +#include "jingle/notifier/base/notifier_options.h" +#include "net/base/host_port_pair.h" +#include "net/url_request/url_request_context_getter.h" static const int kSaveChangesIntervalSeconds = 10; static const FilePath::CharType kSyncDataFolderName[] = @@ -226,6 +230,52 @@ class SyncBackendHost::Core DISALLOW_COPY_AND_ASSIGN(Core); }; +namespace { + +// Parses the given command line for notifier options. +notifier::NotifierOptions ParseNotifierOptions( + const CommandLine& command_line, + const scoped_refptr<net::URLRequestContextGetter>& + request_context_getter) { + notifier::NotifierOptions notifier_options; + notifier_options.request_context_getter = request_context_getter; + + if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { + notifier_options.xmpp_host_port = + net::HostPortPair::FromString( + command_line.GetSwitchValueASCII( + switches::kSyncNotificationHostPort)); + DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() + << " for test sync notification server."; + } + + notifier_options.try_ssltcp_first = + command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); + DVLOG_IF(1, notifier_options.try_ssltcp_first) + << "Trying SSL/TCP port before XMPP port for notifications."; + + notifier_options.invalidate_xmpp_login = + command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); + DVLOG_IF(1, notifier_options.invalidate_xmpp_login) + << "Invalidating sync XMPP login."; + + notifier_options.allow_insecure_connection = + command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); + DVLOG_IF(1, notifier_options.allow_insecure_connection) + << "Allowing insecure XMPP connections."; + + if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { + const std::string notification_method_str( + command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); + notifier_options.notification_method = + notifier::StringToNotificationMethod(notification_method_str); + } + + return notifier_options; +} + +} // namespace + SyncBackendHost::SyncBackendHost(const std::string& name, Profile* profile, const base::WeakPtr<SyncPrefs>& sync_prefs) @@ -240,10 +290,10 @@ SyncBackendHost::SyncBackendHost(const std::string& name, sync_prefs_(sync_prefs), chrome_sync_notification_bridge_(profile_), sync_notifier_factory_( + ParseNotifierOptions(*CommandLine::ForCurrentProcess(), + profile_->GetRequestContext()), content::GetUserAgent(GURL()), - profile_->GetRequestContext(), - sync_prefs, - *CommandLine::ForCurrentProcess()), + sync_prefs), frontend_(NULL), last_auth_error_(AuthError::None()) { } @@ -257,10 +307,10 @@ SyncBackendHost::SyncBackendHost(Profile* profile) initialization_state_(NOT_ATTEMPTED), chrome_sync_notification_bridge_(profile_), sync_notifier_factory_( + ParseNotifierOptions(*CommandLine::ForCurrentProcess(), + profile_->GetRequestContext()), content::GetUserAgent(GURL()), - NULL, - base::WeakPtr<sync_notifier::InvalidationVersionTracker>(), - *CommandLine::ForCurrentProcess()), + base::WeakPtr<sync_notifier::InvalidationVersionTracker>()), frontend_(NULL), last_auth_error_(AuthError::None()) { } diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index 66f8a5d..4d78deb 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -8,6 +8,7 @@ #include <string> +#include "base/basictypes.h" #include "base/callback.h" #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" @@ -29,7 +30,6 @@ #include "chrome/browser/sync/util/weak_handle.h" #include "chrome/common/net/gaia/google_service_auth_error.h" #include "googleurl/src/gurl.h" -#include "net/url_request/url_request_context_getter.h" class MessageLoop; class Profile; diff --git a/chrome/browser/sync/notifier/sync_notifier_factory.cc b/chrome/browser/sync/notifier/sync_notifier_factory.cc index c5bf289..53671b2 100644 --- a/chrome/browser/sync/notifier/sync_notifier_factory.cc +++ b/chrome/browser/sync/notifier/sync_notifier_factory.cc @@ -6,93 +6,22 @@ #include <string> -#include "base/command_line.h" #include "base/logging.h" -#include "base/string_number_conversions.h" -#include "base/string_util.h" #include "chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h" #include "chrome/browser/sync/notifier/p2p_notifier.h" #include "chrome/browser/sync/notifier/sync_notifier.h" -#include "chrome/common/chrome_switches.h" -#include "jingle/notifier/base/const_communicator.h" -#include "jingle/notifier/base/notifier_options.h" #include "jingle/notifier/listener/mediator_thread_impl.h" #include "jingle/notifier/listener/talk_mediator_impl.h" -#include "net/base/host_port_pair.h" namespace sync_notifier { namespace { -// TODO(akalin): Figure out whether this should be a method of -// HostPortPair. -net::HostPortPair StringToHostPortPair(const std::string& host_port_str, - uint16 default_port) { - std::string::size_type colon_index = host_port_str.find(':'); - if (colon_index == std::string::npos) { - return net::HostPortPair(host_port_str, default_port); - } - - std::string host = host_port_str.substr(0, colon_index); - std::string port_str = host_port_str.substr(colon_index + 1); - int port = default_port; - if (!base::StringToInt(port_str, &port) || - (port <= 0) || (port > kuint16max)) { - LOG(WARNING) << "Could not parse valid port from " << port_str - << "; using port " << default_port; - return net::HostPortPair(host, default_port); - } - - return net::HostPortPair(host, port); -} - SyncNotifier* CreateDefaultSyncNotifier( - const CommandLine& command_line, - const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, + const notifier::NotifierOptions& notifier_options, const InvalidationVersionMap& initial_max_invalidation_versions, const browser_sync::WeakHandle<InvalidationVersionTracker>& invalidation_version_tracker, const std::string& client_info) { - // Contains options specific to how sync clients send and listen to - // jingle notifications. - notifier::NotifierOptions notifier_options; - notifier_options.request_context_getter = request_context_getter; - - // Override the notification server host from the command-line, if provided. - if (command_line.HasSwitch(switches::kSyncNotificationHost)) { - std::string value(command_line.GetSwitchValueASCII( - switches::kSyncNotificationHost)); - if (!value.empty()) { - notifier_options.xmpp_host_port = - StringToHostPortPair(value, notifier::kDefaultXmppPort); - } - DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() - << " for test sync notification server."; - } - - notifier_options.try_ssltcp_first = - command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); - if (notifier_options.try_ssltcp_first) - DVLOG(1) << "Trying SSL/TCP port before XMPP port for notifications."; - - notifier_options.invalidate_xmpp_login = - command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); - if (notifier_options.invalidate_xmpp_login) { - DVLOG(1) << "Invalidating sync XMPP login."; - } - - notifier_options.allow_insecure_connection = - command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); - if (notifier_options.allow_insecure_connection) { - DVLOG(1) << "Allowing insecure XMPP connections."; - } - - if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { - const std::string notification_method_str( - command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); - notifier_options.notification_method = - notifier::StringToNotificationMethod(notification_method_str); - } - if (notifier_options.notification_method == notifier::NOTIFICATION_P2P) { notifier::TalkMediator* const talk_mediator = new notifier::TalkMediatorImpl( @@ -115,28 +44,24 @@ SyncNotifier* CreateDefaultSyncNotifier( } // namespace SyncNotifierFactory::SyncNotifierFactory( + const notifier::NotifierOptions& notifier_options, const std::string& client_info, - const scoped_refptr<net::URLRequestContextGetter>& - request_context_getter, const base::WeakPtr<InvalidationVersionTracker>& - invalidation_version_tracker, - const CommandLine& command_line) - : client_info_(client_info), - request_context_getter_(request_context_getter), + invalidation_version_tracker) + : notifier_options_(notifier_options), + client_info_(client_info), initial_max_invalidation_versions_( invalidation_version_tracker.get() ? invalidation_version_tracker->GetAllMaxVersions() : InvalidationVersionMap()), - invalidation_version_tracker_(invalidation_version_tracker), - command_line_(command_line) { + invalidation_version_tracker_(invalidation_version_tracker) { } SyncNotifierFactory::~SyncNotifierFactory() { } SyncNotifier* SyncNotifierFactory::CreateSyncNotifier() { - return CreateDefaultSyncNotifier(command_line_, - request_context_getter_, + return CreateDefaultSyncNotifier(notifier_options_, initial_max_invalidation_versions_, invalidation_version_tracker_, client_info_); diff --git a/chrome/browser/sync/notifier/sync_notifier_factory.h b/chrome/browser/sync/notifier/sync_notifier_factory.h index 96c825d..d763d1a 100644 --- a/chrome/browser/sync/notifier/sync_notifier_factory.h +++ b/chrome/browser/sync/notifier/sync_notifier_factory.h @@ -7,16 +7,10 @@ #include <string> -#include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/sync/notifier/invalidation_version_tracker.h" #include "chrome/browser/sync/util/weak_handle.h" - -class CommandLine; - -namespace net { -class URLRequestContextGetter; -} +#include "jingle/notifier/base/notifier_options.h" namespace sync_notifier { @@ -30,12 +24,10 @@ class SyncNotifierFactory { // agent string. |invalidation_version_tracker| may be NULL (for // tests). SyncNotifierFactory( + const notifier::NotifierOptions& notifier_options, const std::string& client_info, - const scoped_refptr<net::URLRequestContextGetter>& - request_context_getter, const base::WeakPtr<InvalidationVersionTracker>& - invalidation_version_tracker, - const CommandLine& command_line); + invalidation_version_tracker); ~SyncNotifierFactory(); // Creates a sync notifier. Caller takes ownership of the returned @@ -44,12 +36,11 @@ class SyncNotifierFactory { SyncNotifier* CreateSyncNotifier(); private: + const notifier::NotifierOptions notifier_options_; const std::string client_info_; - const scoped_refptr<net::URLRequestContextGetter> request_context_getter_; const InvalidationVersionMap initial_max_invalidation_versions_; const browser_sync::WeakHandle<InvalidationVersionTracker> invalidation_version_tracker_; - const CommandLine& command_line_; }; } // namespace sync_notifier diff --git a/chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc b/chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc index 3ed1ccc..516b389 100644 --- a/chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc +++ b/chrome/browser/sync/notifier/sync_notifier_factory_unittest.cc @@ -16,7 +16,8 @@ #include "chrome/browser/sync/notifier/sync_notifier.h" #include "chrome/browser/sync/syncable/model_type.h" #include "chrome/browser/sync/syncable/model_type_payload_map.h" -#include "chrome/common/chrome_switches.h" +#include "jingle/notifier/base/notification_method.h" +#include "jingle/notifier/base/notifier_options.h" #include "net/url_request/url_request_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -30,34 +31,31 @@ using ::testing::StrictMock; class SyncNotifierFactoryTest : public testing::Test { protected: - SyncNotifierFactoryTest() - : command_line_(CommandLine::NO_PROGRAM) {} - virtual ~SyncNotifierFactoryTest() {} virtual void SetUp() OVERRIDE { - factory_.reset(new SyncNotifierFactory( - "fake_client_info", - new TestURLRequestContextGetter(message_loop_.message_loop_proxy()), - base::WeakPtr<sync_notifier::InvalidationVersionTracker>(), - command_line_)); - message_loop_.RunAllPending(); + notifier_options_.request_context_getter = + new TestURLRequestContextGetter(message_loop_.message_loop_proxy()); } virtual void TearDown() OVERRIDE { Mock::VerifyAndClearExpectations(&mock_observer_); message_loop_.RunAllPending(); - command_line_ = CommandLine(CommandLine::NO_PROGRAM); } MessageLoop message_loop_; StrictMock<MockSyncNotifierObserver> mock_observer_; + notifier::NotifierOptions notifier_options_; scoped_ptr<SyncNotifierFactory> factory_; - CommandLine command_line_; }; // Test basic creation of a NonBlockingInvalidationNotifier. TEST_F(SyncNotifierFactoryTest, Basic) { - scoped_ptr<SyncNotifier> notifier(factory_->CreateSyncNotifier()); + notifier_options_.notification_method = notifier::NOTIFICATION_SERVER; + SyncNotifierFactory factory( + notifier_options_, + "test client info", + base::WeakPtr<sync_notifier::InvalidationVersionTracker>()); + scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); ASSERT_TRUE(notifier.get()); notifier->AddObserver(&mock_observer_); notifier->RemoveObserver(&mock_observer_); @@ -65,8 +63,12 @@ TEST_F(SyncNotifierFactoryTest, Basic) { // Test basic creation of a P2PNotifier. TEST_F(SyncNotifierFactoryTest, Basic_P2P) { - command_line_.AppendSwitchASCII(switches::kSyncNotificationMethod, "p2p"); - scoped_ptr<SyncNotifier> notifier(factory_->CreateSyncNotifier()); + notifier_options_.notification_method = notifier::NOTIFICATION_P2P; + SyncNotifierFactory factory( + notifier_options_, + "test client info", + base::WeakPtr<sync_notifier::InvalidationVersionTracker>()); + scoped_ptr<SyncNotifier> notifier(factory.CreateSyncNotifier()); ASSERT_TRUE(notifier.get()); notifier->AddObserver(&mock_observer_); notifier->RemoveObserver(&mock_observer_); diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index 9855ecc..1499e3a 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -475,8 +475,8 @@ bool SyncTest::SetUpLocalPythonTestServer() { xmpp_host_port_pair.set_port(xmpp_port); xmpp_port_.reset(new net::ScopedPortException(xmpp_port)); - if (!cl->HasSwitch(switches::kSyncNotificationHost)) { - cl->AppendSwitchASCII(switches::kSyncNotificationHost, + if (!cl->HasSwitch(switches::kSyncNotificationHostPort)) { + cl->AppendSwitchASCII(switches::kSyncNotificationHostPort, xmpp_host_port_pair.ToString()); // The local XMPP server only supports insecure connections. cl->AppendSwitch(switches::kSyncAllowInsecureXmppConnection); diff --git a/chrome/browser/sync/tools/sync_listen_notifications.cc b/chrome/browser/sync/tools/sync_listen_notifications.cc index 6a37692..c42352eb 100644 --- a/chrome/browser/sync/tools/sync_listen_notifications.cc +++ b/chrome/browser/sync/tools/sync_listen_notifications.cc @@ -21,6 +21,9 @@ #include "chrome/browser/sync/notifier/sync_notifier_observer.h" #include "chrome/browser/sync/syncable/model_type.h" #include "chrome/browser/sync/syncable/model_type_payload_map.h" +#include "jingle/notifier/base/notification_method.h" +#include "jingle/notifier/base/notifier_options.h" +#include "net/base/host_port_pair.h" #include "net/url_request/url_request_test_util.h" // This is a simple utility that initializes a sync notifier and @@ -77,12 +80,53 @@ class NullInvalidationVersionTracker virtual void SetMaxVersion( syncable::ModelType model_type, int64 max_invalidation_version) OVERRIDE { - DVLOG(1) << "Setting max invalidation version for " - << syncable::ModelTypeToString(model_type) << " to " - << max_invalidation_version; + LOG(INFO) << "Setting max invalidation version for " + << syncable::ModelTypeToString(model_type) << " to " + << max_invalidation_version; } }; +const char kEmailSwitch[] = "email"; +const char kTokenSwitch[] = "token"; +const char kHostPortSwitch[] = "host-port"; +const char kTrySslTcpFirstSwitch[] = "try-ssltcp-first"; +const char kAllowInsecureConnectionSwitch[] = "allow-insecure-connection"; +const char kNotificationMethodSwitch[] = "notification-method"; + +notifier::NotifierOptions ParseNotifierOptions( + const CommandLine& command_line, + const scoped_refptr<net::URLRequestContextGetter>& + request_context_getter) { + notifier::NotifierOptions notifier_options; + notifier_options.request_context_getter = request_context_getter; + + if (command_line.HasSwitch(kHostPortSwitch)) { + notifier_options.xmpp_host_port = + net::HostPortPair::FromString( + command_line.GetSwitchValueASCII(kHostPortSwitch)); + LOG(INFO) << "Using " << notifier_options.xmpp_host_port.ToString() + << " for test sync notification server."; + } + + notifier_options.try_ssltcp_first = + command_line.HasSwitch(kTrySslTcpFirstSwitch); + LOG_IF(INFO, notifier_options.try_ssltcp_first) + << "Trying SSL/TCP port before XMPP port for notifications."; + + notifier_options.allow_insecure_connection = + command_line.HasSwitch(kAllowInsecureConnectionSwitch); + LOG_IF(INFO, notifier_options.allow_insecure_connection) + << "Allowing insecure XMPP connections."; + + if (command_line.HasSwitch(kNotificationMethodSwitch)) { + notifier_options.notification_method = + notifier::StringToNotificationMethod( + command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); + } + + return notifier_options; +} + } // namespace int main(int argc, char* argv[]) { @@ -103,27 +147,34 @@ int main(int argc, char* argv[]) { // Parse command line. const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - std::string email = command_line.GetSwitchValueASCII("email"); - std::string token = command_line.GetSwitchValueASCII("token"); + std::string email = command_line.GetSwitchValueASCII(kEmailSwitch); + std::string token = command_line.GetSwitchValueASCII(kTokenSwitch); // TODO(akalin): Write a wrapper script that gets a token for an // email and password and passes that in to this utility. if (email.empty() || token.empty()) { - std::printf("Usage: %s --email=foo@bar.com --token=token\n\n" - "See sync_notifier_factory.cc for more switches.\n\n" - "Run chrome and set a breakpoint on " + std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" + "[--%s=host:port] [--%s] [--%s]\n" + "[--%s=(server|p2p)]\n\n" + "Run chrome and set a breakpoint on\n" "sync_api::SyncManager::SyncInternal::UpdateCredentials() " - "after logging into sync to get the token to pass into this " - "utility.\n", - argv[0]); + "after logging into\n" + "sync to get the token to pass into this utility.\n", + argv[0], + kTokenSwitch, kEmailSwitch, kHostPortSwitch, + kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch, + kNotificationMethodSwitch); return -1; } + const notifier::NotifierOptions& notifier_options = + ParseNotifierOptions( + command_line, + new TestURLRequestContextGetter(io_thread.message_loop_proxy())); const char kClientInfo[] = "sync_listen_notifications"; NullInvalidationVersionTracker null_invalidation_version_tracker; sync_notifier::SyncNotifierFactory sync_notifier_factory( - kClientInfo, - new TestURLRequestContextGetter(io_thread.message_loop_proxy()), - null_invalidation_version_tracker.AsWeakPtr(), command_line); + notifier_options, kClientInfo, + null_invalidation_version_tracker.AsWeakPtr()); scoped_ptr<sync_notifier::SyncNotifier> sync_notifier( sync_notifier_factory.CreateSyncNotifier()); NotificationPrinter notification_printer; diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index e81ab78..77ea4fb 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1094,9 +1094,8 @@ const char kSyncInvalidateXmppLogin[] = "sync-invalidate-xmpp-login"; // Overrides the default notification method for sync. const char kSyncNotificationMethod[] = "sync-notification-method"; -// Overrides the default host used for sync notifications. Can be either "host" -// or "host:port". -const char kSyncNotificationHost[] = "sync-notification-host"; +// Overrides the default host:port used for sync notifications. +const char kSyncNotificationHostPort[] = "sync-notification-host-port"; // Specifies the sync promo version to display. const char kSyncPromoVersion[] = "sync-promo-version"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 6ade667..a221d2f 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -295,7 +295,7 @@ extern const char kStartMaximized[]; extern const char kSyncAllowInsecureXmppConnection[]; extern const char kSyncInvalidateXmppLogin[]; extern const char kSyncNotificationMethod[]; -extern const char kSyncNotificationHost[]; +extern const char kSyncNotificationHostPort[]; extern const char kSyncPromoVersion[]; extern const char kSyncServiceURL[]; extern const char kSyncThrowUnrecoverableError[]; |