| 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_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/extensions/api/experimental_bluetooth.h" | 10 #include "chrome/common/extensions/api/experimental_bluetooth.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 const char kFailedToConnect[] = "Connection failed"; | 46 const char kFailedToConnect[] = "Connection failed"; |
| 47 const char kInvalidDevice[] = "Invalid device"; | 47 const char kInvalidDevice[] = "Invalid device"; |
| 48 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; | 48 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; |
| 49 const char kStartDiscoveryFailed[] = |
| 50 "Starting discovery failed, or already discovering"; |
| 51 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; |
| 49 | 52 |
| 50 } // namespace | 53 } // namespace |
| 51 | 54 |
| 52 namespace Connect = extensions::api::experimental_bluetooth::Connect; | 55 namespace Connect = extensions::api::experimental_bluetooth::Connect; |
| 53 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; | 56 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; |
| 54 namespace GetDevicesWithServiceName = | 57 namespace GetDevicesWithServiceName = |
| 55 extensions::api::experimental_bluetooth::GetDevicesWithServiceName; | 58 extensions::api::experimental_bluetooth::GetDevicesWithServiceName; |
| 56 namespace GetDevicesWithServiceUUID = | 59 namespace GetDevicesWithServiceUUID = |
| 57 extensions::api::experimental_bluetooth::GetDevicesWithServiceUUID; | 60 extensions::api::experimental_bluetooth::GetDevicesWithServiceUUID; |
| 58 namespace Read = extensions::api::experimental_bluetooth::Read; | 61 namespace Read = extensions::api::experimental_bluetooth::Read; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 298 } |
| 296 | 299 |
| 297 if (!success_) | 300 if (!success_) |
| 298 SetError(safe_strerror(errsv)); | 301 SetError(safe_strerror(errsv)); |
| 299 } | 302 } |
| 300 | 303 |
| 301 bool BluetoothWriteFunction::Respond() { | 304 bool BluetoothWriteFunction::Respond() { |
| 302 return success_; | 305 return success_; |
| 303 } | 306 } |
| 304 | 307 |
| 308 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { |
| 309 SendResponse(true); |
| 310 Release(); // Added in RunImpl |
| 311 } |
| 312 |
| 313 void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
| 314 SetError(kStartDiscoveryFailed); |
| 315 SendResponse(false); |
| 316 Release(); // Added in RunImpl |
| 317 } |
| 318 |
| 319 bool BluetoothStartDiscoveryFunction::RunImpl() { |
| 320 GetEventRouter(profile())->SetSendDiscoveryEvents(true); |
| 321 |
| 322 // BluetoothAdapter will throw an error if we SetDiscovering(true) when |
| 323 // discovery is already in progress |
| 324 if (GetMutableAdapter(profile())->IsDiscovering()) { |
| 325 SendResponse(true); |
| 326 return true; |
| 327 } |
| 328 |
| 329 GetMutableAdapter(profile())->SetDiscovering(true, |
| 330 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
| 331 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
| 332 AddRef(); // Removed in whichever callback is called. |
| 333 return true; |
| 334 } |
| 335 |
| 336 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { |
| 337 SendResponse(true); |
| 338 Release(); // Added in RunImpl |
| 339 } |
| 340 |
| 341 void BluetoothStopDiscoveryFunction::OnErrorCallback() { |
| 342 SetError(kStopDiscoveryFailed); |
| 343 SendResponse(false); |
| 344 Release(); // Added in RunImpl |
| 345 } |
| 346 |
| 347 bool BluetoothStopDiscoveryFunction::RunImpl() { |
| 348 GetEventRouter(profile())->SetSendDiscoveryEvents(false); |
| 349 GetMutableAdapter(profile())->SetDiscovering(false, |
| 350 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
| 351 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
| 352 AddRef(); // Removed in whichever callback is called. |
| 353 return true; |
| 354 } |
| 355 |
| 305 #else | 356 #else |
| 306 | 357 |
| 307 // ----------------------------------------------------------------------------- | 358 // ----------------------------------------------------------------------------- |
| 308 // NIY stubs | 359 // NIY stubs |
| 309 // ----------------------------------------------------------------------------- | 360 // ----------------------------------------------------------------------------- |
| 310 bool BluetoothIsAvailableFunction::RunImpl() { | 361 bool BluetoothIsAvailableFunction::RunImpl() { |
| 311 NOTREACHED() << "Not implemented yet"; | 362 NOTREACHED() << "Not implemented yet"; |
| 312 return false; | 363 return false; |
| 313 } | 364 } |
| 314 | 365 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 410 } |
| 360 | 411 |
| 361 void BluetoothWriteFunction::Work() { | 412 void BluetoothWriteFunction::Work() { |
| 362 } | 413 } |
| 363 | 414 |
| 364 bool BluetoothWriteFunction::Respond() { | 415 bool BluetoothWriteFunction::Respond() { |
| 365 NOTREACHED() << "Not implemented yet"; | 416 NOTREACHED() << "Not implemented yet"; |
| 366 return false; | 417 return false; |
| 367 } | 418 } |
| 368 | 419 |
| 420 bool BluetoothStartDiscoveryFunction::RunImpl() { |
| 421 NOTREACHED() << "Not implemented yet"; |
| 422 return false; |
| 423 } |
| 424 |
| 425 bool BluetoothStopDiscoveryFunction::RunImpl() { |
| 426 NOTREACHED() << "Not implemented yet"; |
| 427 return false; |
| 428 } |
| 429 |
| 369 #endif | 430 #endif |
| 370 | 431 |
| 371 BluetoothReadFunction::BluetoothReadFunction() {} | 432 BluetoothReadFunction::BluetoothReadFunction() {} |
| 372 BluetoothReadFunction::~BluetoothReadFunction() {} | 433 BluetoothReadFunction::~BluetoothReadFunction() {} |
| 373 | 434 |
| 374 BluetoothWriteFunction::BluetoothWriteFunction() {} | 435 BluetoothWriteFunction::BluetoothWriteFunction() {} |
| 375 BluetoothWriteFunction::~BluetoothWriteFunction() {} | 436 BluetoothWriteFunction::~BluetoothWriteFunction() {} |
| 376 | 437 |
| 377 bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { | 438 bool BluetoothSetOutOfBandPairingDataFunction::RunImpl() { |
| 378 NOTREACHED() << "Not implemented yet"; | 439 NOTREACHED() << "Not implemented yet"; |
| 379 return false; | 440 return false; |
| 380 } | 441 } |
| 381 | 442 |
| 382 bool BluetoothGetOutOfBandPairingDataFunction::RunImpl() { | 443 bool BluetoothGetOutOfBandPairingDataFunction::RunImpl() { |
| 383 NOTREACHED() << "Not implemented yet"; | 444 NOTREACHED() << "Not implemented yet"; |
| 384 return false; | 445 return false; |
| 385 } | 446 } |
| 386 | 447 |
| 387 } // namespace api | 448 } // namespace api |
| 388 } // namespace extensions | 449 } // namespace extensions |
| OLD | NEW |