| 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_extension_function.h
    " | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h
    " | 
| 6 | 6 | 
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" | 
| 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 
| 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" | 
| 11 #include "device/bluetooth/bluetooth_adapter.h" | 11 #include "device/bluetooth/bluetooth_adapter.h" | 
| 12 #include "device/bluetooth/bluetooth_adapter_factory.h" | 12 #include "device/bluetooth/bluetooth_adapter_factory.h" | 
| 13 | 13 | 
| 14 namespace { | 14 namespace { | 
| 15 | 15 | 
| 16 const char kPlatformNotSupported[] = | 16 const char kPlatformNotSupported[] = | 
| 17     "This operation is not supported on your platform"; | 17     "This operation is not supported on your platform"; | 
| 18 | 18 | 
| 19 extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { | 19 extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) { | 
| 20   return extensions::BluetoothAPI::Get(profile)->bluetooth_event_router(); | 20   return extensions::BluetoothAPI::Get(profile)->bluetooth_event_router(); | 
| 21 } | 21 } | 
| 22 | 22 | 
| 23 bool IsBluetoothSupported(Profile* profile) { | 23 bool IsBluetoothSupported(Profile* profile) { | 
| 24   return GetEventRouter(profile)->IsBluetoothSupported(); | 24   return GetEventRouter(profile)->IsBluetoothSupported(); | 
| 25 } | 25 } | 
| 26 | 26 | 
| 27 void RunCallbackOnAdapterReady( | 27 void GetAdapter( | 
| 28     const device::BluetoothAdapter::AdapterCallback callback, | 28     const device::BluetoothAdapterFactory::AdapterCallback callback, | 
| 29     Profile* profile) { | 29     Profile* profile) { | 
| 30   GetEventRouter(profile)->RunCallbackOnAdapterReady(callback); | 30   GetEventRouter(profile)->GetAdapter(callback); | 
| 31 } | 31 } | 
| 32 | 32 | 
| 33 }  // namespace | 33 }  // namespace | 
| 34 | 34 | 
| 35 namespace extensions { | 35 namespace extensions { | 
| 36 | 36 | 
| 37 namespace api { | 37 namespace api { | 
| 38 | 38 | 
| 39 BluetoothExtensionFunction::BluetoothExtensionFunction() | 39 BluetoothExtensionFunction::BluetoothExtensionFunction() { | 
| 40     : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |  | 
| 41 } | 40 } | 
| 42 | 41 | 
| 43 BluetoothExtensionFunction::~BluetoothExtensionFunction() { | 42 BluetoothExtensionFunction::~BluetoothExtensionFunction() { | 
| 44 } | 43 } | 
| 45 | 44 | 
| 46 bool BluetoothExtensionFunction::RunImpl() { | 45 bool BluetoothExtensionFunction::RunImpl() { | 
| 47   if (!IsBluetoothSupported(profile())) { | 46   if (!IsBluetoothSupported(profile())) { | 
| 48     SetError(kPlatformNotSupported); | 47     SetError(kPlatformNotSupported); | 
| 49     return false; | 48     return false; | 
| 50   } | 49   } | 
| 51   RunCallbackOnAdapterReady( | 50   GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this), | 
| 52       base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, | 51              profile()); | 
| 53                  weak_ptr_factory_.GetWeakPtr()), | 52 | 
| 54       profile()); |  | 
| 55   return true; | 53   return true; | 
| 56 } | 54 } | 
| 57 | 55 | 
| 58 void BluetoothExtensionFunction::RunOnAdapterReady( | 56 void BluetoothExtensionFunction::RunOnAdapterReady( | 
| 59     scoped_refptr<device::BluetoothAdapter> adapter) { | 57     scoped_refptr<device::BluetoothAdapter> adapter) { | 
| 60   DoWork(adapter); | 58   DoWork(adapter); | 
| 61 } | 59 } | 
| 62 | 60 | 
| 63 }  // namespace api | 61 }  // namespace api | 
| 64 | 62 | 
| 65 }  // namespace extensions | 63 }  // namespace extensions | 
| OLD | NEW | 
|---|