| 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_event_router.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 bool BluetoothEventRouter::ReleaseSocket(int id) { | 104 bool BluetoothEventRouter::ReleaseSocket(int id) { |
| 105 SocketMap::iterator socket_entry = socket_map_.find(id); | 105 SocketMap::iterator socket_entry = socket_map_.find(id); |
| 106 if (socket_entry == socket_map_.end()) | 106 if (socket_entry == socket_map_.end()) |
| 107 return false; | 107 return false; |
| 108 socket_map_.erase(socket_entry); | 108 socket_map_.erase(socket_entry); |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void BluetoothEventRouter::AddProfile( | 112 void BluetoothEventRouter::AddProfile( |
| 113 const std::string& uuid, | 113 const device::BluetoothUUID& uuid, |
| 114 const std::string& extension_id, | 114 const std::string& extension_id, |
| 115 device::BluetoothProfile* bluetooth_profile) { | 115 device::BluetoothProfile* bluetooth_profile) { |
| 116 DCHECK(!HasProfile(uuid)); | 116 DCHECK(!HasProfile(uuid)); |
| 117 ExtensionBluetoothProfileRecord record = { extension_id, bluetooth_profile }; | 117 ExtensionBluetoothProfileRecord record = { extension_id, bluetooth_profile }; |
| 118 bluetooth_profile_map_[uuid] = record; | 118 bluetooth_profile_map_[uuid] = record; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void BluetoothEventRouter::RemoveProfile(const std::string& uuid) { | 121 void BluetoothEventRouter::RemoveProfile(const device::BluetoothUUID& uuid) { |
| 122 BluetoothProfileMap::iterator iter = bluetooth_profile_map_.find(uuid); | 122 BluetoothProfileMap::iterator iter = bluetooth_profile_map_.find(uuid); |
| 123 if (iter != bluetooth_profile_map_.end()) { | 123 if (iter != bluetooth_profile_map_.end()) { |
| 124 device::BluetoothProfile* bluetooth_profile = iter->second.profile; | 124 device::BluetoothProfile* bluetooth_profile = iter->second.profile; |
| 125 bluetooth_profile_map_.erase(iter); | 125 bluetooth_profile_map_.erase(iter); |
| 126 bluetooth_profile->Unregister(); | 126 bluetooth_profile->Unregister(); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool BluetoothEventRouter::HasProfile(const std::string& uuid) const { | 130 bool BluetoothEventRouter::HasProfile(const device::BluetoothUUID& uuid) const { |
| 131 return bluetooth_profile_map_.find(uuid) != bluetooth_profile_map_.end(); | 131 return bluetooth_profile_map_.find(uuid) != bluetooth_profile_map_.end(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void BluetoothEventRouter::StartDiscoverySession( | 134 void BluetoothEventRouter::StartDiscoverySession( |
| 135 device::BluetoothAdapter* adapter, | 135 device::BluetoothAdapter* adapter, |
| 136 const std::string& extension_id, | 136 const std::string& extension_id, |
| 137 const base::Closure& callback, | 137 const base::Closure& callback, |
| 138 const base::Closure& error_callback) { | 138 const base::Closure& error_callback) { |
| 139 if (adapter != adapter_.get()) { | 139 if (adapter != adapter_.get()) { |
| 140 error_callback.Run(); | 140 error_callback.Run(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 169 if (iter == discovery_session_map_.end() || !iter->second->IsActive()) { | 169 if (iter == discovery_session_map_.end() || !iter->second->IsActive()) { |
| 170 DVLOG(1) << "No active discovery session exists for extension."; | 170 DVLOG(1) << "No active discovery session exists for extension."; |
| 171 error_callback.Run(); | 171 error_callback.Run(); |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 device::BluetoothDiscoverySession* session = iter->second; | 174 device::BluetoothDiscoverySession* session = iter->second; |
| 175 session->Stop(callback, error_callback); | 175 session->Stop(callback, error_callback); |
| 176 } | 176 } |
| 177 | 177 |
| 178 device::BluetoothProfile* BluetoothEventRouter::GetProfile( | 178 device::BluetoothProfile* BluetoothEventRouter::GetProfile( |
| 179 const std::string& uuid) const { | 179 const device::BluetoothUUID& uuid) const { |
| 180 BluetoothProfileMap::const_iterator iter = bluetooth_profile_map_.find(uuid); | 180 BluetoothProfileMap::const_iterator iter = bluetooth_profile_map_.find(uuid); |
| 181 if (iter != bluetooth_profile_map_.end()) | 181 if (iter != bluetooth_profile_map_.end()) |
| 182 return iter->second.profile; | 182 return iter->second.profile; |
| 183 | 183 |
| 184 return NULL; | 184 return NULL; |
| 185 } | 185 } |
| 186 | 186 |
| 187 scoped_refptr<device::BluetoothSocket> BluetoothEventRouter::GetSocket(int id) { | 187 scoped_refptr<device::BluetoothSocket> BluetoothEventRouter::GetSocket(int id) { |
| 188 SocketMap::iterator socket_entry = socket_map_.find(id); | 188 SocketMap::iterator socket_entry = socket_map_.find(id); |
| 189 if (socket_entry == socket_map_.end()) | 189 if (socket_entry == socket_map_.end()) |
| 190 return NULL; | 190 return NULL; |
| 191 return socket_entry->second.socket; | 191 return socket_entry->second.socket; |
| 192 } | 192 } |
| 193 | 193 |
| 194 void BluetoothEventRouter::DispatchConnectionEvent( | 194 void BluetoothEventRouter::DispatchConnectionEvent( |
| 195 const std::string& extension_id, | 195 const std::string& extension_id, |
| 196 const std::string& uuid, | 196 const device::BluetoothUUID& uuid, |
| 197 const device::BluetoothDevice* device, | 197 const device::BluetoothDevice* device, |
| 198 scoped_refptr<device::BluetoothSocket> socket) { | 198 scoped_refptr<device::BluetoothSocket> socket) { |
| 199 if (!HasProfile(uuid)) | 199 if (!HasProfile(uuid)) |
| 200 return; | 200 return; |
| 201 | 201 |
| 202 int socket_id = RegisterSocket(extension_id, socket); | 202 int socket_id = RegisterSocket(extension_id, socket); |
| 203 bluetooth::Socket result_socket; | 203 bluetooth::Socket result_socket; |
| 204 bluetooth::BluetoothDeviceToApiDevice(*device, &result_socket.device); | 204 bluetooth::BluetoothDeviceToApiDevice(*device, &result_socket.device); |
| 205 result_socket.profile.uuid = uuid; | 205 result_socket.profile.uuid = uuid.canonical_value(); |
| 206 result_socket.id = socket_id; | 206 result_socket.id = socket_id; |
| 207 | 207 |
| 208 scoped_ptr<base::ListValue> args = | 208 scoped_ptr<base::ListValue> args = |
| 209 bluetooth::OnConnection::Create(result_socket); | 209 bluetooth::OnConnection::Create(result_socket); |
| 210 scoped_ptr<Event> event(new Event( | 210 scoped_ptr<Event> event(new Event( |
| 211 bluetooth::OnConnection::kEventName, args.Pass())); | 211 bluetooth::OnConnection::kEventName, args.Pass())); |
| 212 ExtensionSystem::Get(browser_context_) | 212 ExtensionSystem::Get(browser_context_) |
| 213 ->event_router() | 213 ->event_router() |
| 214 ->DispatchEventToExtension(extension_id, event.Pass()); | 214 ->DispatchEventToExtension(extension_id, event.Pass()); |
| 215 } | 215 } |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 478 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
| 479 extensions::UnloadedExtensionInfo* info = | 479 extensions::UnloadedExtensionInfo* info = |
| 480 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 480 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
| 481 CleanUpForExtension(info->extension->id()); | 481 CleanUpForExtension(info->extension->id()); |
| 482 break; | 482 break; |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 | 486 |
| 487 } // namespace extensions | 487 } // namespace extensions |
| OLD | NEW |