Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/browser/extensions/api/gcd_private/gcd_private_api.cc

Issue 1434383004: Don't use PrivetHTTPAsynchronousFactory in PrivetV3Session (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@context3
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" 5 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/memory/linked_ptr.h" 9 #include "base/memory/linked_ptr.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h" 11 #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h"
12 #include "chrome/browser/local_discovery/endpoint_resolver.h"
12 #include "chrome/browser/local_discovery/privet_http.h" 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 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" 15 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
17 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 namespace gcd_private = api::gcd_private; 22 namespace gcd_private = api::gcd_private;
22 23
23 namespace { 24 namespace {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 78
78 private: 79 private:
79 typedef std::map<std::string /* ssid */, std::string /* password */> 80 typedef std::map<std::string /* ssid */, std::string /* password */>
80 PasswordMap; 81 PasswordMap;
81 82
82 void SendMessageInternal(int session_id, 83 void SendMessageInternal(int session_id,
83 const std::string& api, 84 const std::string& api,
84 const base::DictionaryValue& input, 85 const base::DictionaryValue& input,
85 const MessageResponseCallback& callback); 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 const CreateSessionCallback& callback, 90 const CreateSessionCallback& callback,
89 scoped_ptr<local_discovery::PrivetHTTPClient> client); 91 const net::IPEndPoint& endpoint);
90 92
91 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> 93 scoped_refptr<local_discovery::ServiceDiscoverySharedClient>
92 service_discovery_client_; 94 service_discovery_client_;
93 95
94 struct SessionInfo { 96 struct SessionInfo {
95 linked_ptr<PrivetV3Session> session; 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 std::map<int, SessionInfo> sessions_; 101 std::map<int, SessionInfo> sessions_;
100 int last_session_id_ = 0; 102 int last_session_id_ = 0;
101 103
102 content::BrowserContext* const browser_context_; 104 content::BrowserContext* const browser_context_;
103 105
104 base::WeakPtrFactory<GcdPrivateAPIImpl> weak_ptr_factory_{this}; 106 base::WeakPtrFactory<GcdPrivateAPIImpl> weak_ptr_factory_{this};
105 107
106 DISALLOW_COPY_AND_ASSIGN(GcdPrivateAPIImpl); 108 DISALLOW_COPY_AND_ASSIGN(GcdPrivateAPIImpl);
(...skipping 16 matching lines...) Expand all
123 } 125 }
124 126
125 void GcdPrivateAPIImpl::CreateSession(const std::string& service_name, 127 void GcdPrivateAPIImpl::CreateSession(const std::string& service_name,
126 const CreateSessionCallback& callback) { 128 const CreateSessionCallback& callback) {
127 int session_id = last_session_id_++; 129 int session_id = last_session_id_++;
128 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 130 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
129 switches::kEnablePrivetV3)) { 131 switches::kEnablePrivetV3)) {
130 return callback.Run(session_id, gcd_private::STATUS_SESSIONERROR, 132 return callback.Run(session_id, gcd_private::STATUS_SESSIONERROR,
131 base::DictionaryValue()); 133 base::DictionaryValue());
132 } 134 }
133 scoped_ptr<local_discovery::PrivetHTTPAsynchronousFactory> factory(
134 local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance(
135 browser_context_->GetRequestContext()));
136 auto& session_data = sessions_[session_id]; 135 auto& session_data = sessions_[session_id];
137 session_data.http_resolution.reset( 136 session_data.resolver.reset(new local_discovery::EndpointResolver());
138 factory->CreatePrivetHTTP(service_name).release()); 137 session_data.resolver->Start(
139 session_data.http_resolution->Start( 138 service_name,
140 base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, base::Unretained(this), 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( 143 void GcdPrivateAPIImpl::OnServiceResolved(const std::string& service_name,
145 int session_id, 144 int session_id,
146 const CreateSessionCallback& callback, 145 const CreateSessionCallback& callback,
147 scoped_ptr<local_discovery::PrivetHTTPClient> client) { 146 const net::IPEndPoint& endpoint) {
148 if (!client) { 147 if (endpoint.address().empty()) {
149 return callback.Run(session_id, gcd_private::STATUS_SERVICERESOLUTIONERROR, 148 return callback.Run(session_id, gcd_private::STATUS_SERVICERESOLUTIONERROR,
150 base::DictionaryValue()); 149 base::DictionaryValue());
151 } 150 }
152 auto& session_data = sessions_[session_id]; 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 session_data.session.reset(new PrivetV3Session(client.Pass())); 156 session_data.session.reset(new PrivetV3Session(client.Pass()));
154 session_data.session->Init(base::Bind(callback, session_id)); 157 session_data.session->Init(base::Bind(callback, session_id));
155 } 158 }
156 159
157 void GcdPrivateAPIImpl::StartPairing(int session_id, 160 void GcdPrivateAPIImpl::StartPairing(int session_id,
158 api::gcd_private::PairingType pairing_type, 161 api::gcd_private::PairingType pairing_type,
159 const SessionCallback& callback) { 162 const SessionCallback& callback) {
160 auto found = sessions_.find(session_id); 163 auto found = sessions_.find(session_id);
161 164
162 if (found == sessions_.end()) 165 if (found == sessions_.end())
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 440
438 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); 441 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
439 442
440 gcd_api->RemoveSession(params->session_id); 443 gcd_api->RemoveSession(params->session_id);
441 444
442 SendResponse(true); 445 SendResponse(true);
443 return true; 446 return true;
444 } 447 }
445 448
446 } // namespace extensions 449 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698