OLD | NEW |
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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_SESSION_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_SESSION_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_SESSION_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_SESSION_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // on error |error_callback| is called. After a successful invocation, the | 51 // on error |error_callback| is called. After a successful invocation, the |
52 // adapter may or may not stop device discovery, depending on whether or not | 52 // adapter may or may not stop device discovery, depending on whether or not |
53 // other active discovery sessions are present. Users are highly encouraged | 53 // other active discovery sessions are present. Users are highly encouraged |
54 // to call this method to end a discovery session, instead of relying on the | 54 // to call this method to end a discovery session, instead of relying on the |
55 // destructor, so that they can be notified of the result via the callback | 55 // destructor, so that they can be notified of the result via the callback |
56 // arguments. | 56 // arguments. |
57 virtual void Stop(const base::Closure& callback, | 57 virtual void Stop(const base::Closure& callback, |
58 const ErrorCallback& error_callback); | 58 const ErrorCallback& error_callback); |
59 | 59 |
60 protected: | 60 protected: |
61 friend class BluetoothAdapter; | 61 BluetoothDiscoverySession(); // Called by mock. |
62 explicit BluetoothDiscoverySession(BluetoothAdapter* adapter); | |
63 | 62 |
64 private: | 63 private: |
| 64 friend class BluetoothAdapter; |
| 65 explicit BluetoothDiscoverySession(scoped_refptr<BluetoothAdapter> adapter); |
| 66 |
65 // Internal callback invoked when a call to Stop has succeeded. | 67 // Internal callback invoked when a call to Stop has succeeded. |
66 void OnStop(const base::Closure& callback); | 68 void OnStop(const base::Closure& callback); |
67 | 69 |
68 // Marks this instance as inactive. Called by BluetoothAdapter to mark a | 70 // Marks this instance as inactive. Called by BluetoothAdapter to mark a |
69 // session as inactive in the case of an unexpected change to the adapter | 71 // session as inactive in the case of an unexpected change to the adapter |
70 // discovery state. | 72 // discovery state. |
71 void MarkAsInactive(); | 73 void MarkAsInactive(); |
72 | 74 |
73 // Whether or not this instance represents an active discovery session. | 75 // Whether or not this instance represents an active discovery session. |
74 bool active_; | 76 bool active_; |
75 | 77 |
76 // The adapter that created this instance. | 78 // The adapter that created this instance. |
77 scoped_refptr<BluetoothAdapter> adapter_; | 79 scoped_refptr<BluetoothAdapter> adapter_; |
78 | 80 |
79 // Note: This should remain the last member so it'll be destroyed and | 81 // Note: This should remain the last member so it'll be destroyed and |
80 // invalidate its weak pointers before any other members are destroyed. | 82 // invalidate its weak pointers before any other members are destroyed. |
81 base::WeakPtrFactory<BluetoothDiscoverySession> weak_ptr_factory_; | 83 base::WeakPtrFactory<BluetoothDiscoverySession> weak_ptr_factory_; |
82 | 84 |
83 DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoverySession); | 85 DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoverySession); |
84 }; | 86 }; |
85 | 87 |
86 } // namespace device | 88 } // namespace device |
87 | 89 |
88 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_SESSION_H_ | 90 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_SESSION_H_ |
OLD | NEW |