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

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

Issue 1415653004: Resolve issue from feedback for 1417363004 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 | chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc » ('j') | 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/lazy_instance.h" 8 #include "base/lazy_instance.h"
8 #include "base/location.h" 9 #include "base/location.h"
9 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "chrome/browser/local_discovery/cloud_device_list.h" 15 #include "chrome/browser/local_discovery/cloud_device_list.h"
15 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" 16 #include "chrome/browser/local_discovery/cloud_print_printer_list.h"
16 #include "chrome/browser/local_discovery/gcd_api_flow.h" 17 #include "chrome/browser/local_discovery/gcd_api_flow.h"
17 #include "chrome/browser/local_discovery/gcd_constants.h" 18 #include "chrome/browser/local_discovery/gcd_constants.h"
18 #include "chrome/browser/local_discovery/privet_device_lister_impl.h" 19 #include "chrome/browser/local_discovery/privet_device_lister_impl.h"
19 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" 20 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h"
20 #include "chrome/browser/local_discovery/privet_http_impl.h" 21 #include "chrome/browser/local_discovery/privet_http_impl.h"
21 #include "chrome/browser/local_discovery/privetv3_session.h" 22 #include "chrome/browser/local_discovery/privetv3_session.h"
22 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" 23 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
25 #include "chrome/browser/signin/signin_manager_factory.h" 26 #include "chrome/browser/signin/signin_manager_factory.h"
27 #include "chrome/common/chrome_switches.h"
26 #include "components/signin/core/browser/profile_oauth2_token_service.h" 28 #include "components/signin/core/browser/profile_oauth2_token_service.h"
27 #include "components/signin/core/browser/signin_manager.h" 29 #include "components/signin/core/browser/signin_manager.h"
28 #include "components/signin/core/browser/signin_manager_base.h" 30 #include "components/signin/core/browser/signin_manager_base.h"
29 #include "extensions/browser/event_router.h" 31 #include "extensions/browser/event_router.h"
30 #include "net/base/net_util.h" 32 #include "net/base/net_util.h"
31 33
32 #if defined(ENABLE_WIFI_BOOTSTRAPPING) 34 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
33 #include "chrome/browser/local_discovery/wifi/wifi_manager.h" 35 #include "chrome/browser/local_discovery/wifi/wifi_manager.h"
34 #endif 36 #endif
35 37
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 params.Pass())); 71 params.Pass()));
70 return event.Pass(); 72 return event.Pass();
71 } 73 }
72 74
73 GcdPrivateAPI::GCDApiFlowFactoryForTests* g_gcd_api_flow_factory = NULL; 75 GcdPrivateAPI::GCDApiFlowFactoryForTests* g_gcd_api_flow_factory = NULL;
74 76
75 base::LazyInstance<BrowserContextKeyedAPIFactory<GcdPrivateAPI> > g_factory = 77 base::LazyInstance<BrowserContextKeyedAPIFactory<GcdPrivateAPI> > g_factory =
76 LAZY_INSTANCE_INITIALIZER; 78 LAZY_INSTANCE_INITIALIZER;
77 79
78 scoped_ptr<local_discovery::GCDApiFlow> MakeGCDApiFlow(Profile* profile) { 80 scoped_ptr<local_discovery::GCDApiFlow> MakeGCDApiFlow(Profile* profile) {
79 if (g_gcd_api_flow_factory) { 81 if (g_gcd_api_flow_factory)
80 return g_gcd_api_flow_factory->CreateGCDApiFlow(); 82 return g_gcd_api_flow_factory->CreateGCDApiFlow();
81 }
82 83
83 ProfileOAuth2TokenService* token_service = 84 ProfileOAuth2TokenService* token_service =
84 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 85 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
85 if (!token_service) 86 if (!token_service)
86 return scoped_ptr<local_discovery::GCDApiFlow>(); 87 return scoped_ptr<local_discovery::GCDApiFlow>();
87 SigninManagerBase* signin_manager = 88 SigninManagerBase* signin_manager =
88 SigninManagerFactory::GetInstance()->GetForProfile(profile); 89 SigninManagerFactory::GetInstance()->GetForProfile(profile);
89 if (!signin_manager) 90 if (!signin_manager)
90 return scoped_ptr<local_discovery::GCDApiFlow>(); 91 return scoped_ptr<local_discovery::GCDApiFlow>();
91 return local_discovery::GCDApiFlow::Create( 92 return local_discovery::GCDApiFlow::Create(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 DCHECK(browser_context_); 214 DCHECK(browser_context_);
214 if (EventRouter::Get(context)) { 215 if (EventRouter::Get(context)) {
215 EventRouter::Get(context) 216 EventRouter::Get(context)
216 ->RegisterObserver(this, gcd_private::OnDeviceStateChanged::kEventName); 217 ->RegisterObserver(this, gcd_private::OnDeviceStateChanged::kEventName);
217 EventRouter::Get(context) 218 EventRouter::Get(context)
218 ->RegisterObserver(this, gcd_private::OnDeviceRemoved::kEventName); 219 ->RegisterObserver(this, gcd_private::OnDeviceRemoved::kEventName);
219 } 220 }
220 } 221 }
221 222
222 GcdPrivateAPIImpl::~GcdPrivateAPIImpl() { 223 GcdPrivateAPIImpl::~GcdPrivateAPIImpl() {
223 if (EventRouter::Get(browser_context_)) { 224 if (EventRouter::Get(browser_context_))
224 EventRouter::Get(browser_context_)->UnregisterObserver(this); 225 EventRouter::Get(browser_context_)->UnregisterObserver(this);
225 }
226 } 226 }
227 227
228 void GcdPrivateAPIImpl::OnListenerAdded(const EventListenerInfo& details) { 228 void GcdPrivateAPIImpl::OnListenerAdded(const EventListenerInfo& details) {
229 if (details.event_name == gcd_private::OnDeviceStateChanged::kEventName || 229 if (details.event_name == gcd_private::OnDeviceStateChanged::kEventName ||
230 details.event_name == gcd_private::OnDeviceRemoved::kEventName) { 230 details.event_name == gcd_private::OnDeviceRemoved::kEventName) {
231 num_device_listeners_++; 231 num_device_listeners_++;
232 232
233 if (num_device_listeners_ == 1) { 233 if (num_device_listeners_ == 1) {
234 service_discovery_client_ = 234 service_discovery_client_ =
235 local_discovery::ServiceDiscoverySharedClient::GetInstance(); 235 local_discovery::ServiceDiscoverySharedClient::GetInstance();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return false; 310 return false;
311 311
312 privet_device_lister_->DiscoverNewDevices(true); 312 privet_device_lister_->DiscoverNewDevices(true);
313 313
314 return true; 314 return true;
315 } 315 }
316 316
317 void GcdPrivateAPIImpl::CreateSession(const std::string& service_name, 317 void GcdPrivateAPIImpl::CreateSession(const std::string& service_name,
318 const CreateSessionCallback& callback) { 318 const CreateSessionCallback& callback) {
319 int session_id = last_session_id_++; 319 int session_id = last_session_id_++;
320 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
321 switches::kEnablePrivetV3)) {
322 return callback.Run(session_id, gcd_private::STATUS_SESSIONERROR,
323 base::DictionaryValue());
324 }
320 scoped_ptr<local_discovery::PrivetHTTPAsynchronousFactory> factory( 325 scoped_ptr<local_discovery::PrivetHTTPAsynchronousFactory> factory(
321 local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance( 326 local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance(
322 browser_context_->GetRequestContext())); 327 browser_context_->GetRequestContext()));
323 auto& session_data = sessions_[session_id]; 328 auto& session_data = sessions_[session_id];
324 session_data.http_resolution.reset( 329 session_data.http_resolution.reset(
325 factory->CreatePrivetHTTP(service_name).release()); 330 factory->CreatePrivetHTTP(service_name).release());
326 session_data.http_resolution->Start( 331 session_data.http_resolution->Start(
327 base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, base::Unretained(this), 332 base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, base::Unretained(this),
328 session_id, callback)); 333 session_id, callback));
329 } 334 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 #else 428 #else
424 callback.Run(false); 429 callback.Run(false);
425 #endif 430 #endif
426 } 431 }
427 432
428 #if defined(ENABLE_WIFI_BOOTSTRAPPING) 433 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
429 void GcdPrivateAPIImpl::OnWifiPassword(const SuccessCallback& callback, 434 void GcdPrivateAPIImpl::OnWifiPassword(const SuccessCallback& callback,
430 bool success, 435 bool success,
431 const std::string& ssid, 436 const std::string& ssid,
432 const std::string& password) { 437 const std::string& password) {
433 if (success) { 438 if (success)
434 wifi_passwords_[ssid] = password; 439 wifi_passwords_[ssid] = password;
435 }
436 440
437 callback.Run(success); 441 callback.Run(success);
438 } 442 }
439 443
440 void GcdPrivateAPIImpl::StartWifiIfNotStarted() { 444 void GcdPrivateAPIImpl::StartWifiIfNotStarted() {
441 if (!wifi_manager_) { 445 if (!wifi_manager_) {
442 wifi_manager_ = local_discovery::wifi::WifiManager::Create(); 446 wifi_manager_ = local_discovery::wifi::WifiManager::Create();
443 wifi_manager_->Start(); 447 wifi_manager_->Start();
444 } 448 }
445 } 449 }
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 } 886 }
883 887
884 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { 888 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() {
885 } 889 }
886 890
887 bool GcdPrivateGetCommandsListFunction::RunAsync() { 891 bool GcdPrivateGetCommandsListFunction::RunAsync() {
888 return false; 892 return false;
889 } 893 }
890 894
891 } // namespace extensions 895 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698