|
9 | 9 | #include "base/memory/linked_ptr.h"
|
10 | 10 | #include "base/thread_task_runner_handle.h"
|
11 | 11 | #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h"
|
| 12 | +#include "chrome/browser/local_discovery/endpoint_resolver.h" |
12 | 13 | #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" |
14 | 15 | #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
|
15 | 16 | #include "chrome/browser/profiles/profile.h"
|
16 | 17 | #include "chrome/common/chrome_switches.h"
|
@@ -84,16 +85,17 @@ class GcdPrivateAPIImpl {
|
84 | 85 | const base::DictionaryValue& input,
|
85 | 86 | const MessageResponseCallback& callback);
|
86 | 87 |
|
87 |
| - void OnServiceResolved(int session_id, |
| 88 | + void OnServiceResolved(const std::string& service_name, |
| 89 | + int session_id, |
88 | 90 | const CreateSessionCallback& callback,
|
89 |
| - scoped_ptr<local_discovery::PrivetHTTPClient> client); |
| 91 | + const net::IPEndPoint& endpoint); |
90 | 92 |
|
91 | 93 | scoped_refptr<local_discovery::ServiceDiscoverySharedClient>
|
92 | 94 | service_discovery_client_;
|
93 | 95 |
|
94 | 96 | struct SessionInfo {
|
95 | 97 | linked_ptr<PrivetV3Session> session;
|
96 |
| - linked_ptr<local_discovery::PrivetHTTPResolution> http_resolution; |
| 98 | + linked_ptr<local_discovery::EndpointResolver> resolver; |
97 | 99 | };
|
98 | 100 |
|
99 | 101 | std::map<int, SessionInfo> sessions_;
|
@@ -130,26 +132,27 @@ void GcdPrivateAPIImpl::CreateSession(const std::string& service_name,
|
130 | 132 | return callback.Run(session_id, gcd_private::STATUS_SESSIONERROR,
|
131 | 133 | base::DictionaryValue());
|
132 | 134 | }
|
133 |
| - scoped_ptr<local_discovery::PrivetHTTPAsynchronousFactory> factory( |
134 |
| - local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance( |
135 |
| - browser_context_->GetRequestContext())); |
136 | 135 | 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, |
140 | 139 | base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, base::Unretained(this),
|
141 |
| - session_id, callback)); |
| 140 | + service_name, session_id, callback)); |
142 | 141 | }
|
143 | 142 |
|
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()) { |
149 | 148 | return callback.Run(session_id, gcd_private::STATUS_SERVICERESOLUTIONERROR,
|
150 | 149 | base::DictionaryValue());
|
151 | 150 | }
|
152 | 151 | 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())); |
153 | 156 | session_data.session.reset(new PrivetV3Session(client.Pass()));
|
154 | 157 | session_data.session->Init(base::Bind(callback, session_id));
|
155 | 158 | }
|
|
0 commit comments