Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: device/bluetooth/bluetooth_discovery_session.h

Issue 184953002: Migrate Chrome OS Bluetooth UI to the new discovery API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by derat@ and keybuk@. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 18 matching lines...) Expand all
29 public: 29 public:
30 // The ErrorCallback is used by methods to asynchronously report errors. 30 // The ErrorCallback is used by methods to asynchronously report errors.
31 typedef base::Closure ErrorCallback; 31 typedef base::Closure ErrorCallback;
32 32
33 // Destructor automatically terminates the discovery session. If this 33 // Destructor automatically terminates the discovery session. If this
34 // results in a call to the underlying system to stop device discovery 34 // results in a call to the underlying system to stop device discovery
35 // (i.e. this instance represents the last active discovery session), 35 // (i.e. this instance represents the last active discovery session),
36 // the call may not always succeed. To be notified of such failures, 36 // the call may not always succeed. To be notified of such failures,
37 // users are highly encouraged to call BluetoothDiscoverySession::Stop, 37 // users are highly encouraged to call BluetoothDiscoverySession::Stop,
38 // instead of relying on the destructor. 38 // instead of relying on the destructor.
39 ~BluetoothDiscoverySession(); 39 virtual ~BluetoothDiscoverySession();
40 40
41 // Returns true if the session is active, false otherwise. If false, the 41 // Returns true if the session is active, false otherwise. If false, the
42 // adapter might still be discovering as there might still be other active 42 // adapter might still be discovering as there might still be other active
43 // sessions; this just means that this instance no longer has a say in 43 // sessions; this just means that this instance no longer has a say in
44 // whether or not discovery should continue. In this case, the application 44 // whether or not discovery should continue. In this case, the application
45 // should request a new BluetoothDiscoverySession to make sure that device 45 // should request a new BluetoothDiscoverySession to make sure that device
46 // discovery continues. 46 // discovery continues.
47 bool active() const { return active_; } 47 virtual bool IsActive() const;
48 48
49 // Requests this discovery session instance to stop. If this instance is 49 // Requests this discovery session instance to stop. If this instance is
50 // active, the session will stop. On success, |callback| is called and 50 // active, the session will stop. On success, |callback| is called and
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 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 private: 60 protected:
61 friend class BluetoothAdapter; 61 friend class BluetoothAdapter;
62 explicit BluetoothDiscoverySession(BluetoothAdapter* adapter); 62 explicit BluetoothDiscoverySession(BluetoothAdapter* adapter);
63 63
64 private:
64 // Internal callback invoked when a call to Stop has succeeded. 65 // Internal callback invoked when a call to Stop has succeeded.
65 void OnStop(const base::Closure& callback); 66 void OnStop(const base::Closure& callback);
66 67
67 // Marks this instance as inactive. Called by BluetoothAdapter to mark a 68 // Marks this instance as inactive. Called by BluetoothAdapter to mark a
68 // session as inactive in the case of an unexpected change to the adapter 69 // session as inactive in the case of an unexpected change to the adapter
69 // discovery state. 70 // discovery state.
70 void MarkAsInactive(); 71 void MarkAsInactive();
71 72
72 // Whether or not this instance represents an active discovery session. 73 // Whether or not this instance represents an active discovery session.
73 bool active_; 74 bool active_;
74 75
75 // The adapter that created this instance. 76 // The adapter that created this instance.
76 scoped_refptr<BluetoothAdapter> adapter_; 77 scoped_refptr<BluetoothAdapter> adapter_;
77 78
78 // Note: This should remain the last member so it'll be destroyed and 79 // Note: This should remain the last member so it'll be destroyed and
79 // invalidate its weak pointers before any other members are destroyed. 80 // invalidate its weak pointers before any other members are destroyed.
80 base::WeakPtrFactory<BluetoothDiscoverySession> weak_ptr_factory_; 81 base::WeakPtrFactory<BluetoothDiscoverySession> weak_ptr_factory_;
81 82
82 DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoverySession); 83 DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoverySession);
83 }; 84 };
84 85
85 } // namespace device 86 } // namespace device
86 87
87 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_SESSION_H_ 88 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_SESSION_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_chromeos_unittest.cc ('k') | device/bluetooth/bluetooth_discovery_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698