| OLD | NEW |
| 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_context_getter.h" |
| 11 #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h" | 12 #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h" |
| 12 #include "chrome/browser/local_discovery/endpoint_resolver.h" | 13 #include "chrome/browser/local_discovery/endpoint_resolver.h" |
| 13 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 14 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 16 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 18 | 19 |
| 19 namespace extensions { | 20 namespace extensions { |
| 20 | 21 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 struct SessionInfo { | 95 struct SessionInfo { |
| 95 linked_ptr<PrivetV3Session> session; | 96 linked_ptr<PrivetV3Session> session; |
| 96 linked_ptr<local_discovery::EndpointResolver> resolver; | 97 linked_ptr<local_discovery::EndpointResolver> resolver; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 std::map<int, SessionInfo> sessions_; | 100 std::map<int, SessionInfo> sessions_; |
| 100 int last_session_id_ = 0; | 101 int last_session_id_ = 0; |
| 101 | 102 |
| 102 content::BrowserContext* const browser_context_; | 103 content::BrowserContext* const browser_context_; |
| 103 | 104 |
| 105 scoped_refptr<PrivetV3ContextGetter> context_getter_; |
| 106 |
| 104 base::WeakPtrFactory<GcdPrivateAPIImpl> weak_ptr_factory_{this}; | 107 base::WeakPtrFactory<GcdPrivateAPIImpl> weak_ptr_factory_{this}; |
| 105 | 108 |
| 106 DISALLOW_COPY_AND_ASSIGN(GcdPrivateAPIImpl); | 109 DISALLOW_COPY_AND_ASSIGN(GcdPrivateAPIImpl); |
| 107 }; | 110 }; |
| 108 | 111 |
| 109 | |
| 110 GcdPrivateAPIImpl::GcdPrivateAPIImpl(content::BrowserContext* context) | 112 GcdPrivateAPIImpl::GcdPrivateAPIImpl(content::BrowserContext* context) |
| 111 : browser_context_(context) { | 113 : browser_context_(context) { |
| 112 DCHECK(browser_context_); | 114 DCHECK(browser_context_); |
| 113 } | 115 } |
| 114 | 116 |
| 115 GcdPrivateAPIImpl::~GcdPrivateAPIImpl() { | 117 GcdPrivateAPIImpl::~GcdPrivateAPIImpl() { |
| 116 } | 118 } |
| 117 | 119 |
| 118 // static | 120 // static |
| 119 GcdPrivateAPIImpl* GcdPrivateAPIImpl::Get(content::BrowserContext* context) { | 121 GcdPrivateAPIImpl* GcdPrivateAPIImpl::Get(content::BrowserContext* context) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 138 } | 140 } |
| 139 | 141 |
| 140 void GcdPrivateAPIImpl::OnServiceResolved(int session_id, | 142 void GcdPrivateAPIImpl::OnServiceResolved(int session_id, |
| 141 const CreateSessionCallback& callback, | 143 const CreateSessionCallback& callback, |
| 142 const net::IPEndPoint& endpoint) { | 144 const net::IPEndPoint& endpoint) { |
| 143 if (endpoint.address().empty()) { | 145 if (endpoint.address().empty()) { |
| 144 return callback.Run(session_id, gcd_private::STATUS_SERVICERESOLUTIONERROR, | 146 return callback.Run(session_id, gcd_private::STATUS_SERVICERESOLUTIONERROR, |
| 145 base::DictionaryValue()); | 147 base::DictionaryValue()); |
| 146 } | 148 } |
| 147 auto& session_data = sessions_[session_id]; | 149 auto& session_data = sessions_[session_id]; |
| 148 session_data.session.reset( | 150 |
| 149 new PrivetV3Session(browser_context_->GetRequestContext(), | 151 if (!context_getter_) { |
| 150 net::HostPortPair::FromIPEndPoint(endpoint))); | 152 context_getter_ = new PrivetV3ContextGetter( |
| 153 browser_context_->GetRequestContext()->GetNetworkTaskRunner()); |
| 154 } |
| 155 |
| 156 session_data.session.reset(new PrivetV3Session( |
| 157 context_getter_, net::HostPortPair::FromIPEndPoint(endpoint))); |
| 151 session_data.session->Init(base::Bind(callback, session_id)); | 158 session_data.session->Init(base::Bind(callback, session_id)); |
| 152 } | 159 } |
| 153 | 160 |
| 154 void GcdPrivateAPIImpl::StartPairing(int session_id, | 161 void GcdPrivateAPIImpl::StartPairing(int session_id, |
| 155 api::gcd_private::PairingType pairing_type, | 162 api::gcd_private::PairingType pairing_type, |
| 156 const SessionCallback& callback) { | 163 const SessionCallback& callback) { |
| 157 auto found = sessions_.find(session_id); | 164 auto found = sessions_.find(session_id); |
| 158 | 165 |
| 159 if (found == sessions_.end()) | 166 if (found == sessions_.end()) |
| 160 return callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR); | 167 return callback.Run(gcd_private::STATUS_UNKNOWNSESSIONERROR); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 441 |
| 435 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); | 442 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); |
| 436 | 443 |
| 437 gcd_api->RemoveSession(params->session_id); | 444 gcd_api->RemoveSession(params->session_id); |
| 438 | 445 |
| 439 SendResponse(true); | 446 SendResponse(true); |
| 440 return true; | 447 return true; |
| 441 } | 448 } |
| 442 | 449 |
| 443 } // namespace extensions | 450 } // namespace extensions |
| OLD | NEW |