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

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
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) {
Ryan Sleevi 2015/10/30 23:17:27 FWIW this bracing is inconsistent w/ the rest of t
Vitaly Buka (NO REVIEWS) 2015/10/31 03:55:35 Done.
80 return g_gcd_api_flow_factory->CreateGCDApiFlow(); 82 return g_gcd_api_flow_factory->CreateGCDApiFlow();
81 } 83 }
82 84
83 ProfileOAuth2TokenService* token_service = 85 ProfileOAuth2TokenService* token_service =
84 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 86 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
85 if (!token_service) 87 if (!token_service)
86 return scoped_ptr<local_discovery::GCDApiFlow>(); 88 return scoped_ptr<local_discovery::GCDApiFlow>();
87 SigninManagerBase* signin_manager = 89 SigninManagerBase* signin_manager =
88 SigninManagerFactory::GetInstance()->GetForProfile(profile); 90 SigninManagerFactory::GetInstance()->GetForProfile(profile);
89 if (!signin_manager) 91 if (!signin_manager)
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 EventRouter::Get(context) 217 EventRouter::Get(context)
216 ->RegisterObserver(this, gcd_private::OnDeviceStateChanged::kEventName); 218 ->RegisterObserver(this, gcd_private::OnDeviceStateChanged::kEventName);
217 EventRouter::Get(context) 219 EventRouter::Get(context)
218 ->RegisterObserver(this, gcd_private::OnDeviceRemoved::kEventName); 220 ->RegisterObserver(this, gcd_private::OnDeviceRemoved::kEventName);
219 } 221 }
220 } 222 }
221 223
222 GcdPrivateAPIImpl::~GcdPrivateAPIImpl() { 224 GcdPrivateAPIImpl::~GcdPrivateAPIImpl() {
223 if (EventRouter::Get(browser_context_)) { 225 if (EventRouter::Get(browser_context_)) {
224 EventRouter::Get(browser_context_)->UnregisterObserver(this); 226 EventRouter::Get(browser_context_)->UnregisterObserver(this);
225 } 227 }
Ryan Sleevi 2015/10/30 23:17:27 more inconsistent bracing
Vitaly Buka (NO REVIEWS) 2015/10/31 03:55:35 Done.
226 } 228 }
227 229
228 void GcdPrivateAPIImpl::OnListenerAdded(const EventListenerInfo& details) { 230 void GcdPrivateAPIImpl::OnListenerAdded(const EventListenerInfo& details) {
229 if (details.event_name == gcd_private::OnDeviceStateChanged::kEventName || 231 if (details.event_name == gcd_private::OnDeviceStateChanged::kEventName ||
230 details.event_name == gcd_private::OnDeviceRemoved::kEventName) { 232 details.event_name == gcd_private::OnDeviceRemoved::kEventName) {
231 num_device_listeners_++; 233 num_device_listeners_++;
232 234
233 if (num_device_listeners_ == 1) { 235 if (num_device_listeners_ == 1) {
234 service_discovery_client_ = 236 service_discovery_client_ =
235 local_discovery::ServiceDiscoverySharedClient::GetInstance(); 237 local_discovery::ServiceDiscoverySharedClient::GetInstance();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (!description.id.empty()) 274 if (!description.id.empty())
273 device->cloud_id.reset(new std::string(description.id)); 275 device->cloud_id.reset(new std::string(description.id));
274 276
275 known_devices_[device->device_id] = device; 277 known_devices_[device->device_id] = device;
276 278
277 EventRouter::Get(browser_context_) 279 EventRouter::Get(browser_context_)
278 ->BroadcastEvent(MakeDeviceStateChangedEvent(*device)); 280 ->BroadcastEvent(MakeDeviceStateChangedEvent(*device));
279 } 281 }
280 282
281 void GcdPrivateAPIImpl::DeviceRemoved(const std::string& name) { 283 void GcdPrivateAPIImpl::DeviceRemoved(const std::string& name) {
282 GCDDeviceMap::iterator found = known_devices_.find(kIDPrefixMdns + name); 284 GCDDeviceMap::iterator found = known_devices_.find(kIDPrefixMdns + name);
Ryan Sleevi 2015/10/30 23:17:27 BUG: Can't found == .end() under exceptional cases
Vitaly Buka (NO REVIEWS) 2015/10/31 03:55:35 Thanks. Quite possible. I suspect half of this fil
283 linked_ptr<gcd_private::GCDDevice> device = found->second; 285 linked_ptr<gcd_private::GCDDevice> device = found->second;
284 known_devices_.erase(found); 286 known_devices_.erase(found);
285 287
286 EventRouter::Get(browser_context_) 288 EventRouter::Get(browser_context_)
287 ->BroadcastEvent(MakeDeviceRemovedEvent(device->device_id)); 289 ->BroadcastEvent(MakeDeviceRemovedEvent(device->device_id));
288 } 290 }
289 291
290 void GcdPrivateAPIImpl::DeviceCacheFlushed() { 292 void GcdPrivateAPIImpl::DeviceCacheFlushed() {
291 for (GCDDeviceMap::iterator i = known_devices_.begin(); 293 for (GCDDeviceMap::iterator i = known_devices_.begin();
292 i != known_devices_.end(); 294 i != known_devices_.end();
(...skipping 17 matching lines...) Expand all
310 return false; 312 return false;
311 313
312 privet_device_lister_->DiscoverNewDevices(true); 314 privet_device_lister_->DiscoverNewDevices(true);
313 315
314 return true; 316 return true;
315 } 317 }
316 318
317 void GcdPrivateAPIImpl::CreateSession(const std::string& service_name, 319 void GcdPrivateAPIImpl::CreateSession(const std::string& service_name,
318 const CreateSessionCallback& callback) { 320 const CreateSessionCallback& callback) {
319 int session_id = last_session_id_++; 321 int session_id = last_session_id_++;
322 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
323 switches::kEnablePrivetV3)) {
324 return callback.Run(session_id, gcd_private::STATUS_SESSIONERROR,
325 base::DictionaryValue());
326 }
320 scoped_ptr<local_discovery::PrivetHTTPAsynchronousFactory> factory( 327 scoped_ptr<local_discovery::PrivetHTTPAsynchronousFactory> factory(
321 local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance( 328 local_discovery::PrivetHTTPAsynchronousFactory::CreateInstance(
322 browser_context_->GetRequestContext())); 329 browser_context_->GetRequestContext()));
323 auto& session_data = sessions_[session_id]; 330 auto& session_data = sessions_[session_id];
324 session_data.http_resolution.reset( 331 session_data.http_resolution.reset(
325 factory->CreatePrivetHTTP(service_name).release()); 332 factory->CreatePrivetHTTP(service_name).release());
326 session_data.http_resolution->Start( 333 session_data.http_resolution->Start(
327 base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, base::Unretained(this), 334 base::Bind(&GcdPrivateAPIImpl::OnServiceResolved, base::Unretained(this),
328 session_id, callback)); 335 session_id, callback));
329 } 336 }
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 } 889 }
883 890
884 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { 891 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() {
885 } 892 }
886 893
887 bool GcdPrivateGetCommandsListFunction::RunAsync() { 894 bool GcdPrivateGetCommandsListFunction::RunAsync() {
888 return false; 895 return false;
889 } 896 }
890 897
891 } // namespace extensions 898 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698