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" | |
8 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
9 #include "base/memory/linked_ptr.h" | 8 #include "base/memory/linked_ptr.h" |
10 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
11 #include "chrome/browser/extensions/api/gcd_private/privet_v3_context_getter.h" | 10 #include "chrome/browser/extensions/api/gcd_private/privet_v3_context_getter.h" |
12 #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h" | 11 #include "chrome/browser/extensions/api/gcd_private/privet_v3_session.h" |
13 #include "chrome/browser/local_discovery/endpoint_resolver.h" | 12 #include "chrome/browser/local_discovery/endpoint_resolver.h" |
14 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 13 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/chrome_switches.h" | |
17 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
18 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
19 | 17 |
20 namespace extensions { | 18 namespace extensions { |
21 | 19 |
22 namespace gcd_private = api::gcd_private; | 20 namespace gcd_private = api::gcd_private; |
23 | 21 |
24 namespace { | 22 namespace { |
25 | 23 |
26 const char kPrivatAPISetup[] = "/privet/v3/setup/start"; | 24 const char kPrivatAPISetup[] = "/privet/v3/setup/start"; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // static | 118 // static |
121 GcdPrivateAPIImpl* GcdPrivateAPIImpl::Get(content::BrowserContext* context) { | 119 GcdPrivateAPIImpl* GcdPrivateAPIImpl::Get(content::BrowserContext* context) { |
122 GcdPrivateAPI* gcd_api = | 120 GcdPrivateAPI* gcd_api = |
123 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(context); | 121 BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(context); |
124 return gcd_api ? gcd_api->impl_.get() : NULL; | 122 return gcd_api ? gcd_api->impl_.get() : NULL; |
125 } | 123 } |
126 | 124 |
127 void GcdPrivateAPIImpl::CreateSession(const std::string& service_name, | 125 void GcdPrivateAPIImpl::CreateSession(const std::string& service_name, |
128 const CreateSessionCallback& callback) { | 126 const CreateSessionCallback& callback) { |
129 int session_id = last_session_id_++; | 127 int session_id = last_session_id_++; |
130 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
131 switches::kEnablePrivetV3)) { | |
132 return callback.Run(session_id, gcd_private::STATUS_SESSIONERROR, | |
133 base::DictionaryValue()); | |
134 } | |
135 auto& session_data = sessions_[session_id]; | 128 auto& session_data = sessions_[session_id]; |
136 session_data.resolver.reset(new local_discovery::EndpointResolver()); | 129 session_data.resolver.reset(new local_discovery::EndpointResolver()); |
137 session_data.resolver->Start( | 130 session_data.resolver->Start( |
138 service_name, base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, | 131 service_name, base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, |
139 base::Unretained(this), session_id, callback)); | 132 base::Unretained(this), session_id, callback)); |
140 } | 133 } |
141 | 134 |
142 void GcdPrivateAPIImpl::OnServiceResolved(int session_id, | 135 void GcdPrivateAPIImpl::OnServiceResolved(int session_id, |
143 const CreateSessionCallback& callback, | 136 const CreateSessionCallback& callback, |
144 const net::IPEndPoint& endpoint) { | 137 const net::IPEndPoint& endpoint) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 | 434 |
442 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); | 435 GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile()); |
443 | 436 |
444 gcd_api->RemoveSession(params->session_id); | 437 gcd_api->RemoveSession(params->session_id); |
445 | 438 |
446 SendResponse(true); | 439 SendResponse(true); |
447 return true; | 440 return true; |
448 } | 441 } |
449 | 442 |
450 } // namespace extensions | 443 } // namespace extensions |
OLD | NEW |