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

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

Issue 276573004: Bluetooth: Implement new socket API for Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DCHECK nits Created 6 years, 7 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
« no previous file with comments | « device/bluetooth/bluetooth_profile.cc ('k') | device/bluetooth/bluetooth_profile_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/sequenced_task_runner.h"
15 #include "chromeos/chromeos_export.h"
16 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
17 #include "chromeos/dbus/bluetooth_profile_service_provider.h"
18 #include "dbus/object_path.h"
19 #include "device/bluetooth/bluetooth_adapter.h"
20 #include "device/bluetooth/bluetooth_profile.h"
21 #include "device/bluetooth/bluetooth_uuid.h"
22
23 namespace dbus {
24
25 class FileDescriptor;
26
27 } // namespace dbus
28
29 namespace device {
30 class BluetoothSocketThread;
31 } // namespace device
32
33 namespace chromeos {
34
35 class BluetoothSocketChromeOS;
36
37 // The BluetoothProfileChromeOS class implements BluetoothProfile for the
38 // Chrome OS platform.
39 class CHROMEOS_EXPORT BluetoothProfileChromeOS
40 : public device::BluetoothProfile,
41 public device::BluetoothAdapter::Observer,
42 public BluetoothProfileServiceProvider::Delegate {
43 public:
44 // BluetoothProfile override.
45 virtual void Unregister() OVERRIDE;
46 virtual void SetConnectionCallback(
47 const ConnectionCallback& callback) OVERRIDE;
48
49 // Return the UUID of the profile.
50 const device::BluetoothUUID& uuid() const { return uuid_; }
51
52 private:
53 friend class BluetoothProfile;
54
55 BluetoothProfileChromeOS(
56 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
57 scoped_refptr<device::BluetoothSocketThread> socket_thread);
58 virtual ~BluetoothProfileChromeOS();
59
60 // Called by BluetoothProfile::Register to initialize the profile object
61 // asynchronously. |uuid|, |options| and |callback| are the arguments to
62 // BluetoothProfile::Register.
63 void Init(const device::BluetoothUUID& uuid,
64 const device::BluetoothProfile::Options& options,
65 const ProfileCallback& callback);
66
67 // BluetoothProfileServiceProvider::Delegate override.
68 virtual void Released() OVERRIDE;
69 virtual void NewConnection(
70 const dbus::ObjectPath& device_path,
71 scoped_ptr<dbus::FileDescriptor> fd,
72 const BluetoothProfileServiceProvider::Delegate::Options& options,
73 const ConfirmationCallback& callback) OVERRIDE;
74 virtual void RequestDisconnection(
75 const dbus::ObjectPath& device_path,
76 const ConfirmationCallback& callback) OVERRIDE;
77 virtual void Cancel() OVERRIDE;
78
79 // device::BluetoothAdapter::Observer override.
80 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter,
81 bool present) OVERRIDE;
82
83 // Called by dbus:: on completion of the D-Bus method call to register the
84 // profile object as a result of the adapter becoming present.
85 void OnInternalRegisterProfile();
86 void OnInternalRegisterProfileError(const std::string& error_name,
87 const std::string& error_message);
88
89 // Internal method run to get the adapter object during initialization.
90 void OnGetAdapter(const ProfileCallback& callback,
91 scoped_refptr<device::BluetoothAdapter> adapter);
92
93 // Called by dbus:: on completion of the D-Bus method call to register the
94 // profile object during initialization.
95 void OnRegisterProfile(const ProfileCallback& callback);
96 void OnRegisterProfileError(const ProfileCallback& callback,
97 const std::string& error_name,
98 const std::string& error_message);
99
100 // Called by dbus:: on completion of the D-Bus method call to unregister
101 // the profile object.
102 void OnUnregisterProfile();
103 void OnUnregisterProfileError(const std::string& error_name,
104 const std::string& error_message);
105
106 // Method run once the file descriptor has been validated in order to get
107 // the device object to be passed to the connection callback.
108 //
109 // The |fd| argument is moved compared to the NewConnection() call since it
110 // becomes the result of a PostTaskAndReplyWithResult() call.
111 void OnCheckValidity(
112 const dbus::ObjectPath& device_path,
113 const BluetoothProfileServiceProvider::Delegate::Options& options,
114 const ConfirmationCallback& callback,
115 scoped_ptr<dbus::FileDescriptor> fd);
116
117 // Methods run after the socket has been connected to a
118 // BluetoothSocketChromeOS instance on the I/O thread, these methods complete
119 // the incoming connection calling both the Bluetooth daemon callback
120 // |callback| to indicate success or failure and calling this object's
121 // new connection callback method.
122 void OnConnect(const dbus::ObjectPath& device_path,
123 scoped_refptr<BluetoothSocketChromeOS> socket,
124 const ConfirmationCallback& callback);
125 void OnConnectError(const ConfirmationCallback& callback,
126 const std::string& error_message);
127
128 // UUID of the profile passed during initialization.
129 device::BluetoothUUID uuid_;
130
131 // Copy of the profile options passed during initialization.
132 BluetoothProfileManagerClient::Options options_;
133
134 // Object path of the local profile D-Bus object.
135 dbus::ObjectPath object_path_;
136
137 // Local profile D-Bus object used for receiving profile delegate methods
138 // from BlueZ.
139 scoped_ptr<BluetoothProfileServiceProvider> profile_;
140
141 // Reference to the adapter object, the profile is re-registered when the
142 // adapter changes.
143 scoped_refptr<device::BluetoothAdapter> adapter_;
144
145 // Callback used on both outgoing and incoming connections to pass the
146 // connected socket to profile object owner.
147 ConnectionCallback connection_callback_;
148
149 // UI thread task runner and socket thread object used to create sockets.
150 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
151 scoped_refptr<device::BluetoothSocketThread> socket_thread_;
152
153 // Note: This should remain the last member so it'll be destroyed and
154 // invalidate its weak pointers before any other members are destroyed.
155 base::WeakPtrFactory<BluetoothProfileChromeOS> weak_ptr_factory_;
156
157 DISALLOW_COPY_AND_ASSIGN(BluetoothProfileChromeOS);
158 };
159
160 } // namespace chromeos
161
162 #endif // DEVICE_BLUETOOTH_BLUETOOTH_PROFILE_CHROMEOS_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_profile.cc ('k') | device/bluetooth/bluetooth_profile_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698