| 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" |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 628 |
| 629 return true; | 629 return true; |
| 630 } | 630 } |
| 631 | 631 |
| 632 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { | 632 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { |
| 633 SendResponse(true); | 633 SendResponse(true); |
| 634 } | 634 } |
| 635 | 635 |
| 636 void BluetoothStartDiscoveryFunction::OnErrorCallback() { | 636 void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
| 637 SetError(kStartDiscoveryFailed); | 637 SetError(kStartDiscoveryFailed); |
| 638 GetEventRouter(browser_context())->SetResponsibleForDiscovery(false); | |
| 639 SendResponse(false); | 638 SendResponse(false); |
| 640 GetEventRouter(browser_context())->OnListenerRemoved(); | 639 GetEventRouter(browser_context())->OnListenerRemoved(); |
| 641 } | 640 } |
| 642 | 641 |
| 643 bool BluetoothStartDiscoveryFunction::DoWork( | 642 bool BluetoothStartDiscoveryFunction::DoWork( |
| 644 scoped_refptr<BluetoothAdapter> adapter) { | 643 scoped_refptr<BluetoothAdapter> adapter) { |
| 645 GetEventRouter(browser_context())->SetSendDiscoveryEvents(true); | 644 GetEventRouter(browser_context())->OnListenerAdded(); |
| 646 | 645 GetEventRouter(browser_context())->AddDiscoverySession( |
| 647 // If this profile is already discovering devices, there should be nothing | 646 adapter, |
| 648 // else to do. | 647 extension_id(), |
| 649 if (!GetEventRouter(browser_context())->IsResponsibleForDiscovery()) { | 648 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
| 650 GetEventRouter(browser_context())->SetResponsibleForDiscovery(true); | 649 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
| 651 GetEventRouter(browser_context())->OnListenerAdded(); | |
| 652 adapter->StartDiscovering( | |
| 653 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), | |
| 654 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); | |
| 655 } | |
| 656 | 650 |
| 657 return true; | 651 return true; |
| 658 } | 652 } |
| 659 | 653 |
| 660 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { | 654 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { |
| 661 SendResponse(true); | 655 SendResponse(true); |
| 662 GetEventRouter(browser_context())->OnListenerRemoved(); | 656 GetEventRouter(browser_context())->OnListenerRemoved(); |
| 663 } | 657 } |
| 664 | 658 |
| 665 void BluetoothStopDiscoveryFunction::OnErrorCallback() { | 659 void BluetoothStopDiscoveryFunction::OnErrorCallback() { |
| 666 SetError(kStopDiscoveryFailed); | 660 SetError(kStopDiscoveryFailed); |
| 667 GetEventRouter(browser_context())->SetResponsibleForDiscovery(true); | |
| 668 SendResponse(false); | 661 SendResponse(false); |
| 669 GetEventRouter(browser_context())->OnListenerRemoved(); | 662 GetEventRouter(browser_context())->OnListenerRemoved(); |
| 670 } | 663 } |
| 671 | 664 |
| 672 bool BluetoothStopDiscoveryFunction::DoWork( | 665 bool BluetoothStopDiscoveryFunction::DoWork( |
| 673 scoped_refptr<BluetoothAdapter> adapter) { | 666 scoped_refptr<BluetoothAdapter> adapter) { |
| 674 GetEventRouter(browser_context())->SetSendDiscoveryEvents(false); | 667 GetEventRouter(browser_context())->RemoveDiscoverySession( |
| 675 if (GetEventRouter(browser_context())->IsResponsibleForDiscovery()) { | 668 adapter, |
| 676 adapter->StopDiscovering( | 669 extension_id(), |
| 677 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 670 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
| 678 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 671 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
| 679 } | |
| 680 | 672 |
| 681 return true; | 673 return true; |
| 682 } | 674 } |
| 683 | 675 |
| 684 } // namespace api | 676 } // namespace api |
| 685 } // namespace extensions | 677 } // namespace extensions |
| OLD | NEW |