Commit e61a6220 authored by vitalybuka's avatar vitalybuka Committed by Commit bot

Remove ServiceDiscoveryClient* from PrivetHTTPAsynchronousFactoryImpl interface

PrivetHTTPAsynchronousFactoryImpl can use ServiceDiscoverySharedClient::GetInstance.
Also we don't use this for testing, so we can simplify interface.

BUG=461504

Review URL: https://codereview.chromium.org/959503003

Cr-Commit-Position: refs/heads/master@{#318013}
parent 0d1cd5b3
...@@ -15,7 +15,6 @@ namespace local_discovery { ...@@ -15,7 +15,6 @@ namespace local_discovery {
// static // static
scoped_ptr<PrivetHTTPAsynchronousFactory> scoped_ptr<PrivetHTTPAsynchronousFactory>
PrivetHTTPAsynchronousFactory::CreateInstance( PrivetHTTPAsynchronousFactory::CreateInstance(
ServiceDiscoveryClient* service_discovery_client,
net::URLRequestContextGetter* request_context) { net::URLRequestContextGetter* request_context) {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
return make_scoped_ptr<PrivetHTTPAsynchronousFactory>( return make_scoped_ptr<PrivetHTTPAsynchronousFactory>(
...@@ -23,8 +22,7 @@ PrivetHTTPAsynchronousFactory::CreateInstance( ...@@ -23,8 +22,7 @@ PrivetHTTPAsynchronousFactory::CreateInstance(
#else #else
return make_scoped_ptr<PrivetHTTPAsynchronousFactory>( return make_scoped_ptr<PrivetHTTPAsynchronousFactory>(
new PrivetHTTPAsynchronousFactoryImpl(service_discovery_client, new PrivetHTTPAsynchronousFactoryImpl(request_context));
request_context));
#endif #endif
} }
......
...@@ -18,7 +18,6 @@ class URLRequestContextGetter; ...@@ -18,7 +18,6 @@ class URLRequestContextGetter;
namespace local_discovery { namespace local_discovery {
class PrivetHTTPClient; class PrivetHTTPClient;
class ServiceDiscoveryClient;
class PrivetHTTPResolution { class PrivetHTTPResolution {
public: public:
...@@ -34,7 +33,6 @@ class PrivetHTTPAsynchronousFactory { ...@@ -34,7 +33,6 @@ class PrivetHTTPAsynchronousFactory {
virtual ~PrivetHTTPAsynchronousFactory() {} virtual ~PrivetHTTPAsynchronousFactory() {}
static scoped_ptr<PrivetHTTPAsynchronousFactory> CreateInstance( static scoped_ptr<PrivetHTTPAsynchronousFactory> CreateInstance(
ServiceDiscoveryClient* service_discovery_client,
net::URLRequestContextGetter* request_context); net::URLRequestContextGetter* request_context);
virtual scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP( virtual scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP(
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/local_discovery/privet_http_impl.h" #include "chrome/browser/local_discovery/privet_http_impl.h"
#include "chrome/browser/local_discovery/service_discovery_shared_client.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
namespace local_discovery { namespace local_discovery {
...@@ -28,10 +29,8 @@ std::string IPAddressToHostString(const net::IPAddressNumber& address) { ...@@ -28,10 +29,8 @@ std::string IPAddressToHostString(const net::IPAddressNumber& address) {
} // namespace } // namespace
PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl( PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl(
ServiceDiscoveryClient* service_discovery_client,
net::URLRequestContextGetter* request_context) net::URLRequestContextGetter* request_context)
: service_discovery_client_(service_discovery_client), : request_context_(request_context) {
request_context_(request_context) {
} }
PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() { PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() {
...@@ -43,33 +42,28 @@ PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP( ...@@ -43,33 +42,28 @@ PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP(
const net::HostPortPair& address, const net::HostPortPair& address,
const ResultCallback& callback) { const ResultCallback& callback) {
return scoped_ptr<PrivetHTTPResolution>( return scoped_ptr<PrivetHTTPResolution>(
new ResolutionImpl(name, new ResolutionImpl(name, address, callback, request_context_.get()));
address,
callback,
service_discovery_client_,
request_context_.get()));
} }
PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl( PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl(
const std::string& name, const std::string& name,
const net::HostPortPair& address, const net::HostPortPair& address,
const ResultCallback& callback, const ResultCallback& callback,
ServiceDiscoveryClient* service_discovery_client,
net::URLRequestContextGetter* request_context) net::URLRequestContextGetter* request_context)
: name_(name), : name_(name),
hostport_(address), hostport_(address),
callback_(callback), callback_(callback),
request_context_(request_context) { request_context_(request_context) {
net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED; service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance();
net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED;
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kPrivetIPv6Only)) { switches::kPrivetIPv6Only)) {
address_family = net::ADDRESS_FAMILY_IPV6; address_family = net::ADDRESS_FAMILY_IPV6;
} }
resolver_ = service_discovery_client->CreateLocalDomainResolver( resolver_ = service_discovery_client_->CreateLocalDomainResolver(
address.host(), address.host(), address_family,
address_family,
base::Bind(&ResolutionImpl::ResolveComplete, base::Unretained(this))); base::Bind(&ResolutionImpl::ResolveComplete, base::Unretained(this)));
} }
......
...@@ -11,10 +11,11 @@ ...@@ -11,10 +11,11 @@
namespace local_discovery { namespace local_discovery {
class ServiceDiscoverySharedClient;
class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory { class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory {
public: public:
PrivetHTTPAsynchronousFactoryImpl( explicit PrivetHTTPAsynchronousFactoryImpl(
ServiceDiscoveryClient* service_discovery_client,
net::URLRequestContextGetter* request_context); net::URLRequestContextGetter* request_context);
~PrivetHTTPAsynchronousFactoryImpl() override; ~PrivetHTTPAsynchronousFactoryImpl() override;
...@@ -29,7 +30,6 @@ class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory { ...@@ -29,7 +30,6 @@ class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory {
ResolutionImpl(const std::string& name, ResolutionImpl(const std::string& name,
const net::HostPortPair& address, const net::HostPortPair& address,
const ResultCallback& callback, const ResultCallback& callback,
ServiceDiscoveryClient* service_discovery_client,
net::URLRequestContextGetter* request_context); net::URLRequestContextGetter* request_context);
~ResolutionImpl() override; ~ResolutionImpl() override;
...@@ -46,9 +46,9 @@ class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory { ...@@ -46,9 +46,9 @@ class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory {
net::HostPortPair hostport_; net::HostPortPair hostport_;
ResultCallback callback_; ResultCallback callback_;
scoped_refptr<net::URLRequestContextGetter> request_context_; scoped_refptr<net::URLRequestContextGetter> request_context_;
scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_;
}; };
ServiceDiscoveryClient* service_discovery_client_;
scoped_refptr<net::URLRequestContextGetter> request_context_; scoped_refptr<net::URLRequestContextGetter> request_context_;
}; };
......
...@@ -31,7 +31,7 @@ PrivetLocalPrinterLister::PrivetLocalPrinterLister( ...@@ -31,7 +31,7 @@ PrivetLocalPrinterLister::PrivetLocalPrinterLister(
privet_lister_.reset( privet_lister_.reset(
new PrivetDeviceListerImpl(service_discovery_client, this)); new PrivetDeviceListerImpl(service_discovery_client, this));
privet_http_factory_ = PrivetHTTPAsynchronousFactory::CreateInstance( privet_http_factory_ = PrivetHTTPAsynchronousFactory::CreateInstance(
service_discovery_client, request_context); request_context);
} }
PrivetLocalPrinterLister::~PrivetLocalPrinterLister() { PrivetLocalPrinterLister::~PrivetLocalPrinterLister() {
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/message_loop/message_loop.h"
#include "chrome/browser/local_discovery/privet_local_printer_lister.h" #include "chrome/browser/local_discovery/privet_local_printer_lister.h"
#include "base/run_loop.h"
#include "chrome/browser/local_discovery/test_service_discovery_client.h" #include "chrome/browser/local_discovery/test_service_discovery_client.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -137,7 +138,7 @@ class PrivetLocalPrinterListerTest : public testing::Test { ...@@ -137,7 +138,7 @@ class PrivetLocalPrinterListerTest : public testing::Test {
void SimulateReceive(const uint8* packet, size_t size) { void SimulateReceive(const uint8* packet, size_t size) {
test_service_discovery_client_->SimulateReceive(packet, size); test_service_discovery_client_->SimulateReceive(packet, size);
message_loop_.RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
void ExpectAnyPacket() { void ExpectAnyPacket() {
...@@ -146,7 +147,7 @@ class PrivetLocalPrinterListerTest : public testing::Test { ...@@ -146,7 +147,7 @@ class PrivetLocalPrinterListerTest : public testing::Test {
} }
protected: protected:
base::MessageLoop message_loop_; content::TestBrowserThreadBundle test_thread_bundle;
scoped_refptr<TestServiceDiscoveryClient> test_service_discovery_client_; scoped_refptr<TestServiceDiscoveryClient> test_service_discovery_client_;
scoped_refptr<net::TestURLRequestContextGetter> url_request_context_; scoped_refptr<net::TestURLRequestContextGetter> url_request_context_;
scoped_ptr<PrivetLocalPrinterLister> local_printer_lister_; scoped_ptr<PrivetLocalPrinterLister> local_printer_lister_;
......
...@@ -351,7 +351,7 @@ void PrivetNotificationService::StartLister() { ...@@ -351,7 +351,7 @@ void PrivetNotificationService::StartLister() {
scoped_ptr<PrivetHTTPAsynchronousFactory> http_factory( scoped_ptr<PrivetHTTPAsynchronousFactory> http_factory(
PrivetHTTPAsynchronousFactory::CreateInstance( PrivetHTTPAsynchronousFactory::CreateInstance(
service_discovery_client_.get(), profile_->GetRequestContext())); profile_->GetRequestContext()));
privet_notifications_listener_.reset(new PrivetNotificationsListener( privet_notifications_listener_.reset(new PrivetNotificationsListener(
http_factory.Pass(), this)); http_factory.Pass(), this));
......
...@@ -171,7 +171,7 @@ void LocalDiscoveryUIHandler::HandleStart(const base::ListValue* args) { ...@@ -171,7 +171,7 @@ void LocalDiscoveryUIHandler::HandleStart(const base::ListValue* args) {
privet_lister_.reset( privet_lister_.reset(
new PrivetDeviceListerImpl(service_discovery_client_.get(), this)); new PrivetDeviceListerImpl(service_discovery_client_.get(), this));
privet_http_factory_ = PrivetHTTPAsynchronousFactory::CreateInstance( privet_http_factory_ = PrivetHTTPAsynchronousFactory::CreateInstance(
service_discovery_client_.get(), profile->GetRequestContext()); profile->GetRequestContext());
SigninManagerBase* signin_manager = SigninManagerBase* signin_manager =
SigninManagerFactory::GetInstance()->GetForProfile(profile); SigninManagerFactory::GetInstance()->GetForProfile(profile);
...@@ -211,8 +211,7 @@ void LocalDiscoveryUIHandler::HandleRegisterDevice( ...@@ -211,8 +211,7 @@ void LocalDiscoveryUIHandler::HandleRegisterDevice(
if (found->second.version < kCloudDevicesPrivetVersion) { if (found->second.version < kCloudDevicesPrivetVersion) {
privet_resolution_ = privet_http_factory_->CreatePrivetHTTP( privet_resolution_ = privet_http_factory_->CreatePrivetHTTP(
device, device, found->second.address,
found->second.address,
base::Bind(&LocalDiscoveryUIHandler::StartRegisterHTTP, base::Bind(&LocalDiscoveryUIHandler::StartRegisterHTTP,
base::Unretained(this))); base::Unretained(this)));
privet_resolution_->Start(); privet_resolution_->Start();
......
...@@ -1621,7 +1621,6 @@ bool PrintPreviewHandler::CreatePrivetHTTP( ...@@ -1621,7 +1621,6 @@ bool PrintPreviewHandler::CreatePrivetHTTP(
privet_http_factory_ = privet_http_factory_ =
local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance( local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance(
service_discovery_client_.get(),
Profile::FromWebUI(web_ui())->GetRequestContext()); Profile::FromWebUI(web_ui())->GetRequestContext());
privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP( privet_http_resolution_ = privet_http_factory_->CreatePrivetHTTP(
name, device_description->address, callback); name, device_description->address, callback);
......
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