OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/dbus/experimental_bluetooth_profile_service_provider.h" | 5 #include "chromeos/dbus/experimental_bluetooth_profile_service_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/chromeos/chromeos_version.h" | 10 #include "base/chromeos/chromeos_version.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 // Called by dbus:: when the Bluetooth daemon establishes a new connection | 107 // Called by dbus:: when the Bluetooth daemon establishes a new connection |
108 // to the profile. | 108 // to the profile. |
109 void NewConnection(dbus::MethodCall* method_call, | 109 void NewConnection(dbus::MethodCall* method_call, |
110 dbus::ExportedObject::ResponseSender response_sender) { | 110 dbus::ExportedObject::ResponseSender response_sender) { |
111 DCHECK(OnOriginThread()); | 111 DCHECK(OnOriginThread()); |
112 DCHECK(delegate_); | 112 DCHECK(delegate_); |
113 | 113 |
114 dbus::MessageReader reader(method_call); | 114 dbus::MessageReader reader(method_call); |
115 dbus::ObjectPath device_path; | 115 dbus::ObjectPath device_path; |
116 dbus::FileDescriptor fd; | 116 scoped_ptr<dbus::FileDescriptor> fd(new dbus::FileDescriptor()); |
117 dbus::MessageReader array_reader(NULL); | 117 dbus::MessageReader array_reader(NULL); |
118 if (!reader.PopObjectPath(&device_path) || | 118 if (!reader.PopObjectPath(&device_path) || |
119 !reader.PopFileDescriptor(&fd) || | 119 !reader.PopFileDescriptor(fd.get()) || |
120 !reader.PopArray(&array_reader)) { | 120 !reader.PopArray(&array_reader)) { |
121 LOG(WARNING) << "NewConnection called with incorrect paramters: " | 121 LOG(WARNING) << "NewConnection called with incorrect paramters: " |
122 << method_call->ToString(); | 122 << method_call->ToString(); |
123 return; | 123 return; |
124 } | 124 } |
125 | 125 |
126 Delegate::Options options; | 126 Delegate::Options options; |
127 while (array_reader.HasMoreData()) { | 127 while (array_reader.HasMoreData()) { |
128 dbus::MessageReader dict_entry_reader(NULL); | 128 dbus::MessageReader dict_entry_reader(NULL); |
129 std::string key; | 129 std::string key; |
130 if (!array_reader.PopDictEntry(&dict_entry_reader) || | 130 if (!array_reader.PopDictEntry(&dict_entry_reader) || |
131 !dict_entry_reader.PopString(&key)) { | 131 !dict_entry_reader.PopString(&key)) { |
132 LOG(WARNING) << "NewConnection called with incorrect paramters: " | 132 LOG(WARNING) << "NewConnection called with incorrect paramters: " |
133 << method_call->ToString(); | 133 << method_call->ToString(); |
134 } else { | 134 } else { |
135 if (key == bluetooth_profile::kVersionProperty) | 135 if (key == bluetooth_profile::kVersionProperty) |
136 dict_entry_reader.PopVariantOfUint16(&options.version); | 136 dict_entry_reader.PopVariantOfUint16(&options.version); |
137 else if (key == bluetooth_profile::kFeaturesProperty) | 137 else if (key == bluetooth_profile::kFeaturesProperty) |
138 dict_entry_reader.PopVariantOfUint16(&options.features); | 138 dict_entry_reader.PopVariantOfUint16(&options.features); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 Delegate::ConfirmationCallback callback = base::Bind( | 142 Delegate::ConfirmationCallback callback = base::Bind( |
143 &ExperimentalBluetoothProfileServiceProviderImpl::OnConfirmation, | 143 &ExperimentalBluetoothProfileServiceProviderImpl::OnConfirmation, |
144 weak_ptr_factory_.GetWeakPtr(), | 144 weak_ptr_factory_.GetWeakPtr(), |
145 method_call, | 145 method_call, |
146 response_sender); | 146 response_sender); |
147 | 147 |
148 delegate_->NewConnection(device_path, &fd, options, callback); | 148 delegate_->NewConnection(device_path, fd.Pass(), options, callback); |
149 | |
150 response_sender.Run(dbus::Response::FromMethodCall(method_call)); | |
151 } | 149 } |
152 | 150 |
153 // Called by dbus:: when the Bluetooth daemon is about to disconnect the | 151 // Called by dbus:: when the Bluetooth daemon is about to disconnect the |
154 // profile. | 152 // profile. |
155 void RequestDisconnection( | 153 void RequestDisconnection( |
156 dbus::MethodCall* method_call, | 154 dbus::MethodCall* method_call, |
157 dbus::ExportedObject::ResponseSender response_sender) { | 155 dbus::ExportedObject::ResponseSender response_sender) { |
158 DCHECK(OnOriginThread()); | 156 DCHECK(OnOriginThread()); |
159 DCHECK(delegate_); | 157 DCHECK(delegate_); |
160 | 158 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 Delegate* delegate) { | 268 Delegate* delegate) { |
271 if (base::chromeos::IsRunningOnChromeOS()) { | 269 if (base::chromeos::IsRunningOnChromeOS()) { |
272 return new ExperimentalBluetoothProfileServiceProviderImpl( | 270 return new ExperimentalBluetoothProfileServiceProviderImpl( |
273 bus, object_path, delegate); | 271 bus, object_path, delegate); |
274 } else { | 272 } else { |
275 return new FakeBluetoothProfileServiceProvider(object_path, delegate); | 273 return new FakeBluetoothProfileServiceProvider(object_path, delegate); |
276 } | 274 } |
277 } | 275 } |
278 | 276 |
279 } // namespace chromeos | 277 } // namespace chromeos |
OLD | NEW |