OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bluetooth/bluetooth_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" | 11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" |
12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
13 #include "chrome/browser/extensions/event_names.h" | 13 #include "chrome/browser/extensions/event_names.h" |
14 #include "chrome/browser/profiles/profile.h" | |
15 #include "chrome/common/extensions/api/bluetooth.h" | 14 #include "chrome/common/extensions/api/bluetooth.h" |
16 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" | 15 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" |
17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
18 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
19 #include "device/bluetooth/bluetooth_device.h" | 18 #include "device/bluetooth/bluetooth_device.h" |
20 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 19 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
21 #include "device/bluetooth/bluetooth_profile.h" | 20 #include "device/bluetooth/bluetooth_profile.h" |
22 #include "device/bluetooth/bluetooth_service_record.h" | 21 #include "device/bluetooth/bluetooth_service_record.h" |
23 #include "device/bluetooth/bluetooth_socket.h" | 22 #include "device/bluetooth/bluetooth_socket.h" |
24 #include "device/bluetooth/bluetooth_utils.h" | 23 #include "device/bluetooth/bluetooth_utils.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 ProfileKeyedAPIFactory<BluetoothAPI>* BluetoothAPI::GetFactoryInstance() { | 85 ProfileKeyedAPIFactory<BluetoothAPI>* BluetoothAPI::GetFactoryInstance() { |
87 return g_factory.Pointer(); | 86 return g_factory.Pointer(); |
88 } | 87 } |
89 | 88 |
90 // static | 89 // static |
91 BluetoothAPI* BluetoothAPI::Get(BrowserContext* context) { | 90 BluetoothAPI* BluetoothAPI::Get(BrowserContext* context) { |
92 return GetFactoryInstance()->GetForProfile(context); | 91 return GetFactoryInstance()->GetForProfile(context); |
93 } | 92 } |
94 | 93 |
95 BluetoothAPI::BluetoothAPI(BrowserContext* context) | 94 BluetoothAPI::BluetoothAPI(BrowserContext* context) |
96 : profile_(Profile::FromBrowserContext(context)) { | 95 : browser_context_(context) { |
97 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 96 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( |
98 this, bluetooth::OnAdapterStateChanged::kEventName); | 97 this, bluetooth::OnAdapterStateChanged::kEventName); |
99 } | 98 } |
100 | 99 |
101 BluetoothAPI::~BluetoothAPI() { | 100 BluetoothAPI::~BluetoothAPI() { |
102 } | 101 } |
103 | 102 |
104 ExtensionBluetoothEventRouter* BluetoothAPI::bluetooth_event_router() { | 103 ExtensionBluetoothEventRouter* BluetoothAPI::bluetooth_event_router() { |
105 if (!bluetooth_event_router_) | 104 if (!bluetooth_event_router_) |
106 bluetooth_event_router_.reset(new ExtensionBluetoothEventRouter(profile_)); | 105 bluetooth_event_router_.reset( |
| 106 new ExtensionBluetoothEventRouter(browser_context_)); |
107 | 107 |
108 return bluetooth_event_router_.get(); | 108 return bluetooth_event_router_.get(); |
109 } | 109 } |
110 | 110 |
111 void BluetoothAPI::Shutdown() { | 111 void BluetoothAPI::Shutdown() { |
112 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 112 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( |
| 113 this); |
113 } | 114 } |
114 | 115 |
115 void BluetoothAPI::OnListenerAdded(const EventListenerInfo& details) { | 116 void BluetoothAPI::OnListenerAdded(const EventListenerInfo& details) { |
116 if (bluetooth_event_router()->IsBluetoothSupported()) | 117 if (bluetooth_event_router()->IsBluetoothSupported()) |
117 bluetooth_event_router()->OnListenerAdded(); | 118 bluetooth_event_router()->OnListenerAdded(); |
118 } | 119 } |
119 | 120 |
120 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { | 121 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { |
121 if (bluetooth_event_router()->IsBluetoothSupported()) | 122 if (bluetooth_event_router()->IsBluetoothSupported()) |
122 bluetooth_event_router()->OnListenerRemoved(); | 123 bluetooth_event_router()->OnListenerRemoved(); |
(...skipping 14 matching lines...) Expand all Loading... |
137 } | 138 } |
138 | 139 |
139 BluetoothPermissionRequest param(params->profile.uuid); | 140 BluetoothPermissionRequest param(params->profile.uuid); |
140 if (!BluetoothManifestData::CheckRequest(GetExtension(), param)) { | 141 if (!BluetoothManifestData::CheckRequest(GetExtension(), param)) { |
141 error_ = kPermissionDenied; | 142 error_ = kPermissionDenied; |
142 return false; | 143 return false; |
143 } | 144 } |
144 | 145 |
145 uuid_ = device::bluetooth_utils::CanonicalUuid(params->profile.uuid); | 146 uuid_ = device::bluetooth_utils::CanonicalUuid(params->profile.uuid); |
146 | 147 |
147 if (GetEventRouter(GetProfile())->HasProfile(uuid_)) { | 148 if (GetEventRouter(browser_context())->HasProfile(uuid_)) { |
148 SetError(kProfileAlreadyRegistered); | 149 SetError(kProfileAlreadyRegistered); |
149 return false; | 150 return false; |
150 } | 151 } |
151 | 152 |
152 BluetoothProfile::Options options; | 153 BluetoothProfile::Options options; |
153 if (params->profile.name.get()) | 154 if (params->profile.name.get()) |
154 options.name = *params->profile.name.get(); | 155 options.name = *params->profile.name.get(); |
155 if (params->profile.channel.get()) | 156 if (params->profile.channel.get()) |
156 options.channel = *params->profile.channel.get(); | 157 options.channel = *params->profile.channel.get(); |
157 if (params->profile.psm.get()) | 158 if (params->profile.psm.get()) |
(...skipping 27 matching lines...) Expand all Loading... |
185 } | 186 } |
186 | 187 |
187 void BluetoothAddProfileFunction::OnProfileRegistered( | 188 void BluetoothAddProfileFunction::OnProfileRegistered( |
188 BluetoothProfile* bluetooth_profile) { | 189 BluetoothProfile* bluetooth_profile) { |
189 if (!bluetooth_profile) { | 190 if (!bluetooth_profile) { |
190 SetError(kProfileRegistrationFailed); | 191 SetError(kProfileRegistrationFailed); |
191 SendResponse(false); | 192 SendResponse(false); |
192 return; | 193 return; |
193 } | 194 } |
194 | 195 |
195 if (GetEventRouter(GetProfile())->HasProfile(uuid_)) { | 196 if (GetEventRouter(browser_context())->HasProfile(uuid_)) { |
196 bluetooth_profile->Unregister(); | 197 bluetooth_profile->Unregister(); |
197 SetError(kProfileAlreadyRegistered); | 198 SetError(kProfileAlreadyRegistered); |
198 SendResponse(false); | 199 SendResponse(false); |
199 return; | 200 return; |
200 } | 201 } |
201 | 202 |
202 bluetooth_profile->SetConnectionCallback( | 203 bluetooth_profile->SetConnectionCallback( |
203 base::Bind(&ExtensionBluetoothEventRouter::DispatchConnectionEvent, | 204 base::Bind(&ExtensionBluetoothEventRouter::DispatchConnectionEvent, |
204 base::Unretained(GetEventRouter(GetProfile())), | 205 base::Unretained(GetEventRouter(browser_context())), |
205 extension_id(), | 206 extension_id(), |
206 uuid_)); | 207 uuid_)); |
207 GetEventRouter(GetProfile())->AddProfile( | 208 GetEventRouter(browser_context()) |
208 uuid_, extension_id(), bluetooth_profile); | 209 ->AddProfile(uuid_, extension_id(), bluetooth_profile); |
209 SendResponse(true); | 210 SendResponse(true); |
210 } | 211 } |
211 | 212 |
212 bool BluetoothRemoveProfileFunction::RunImpl() { | 213 bool BluetoothRemoveProfileFunction::RunImpl() { |
213 scoped_ptr<RemoveProfile::Params> params( | 214 scoped_ptr<RemoveProfile::Params> params( |
214 RemoveProfile::Params::Create(*args_)); | 215 RemoveProfile::Params::Create(*args_)); |
215 | 216 |
216 if (!BluetoothDevice::IsUUIDValid(params->profile.uuid)) { | 217 if (!BluetoothDevice::IsUUIDValid(params->profile.uuid)) { |
217 SetError(kInvalidUuid); | 218 SetError(kInvalidUuid); |
218 return false; | 219 return false; |
219 } | 220 } |
220 | 221 |
221 std::string uuid = | 222 std::string uuid = |
222 device::bluetooth_utils::CanonicalUuid(params->profile.uuid); | 223 device::bluetooth_utils::CanonicalUuid(params->profile.uuid); |
223 | 224 |
224 if (!GetEventRouter(GetProfile())->HasProfile(uuid)) { | 225 if (!GetEventRouter(browser_context())->HasProfile(uuid)) { |
225 SetError(kProfileNotFound); | 226 SetError(kProfileNotFound); |
226 return false; | 227 return false; |
227 } | 228 } |
228 | 229 |
229 GetEventRouter(GetProfile())->RemoveProfile(uuid); | 230 GetEventRouter(browser_context())->RemoveProfile(uuid); |
230 return true; | 231 return true; |
231 } | 232 } |
232 | 233 |
233 // TODO(youngki): Implement. | 234 // TODO(youngki): Implement. |
234 bool BluetoothGetProfilesFunction::DoWork( | 235 bool BluetoothGetProfilesFunction::DoWork( |
235 scoped_refptr<device::BluetoothAdapter> adapter) { | 236 scoped_refptr<device::BluetoothAdapter> adapter) { |
236 scoped_ptr<GetProfiles::Params> params(GetProfiles::Params::Create(*args_)); | 237 scoped_ptr<GetProfiles::Params> params(GetProfiles::Params::Create(*args_)); |
237 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 238 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
238 const bluetooth::GetProfilesOptions& options = params->options; | 239 const bluetooth::GetProfilesOptions& options = params->options; |
239 | 240 |
(...skipping 30 matching lines...) Expand all Loading... |
270 return true; | 271 return true; |
271 } | 272 } |
272 | 273 |
273 BluetoothGetDevicesFunction::BluetoothGetDevicesFunction() | 274 BluetoothGetDevicesFunction::BluetoothGetDevicesFunction() |
274 : device_events_sent_(0) {} | 275 : device_events_sent_(0) {} |
275 | 276 |
276 void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( | 277 void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( |
277 const BluetoothDevice& device) { | 278 const BluetoothDevice& device) { |
278 bluetooth::Device extension_device; | 279 bluetooth::Device extension_device; |
279 bluetooth::BluetoothDeviceToApiDevice(device, &extension_device); | 280 bluetooth::BluetoothDeviceToApiDevice(device, &extension_device); |
280 GetEventRouter(GetProfile())->DispatchDeviceEvent( | 281 GetEventRouter(browser_context())->DispatchDeviceEvent( |
281 extensions::event_names::kBluetoothOnDeviceSearchResult, | 282 extensions::event_names::kBluetoothOnDeviceSearchResult, |
282 extension_device); | 283 extension_device); |
283 | 284 |
284 device_events_sent_++; | 285 device_events_sent_++; |
285 } | 286 } |
286 | 287 |
287 void BluetoothGetDevicesFunction::FinishDeviceSearch() { | 288 void BluetoothGetDevicesFunction::FinishDeviceSearch() { |
288 scoped_ptr<base::ListValue> args(new base::ListValue()); | 289 scoped_ptr<base::ListValue> args(new base::ListValue()); |
289 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue()); | 290 scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue()); |
290 info->SetInteger("expectedEventCount", device_events_sent_); | 291 info->SetInteger("expectedEventCount", device_events_sent_); |
291 args->Append(info.release()); | 292 args->Append(info.release()); |
292 | 293 |
293 scoped_ptr<extensions::Event> event(new extensions::Event( | 294 scoped_ptr<extensions::Event> event(new extensions::Event( |
294 extensions::event_names::kBluetoothOnDeviceSearchFinished, args.Pass())); | 295 extensions::event_names::kBluetoothOnDeviceSearchFinished, args.Pass())); |
295 extensions::ExtensionSystem::Get(GetProfile()) | 296 extensions::ExtensionSystem::Get(browser_context()) |
296 ->event_router() | 297 ->event_router() |
297 ->BroadcastEvent(event.Pass()); | 298 ->BroadcastEvent(event.Pass()); |
298 | 299 |
299 SendResponse(true); | 300 SendResponse(true); |
300 } | 301 } |
301 | 302 |
302 bool BluetoothGetDevicesFunction::DoWork( | 303 bool BluetoothGetDevicesFunction::DoWork( |
303 scoped_refptr<BluetoothAdapter> adapter) { | 304 scoped_refptr<BluetoothAdapter> adapter) { |
304 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 305 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
305 | 306 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if (!device) { | 404 if (!device) { |
404 SetError(kInvalidDevice); | 405 SetError(kInvalidDevice); |
405 SendResponse(false); | 406 SendResponse(false); |
406 return false; | 407 return false; |
407 } | 408 } |
408 | 409 |
409 std::string uuid = device::bluetooth_utils::CanonicalUuid( | 410 std::string uuid = device::bluetooth_utils::CanonicalUuid( |
410 options.profile.uuid); | 411 options.profile.uuid); |
411 | 412 |
412 BluetoothProfile* bluetooth_profile = | 413 BluetoothProfile* bluetooth_profile = |
413 GetEventRouter(GetProfile())->GetProfile(uuid); | 414 GetEventRouter(browser_context())->GetProfile(uuid); |
414 if (!bluetooth_profile) { | 415 if (!bluetooth_profile) { |
415 SetError(kProfileNotFound); | 416 SetError(kProfileNotFound); |
416 SendResponse(false); | 417 SendResponse(false); |
417 return false; | 418 return false; |
418 } | 419 } |
419 | 420 |
420 device->ConnectToProfile( | 421 device->ConnectToProfile( |
421 bluetooth_profile, | 422 bluetooth_profile, |
422 base::Bind(&BluetoothConnectFunction::OnSuccessCallback, this), | 423 base::Bind(&BluetoothConnectFunction::OnSuccessCallback, this), |
423 base::Bind(&BluetoothConnectFunction::OnErrorCallback, this)); | 424 base::Bind(&BluetoothConnectFunction::OnErrorCallback, this)); |
424 | 425 |
425 return true; | 426 return true; |
426 } | 427 } |
427 | 428 |
428 bool BluetoothDisconnectFunction::RunImpl() { | 429 bool BluetoothDisconnectFunction::RunImpl() { |
429 scoped_ptr<Disconnect::Params> params(Disconnect::Params::Create(*args_)); | 430 scoped_ptr<Disconnect::Params> params(Disconnect::Params::Create(*args_)); |
430 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 431 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
431 const bluetooth::DisconnectOptions& options = params->options; | 432 const bluetooth::DisconnectOptions& options = params->options; |
432 return GetEventRouter(GetProfile())->ReleaseSocket(options.socket.id); | 433 return GetEventRouter(browser_context())->ReleaseSocket(options.socket.id); |
433 } | 434 } |
434 | 435 |
435 BluetoothReadFunction::BluetoothReadFunction() : success_(false) {} | 436 BluetoothReadFunction::BluetoothReadFunction() : success_(false) {} |
436 BluetoothReadFunction::~BluetoothReadFunction() {} | 437 BluetoothReadFunction::~BluetoothReadFunction() {} |
437 | 438 |
438 bool BluetoothReadFunction::Prepare() { | 439 bool BluetoothReadFunction::Prepare() { |
439 scoped_ptr<Read::Params> params(Read::Params::Create(*args_)); | 440 scoped_ptr<Read::Params> params(Read::Params::Create(*args_)); |
440 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 441 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
441 const bluetooth::ReadOptions& options = params->options; | 442 const bluetooth::ReadOptions& options = params->options; |
442 | 443 |
443 socket_ = GetEventRouter(GetProfile())->GetSocket(options.socket.id); | 444 socket_ = GetEventRouter(browser_context())->GetSocket(options.socket.id); |
444 if (socket_.get() == NULL) { | 445 if (socket_.get() == NULL) { |
445 SetError(kSocketNotFoundError); | 446 SetError(kSocketNotFoundError); |
446 return false; | 447 return false; |
447 } | 448 } |
448 | 449 |
449 success_ = false; | 450 success_ = false; |
450 return true; | 451 return true; |
451 } | 452 } |
452 | 453 |
453 void BluetoothReadFunction::Work() { | 454 void BluetoothReadFunction::Work() { |
(...skipping 27 matching lines...) Expand all Loading... |
481 // support is added | 482 // support is added |
482 base::DictionaryValue* options; | 483 base::DictionaryValue* options; |
483 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); | 484 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); |
484 | 485 |
485 base::DictionaryValue* socket; | 486 base::DictionaryValue* socket; |
486 EXTENSION_FUNCTION_VALIDATE(options->GetDictionary("socket", &socket)); | 487 EXTENSION_FUNCTION_VALIDATE(options->GetDictionary("socket", &socket)); |
487 | 488 |
488 int socket_id; | 489 int socket_id; |
489 EXTENSION_FUNCTION_VALIDATE(socket->GetInteger("id", &socket_id)); | 490 EXTENSION_FUNCTION_VALIDATE(socket->GetInteger("id", &socket_id)); |
490 | 491 |
491 socket_ = GetEventRouter(GetProfile())->GetSocket(socket_id); | 492 socket_ = GetEventRouter(browser_context())->GetSocket(socket_id); |
492 if (socket_.get() == NULL) { | 493 if (socket_.get() == NULL) { |
493 SetError(kSocketNotFoundError); | 494 SetError(kSocketNotFoundError); |
494 return false; | 495 return false; |
495 } | 496 } |
496 | 497 |
497 base::BinaryValue* tmp_data; | 498 base::BinaryValue* tmp_data; |
498 EXTENSION_FUNCTION_VALIDATE(options->GetBinary("data", &tmp_data)); | 499 EXTENSION_FUNCTION_VALIDATE(options->GetBinary("data", &tmp_data)); |
499 data_to_write_ = tmp_data; | 500 data_to_write_ = tmp_data; |
500 | 501 |
501 success_ = false; | 502 success_ = false; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 628 |
628 return true; | 629 return true; |
629 } | 630 } |
630 | 631 |
631 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { | 632 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { |
632 SendResponse(true); | 633 SendResponse(true); |
633 } | 634 } |
634 | 635 |
635 void BluetoothStartDiscoveryFunction::OnErrorCallback() { | 636 void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
636 SetError(kStartDiscoveryFailed); | 637 SetError(kStartDiscoveryFailed); |
637 GetEventRouter(GetProfile())->SetResponsibleForDiscovery(false); | 638 GetEventRouter(browser_context())->SetResponsibleForDiscovery(false); |
638 SendResponse(false); | 639 SendResponse(false); |
639 GetEventRouter(GetProfile())->OnListenerRemoved(); | 640 GetEventRouter(browser_context())->OnListenerRemoved(); |
640 } | 641 } |
641 | 642 |
642 bool BluetoothStartDiscoveryFunction::DoWork( | 643 bool BluetoothStartDiscoveryFunction::DoWork( |
643 scoped_refptr<BluetoothAdapter> adapter) { | 644 scoped_refptr<BluetoothAdapter> adapter) { |
644 GetEventRouter(GetProfile())->SetSendDiscoveryEvents(true); | 645 GetEventRouter(browser_context())->SetSendDiscoveryEvents(true); |
645 | 646 |
646 // If this profile is already discovering devices, there should be nothing | 647 // If this profile is already discovering devices, there should be nothing |
647 // else to do. | 648 // else to do. |
648 if (!GetEventRouter(GetProfile())->IsResponsibleForDiscovery()) { | 649 if (!GetEventRouter(browser_context())->IsResponsibleForDiscovery()) { |
649 GetEventRouter(GetProfile())->SetResponsibleForDiscovery(true); | 650 GetEventRouter(browser_context())->SetResponsibleForDiscovery(true); |
650 GetEventRouter(GetProfile())->OnListenerAdded(); | 651 GetEventRouter(browser_context())->OnListenerAdded(); |
651 adapter->StartDiscovering( | 652 adapter->StartDiscovering( |
652 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), | 653 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
653 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); | 654 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
654 } | 655 } |
655 | 656 |
656 return true; | 657 return true; |
657 } | 658 } |
658 | 659 |
659 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { | 660 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { |
660 SendResponse(true); | 661 SendResponse(true); |
661 GetEventRouter(GetProfile())->OnListenerRemoved(); | 662 GetEventRouter(browser_context())->OnListenerRemoved(); |
662 } | 663 } |
663 | 664 |
664 void BluetoothStopDiscoveryFunction::OnErrorCallback() { | 665 void BluetoothStopDiscoveryFunction::OnErrorCallback() { |
665 SetError(kStopDiscoveryFailed); | 666 SetError(kStopDiscoveryFailed); |
666 GetEventRouter(GetProfile())->SetResponsibleForDiscovery(true); | 667 GetEventRouter(browser_context())->SetResponsibleForDiscovery(true); |
667 SendResponse(false); | 668 SendResponse(false); |
668 GetEventRouter(GetProfile())->OnListenerRemoved(); | 669 GetEventRouter(browser_context())->OnListenerRemoved(); |
669 } | 670 } |
670 | 671 |
671 bool BluetoothStopDiscoveryFunction::DoWork( | 672 bool BluetoothStopDiscoveryFunction::DoWork( |
672 scoped_refptr<BluetoothAdapter> adapter) { | 673 scoped_refptr<BluetoothAdapter> adapter) { |
673 GetEventRouter(GetProfile())->SetSendDiscoveryEvents(false); | 674 GetEventRouter(browser_context())->SetSendDiscoveryEvents(false); |
674 if (GetEventRouter(GetProfile())->IsResponsibleForDiscovery()) { | 675 if (GetEventRouter(browser_context())->IsResponsibleForDiscovery()) { |
675 adapter->StopDiscovering( | 676 adapter->StopDiscovering( |
676 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 677 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
677 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 678 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
678 } | 679 } |
679 | 680 |
680 return true; | 681 return true; |
681 } | 682 } |
682 | 683 |
683 } // namespace api | 684 } // namespace api |
684 } // namespace extensions | 685 } // namespace extensions |
OLD | NEW |