Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit 1283eca

Browse files
vitalybukaCommit bot
authored and
Commit bot
committed
Don't use PrivetHTTPAsynchronousFactory in PrivetV3Session
BUG=551631, 524788 Review URL: https://codereview.chromium.org/1434383004 Cr-Commit-Position: refs/heads/master@{#359700}
1 parent 2c347f8 commit 1283eca

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

chrome/browser/extensions/api/gcd_private/gcd_private_api.cc

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
#include "base/memory/linked_ptr.h"
1010
#include "base/thread_task_runner_handle.h"
1111
#include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h"
12+
#include "chrome/browser/local_discovery/endpoint_resolver.h"
1213
#include "chrome/browser/local_discovery/privet_http.h"
13-
#include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h"
14+
#include "chrome/browser/local_discovery/privet_http_impl.h"
1415
#include "chrome/browser/local_discovery/service_discovery_shared_client.h"
1516
#include "chrome/browser/profiles/profile.h"
1617
#include "chrome/common/chrome_switches.h"
@@ -84,16 +85,17 @@ class GcdPrivateAPIImpl {
8485
const base::DictionaryValue& input,
8586
const MessageResponseCallback& callback);
8687

87-
void OnServiceResolved(int session_id,
88+
void OnServiceResolved(const std::string& service_name,
89+
int session_id,
8890
const CreateSessionCallback& callback,
89-
scoped_ptr<local_discovery::PrivetHTTPClient> client);
91+
const net::IPEndPoint& endpoint);
9092

9193
scoped_refptr<local_discovery::ServiceDiscoverySharedClient>
9294
service_discovery_client_;
9395

9496
struct SessionInfo {
9597
linked_ptr<PrivetV3Session> session;
96-
linked_ptr<local_discovery::PrivetHTTPResolution> http_resolution;
98+
linked_ptr<local_discovery::EndpointResolver> resolver;
9799
};
98100

99101
std::map<int, SessionInfo> sessions_;
@@ -130,26 +132,27 @@ void GcdPrivateAPIImpl::CreateSession(const std::string& service_name,
130132
return callback.Run(session_id, gcd_private::STATUS_SESSIONERROR,
131133
base::DictionaryValue());
132134
}
133-
scoped_ptr<local_discovery::PrivetHTTPAsynchronousFactory> factory(
134-
local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance(
135-
browser_context_->GetRequestContext()));
136135
auto& session_data = sessions_[session_id];
137-
session_data.http_resolution.reset(
138-
factory->CreatePrivetHTTP(service_name).release());
139-
session_data.http_resolution->Start(
136+
session_data.resolver.reset(new local_discovery::EndpointResolver());
137+
session_data.resolver->Start(
138+
service_name,
140139
base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, base::Unretained(this),
141-
session_id, callback));
140+
service_name, session_id, callback));
142141
}
143142

144-
void GcdPrivateAPIImpl::OnServiceResolved(
145-
int session_id,
146-
const CreateSessionCallback& callback,
147-
scoped_ptr<local_discovery::PrivetHTTPClient> client) {
148-
if (!client) {
143+
void GcdPrivateAPIImpl::OnServiceResolved(const std::string& service_name,
144+
int session_id,
145+
const CreateSessionCallback& callback,
146+
const net::IPEndPoint& endpoint) {
147+
if (endpoint.address().empty()) {
149148
return callback.Run(session_id, gcd_private::STATUS_SERVICERESOLUTIONERROR,
150149
base::DictionaryValue());
151150
}
152151
auto& session_data = sessions_[session_id];
152+
net::HostPortPair host_port = net::HostPortPair::FromIPEndPoint(endpoint);
153+
scoped_ptr<local_discovery::PrivetHTTPClient> client(
154+
new local_discovery::PrivetHTTPClientImpl(
155+
service_name, host_port, browser_context_->GetRequestContext()));
153156
session_data.session.reset(new PrivetV3Session(client.Pass()));
154157
session_data.session->Init(base::Bind(callback, session_id));
155158
}

0 commit comments

Comments
 (0)