Commit ecbf38d5 authored by Tanja Gornak's avatar Tanja Gornak Committed by Commit Bot

Ditch components/sync/tools/sync_listen_notifications.

sync_listen_notifications istn't used neither in production code,
nor in tests. Hence removing.

Bug: 880056, 801985
Change-Id: If518c9dad72b3f718ee649844a6cf3a4703bc0c7
Reviewed-on: https://chromium-review.googlesource.com/c/1307434
Commit-Queue: Tatiana Gornak <melandory@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607209}
parent af2a90f5
......@@ -105,7 +105,6 @@ group("gn_all") {
"//chrome/test:sync_integration_tests",
"//chrome/test/chromedriver:chromedriver_unittests",
"//components/subresource_filter/tools:subresource_filter_tools",
"//components/sync/tools:sync_listen_notifications",
"//components/zucchini:zucchini",
"//components/zucchini:zucchini_unittests",
"//gpu/gles2_conform_support:gles2_conform_test",
......
# Copyright 2014 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.
import("//testing/test.gni")
source_set("common") {
testonly = true
sources = [
"null_invalidation_state_tracker.cc",
"null_invalidation_state_tracker.h",
]
deps = [
"//base",
"//components/invalidation/impl",
"//components/sync",
]
}
test("sync_listen_notifications") {
sources = [
"sync_listen_notifications.cc",
]
defines = [ "SYNC_TEST" ]
deps = [
":common",
"//base",
"//components/invalidation/impl",
"//components/sync",
"//components/sync:test_support_engine",
"//jingle:notifier",
"//net:test_support",
]
}
include_rules = [
"+components/invalidation",
"+components/sync/base",
"+components/sync/driver",
"+components/sync/engine",
"+components/sync/syncable",
"+components/sync/js",
"+google/cacheinvalidation",
"+jingle/notifier/base",
"+net",
"+services/network",
]
// Copyright (c) 2012 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 "components/sync/tools/null_invalidation_state_tracker.h"
#include "base/base64.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/task_runner.h"
#include "components/invalidation/public/invalidation_util.h"
namespace syncer {
NullInvalidationStateTracker::NullInvalidationStateTracker() {}
NullInvalidationStateTracker::~NullInvalidationStateTracker() {}
void NullInvalidationStateTracker::ClearAndSetNewClientId(
const std::string& data) {
LOG(INFO) << "Setting invalidator client ID to: " << data;
}
std::string NullInvalidationStateTracker::GetInvalidatorClientId() const {
// The caller of this function is probably looking for an ID it can use to
// identify this client as the originator of some notifiable change. It does
// this so the invalidation server can prevent it from being notified of its
// own changes. This invalidation state tracker doesn't remember its ID, so
// it can't support this feature.
NOTREACHED() << "This state tracker does not support reflection-blocking";
return std::string();
}
std::string NullInvalidationStateTracker::GetBootstrapData() const {
return std::string();
}
void NullInvalidationStateTracker::SetBootstrapData(const std::string& data) {
std::string base64_data;
base::Base64Encode(data, &base64_data);
LOG(INFO) << "Setting bootstrap data to: " << base64_data;
}
void NullInvalidationStateTracker::Clear() {
// We have no members to clear.
}
void NullInvalidationStateTracker::SetSavedInvalidations(
const UnackedInvalidationsMap& states) {
// Do nothing.
}
UnackedInvalidationsMap NullInvalidationStateTracker::GetSavedInvalidations()
const {
return UnackedInvalidationsMap();
}
} // namespace syncer
// Copyright (c) 2012 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 COMPONENTS_SYNC_TOOLS_NULL_INVALIDATION_STATE_TRACKER_H_
#define COMPONENTS_SYNC_TOOLS_NULL_INVALIDATION_STATE_TRACKER_H_
#include <string>
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "components/invalidation/impl/invalidation_state_tracker.h"
namespace syncer {
class NullInvalidationStateTracker
: public base::SupportsWeakPtr<NullInvalidationStateTracker>,
public InvalidationStateTracker {
public:
NullInvalidationStateTracker();
~NullInvalidationStateTracker() override;
void ClearAndSetNewClientId(const std::string& data) override;
std::string GetInvalidatorClientId() const override;
std::string GetBootstrapData() const override;
void SetBootstrapData(const std::string& data) override;
void SetSavedInvalidations(const UnackedInvalidationsMap& states) override;
UnackedInvalidationsMap GetSavedInvalidations() const override;
void Clear() override;
};
} // namespace syncer
#endif // COMPONENTS_SYNC_TOOLS_NULL_INVALIDATION_STATE_TRACKER_H_
// Copyright (c) 2012 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 <cstddef>
#include <cstdio>
#include <memory>
#include <string>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "components/invalidation/impl/invalidation_state_tracker.h"
#include "components/invalidation/impl/invalidator.h"
#include "components/invalidation/impl/non_blocking_invalidator.h"
#include "components/invalidation/public/invalidation_handler.h"
#include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/object_id_invalidation_map.h"
#include "components/sync/base/invalidation_helper.h"
#include "components/sync/base/model_type.h"
#include "components/sync/tools/null_invalidation_state_tracker.h"
#include "jingle/notifier/base/notification_method.h"
#include "jingle/notifier/base/notifier_options.h"
#include "net/base/host_port_pair.h"
#include "net/base/network_change_notifier.h"
#include "net/dns/host_resolver.h"
#include "net/http/transport_security_state.h"
#include "net/url_request/url_request_test_util.h"
#if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
#endif
// This is a simple utility that initializes a sync notifier and
// listens to any received notifications.
namespace syncer {
namespace {
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";
// Class to print received notifications events.
class NotificationPrinter : public InvalidationHandler {
public:
NotificationPrinter() {}
~NotificationPrinter() override {}
void OnInvalidatorStateChange(InvalidatorState state) override {
LOG(INFO) << "Invalidator state changed to "
<< InvalidatorStateToString(state);
}
void OnIncomingInvalidation(
const ObjectIdInvalidationMap& invalidation_map) override {
ObjectIdSet ids = invalidation_map.GetObjectIds();
for (auto it = ids.begin(); it != ids.end(); ++it) {
LOG(INFO) << "Remote invalidation: " << invalidation_map.ToString();
}
}
std::string GetOwnerName() const override { return "NotificationPrinter"; }
private:
DISALLOW_COPY_AND_ASSIGN(NotificationPrinter);
};
// Needed to use a real host resolver.
class MyTestURLRequestContext : public net::TestURLRequestContext {
public:
MyTestURLRequestContext() : TestURLRequestContext(true) {
context_storage_.set_host_resolver(
net::HostResolver::CreateDefaultResolver(nullptr));
context_storage_.set_transport_security_state(
std::make_unique<net::TransportSecurityState>());
Init();
}
~MyTestURLRequestContext() override {}
};
class MyTestURLRequestContextGetter : public net::TestURLRequestContextGetter {
public:
explicit MyTestURLRequestContextGetter(
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
: TestURLRequestContextGetter(io_task_runner) {}
net::TestURLRequestContext* GetURLRequestContext() override {
// Construct |context_| lazily so it gets constructed on the right
// thread (the IO thread).
if (!context_)
context_ = std::make_unique<MyTestURLRequestContext>();
return context_.get();
}
private:
~MyTestURLRequestContextGetter() override {}
std::unique_ptr<MyTestURLRequestContext> context_;
};
notifier::NotifierOptions ParseNotifierOptions(
const base::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.";
return notifier_options;
}
int SyncListenNotificationsMain(int argc, char* argv[]) {
#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool pool;
#endif
base::AtExitManager exit_manager;
base::CommandLine::Init(argc, argv);
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
logging::InitLogging(settings);
base::MessageLoop ui_loop;
base::Thread io_thread("IO thread");
base::Thread::Options options;
options.message_loop_type = base::MessageLoop::TYPE_IO;
io_thread.StartWithOptions(options);
// Parse command line.
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
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 --%s=foo@bar.com --%s=token\n"
"[--%s=host:port] [--%s] [--%s]\n"
"Run chrome and set a breakpoint on\n"
"SyncManagerImpl::UpdateCredentials() "
"after logging into\n"
"sync to get the token to pass into this utility.\n",
argv[0], kEmailSwitch, kTokenSwitch, kHostPortSwitch,
kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch);
return -1;
}
// Set up objects that monitor the network.
std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier(
net::NetworkChangeNotifier::Create());
const notifier::NotifierOptions& notifier_options = ParseNotifierOptions(
command_line, new MyTestURLRequestContextGetter(io_thread.task_runner()));
NetworkChannelCreator network_channel_creator =
NonBlockingInvalidator::MakePushClientChannelCreator(notifier_options);
const char kClientInfo[] = "sync_listen_notifications";
NullInvalidationStateTracker null_invalidation_state_tracker;
std::unique_ptr<Invalidator> invalidator(new NonBlockingInvalidator(
network_channel_creator, base::RandBytesAsString(8),
null_invalidation_state_tracker.GetSavedInvalidations(),
null_invalidation_state_tracker.GetBootstrapData(),
&null_invalidation_state_tracker, kClientInfo,
notifier_options.request_context_getter->GetNetworkTaskRunner()));
NotificationPrinter notification_printer;
invalidator->UpdateCredentials(email, token);
// Listen for notifications for all known types.
invalidator->RegisterHandler(&notification_printer);
bool success = invalidator->UpdateRegisteredIds(
&notification_printer, ModelTypeSetToObjectIdSet(ModelTypeSet::All()));
DCHECK(success);
base::RunLoop().Run();
invalidator->UnregisterHandler(&notification_printer);
io_thread.Stop();
return 0;
}
} // namespace
} // namespace syncer
int main(int argc, char* argv[]) {
return syncer::SyncListenNotificationsMain(argc, argv);
}
include_rules = [
"+components/sync/test",
"+net",
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment