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