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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc

Issue 10815072: Bluetooth API: improve discovery (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 8 years, 4 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 (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 #if defined(OS_CHROMEOS) 7 #if defined(OS_CHROMEOS)
8 #include <errno.h> 8 #include <errno.h>
9 #endif 9 #endif
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 namespace { 45 namespace {
46 46
47 const char kCouldNotGetLocalOutOfBandPairingData[] = 47 const char kCouldNotGetLocalOutOfBandPairingData[] =
48 "Could not get local Out Of Band Pairing Data"; 48 "Could not get local Out Of Band Pairing Data";
49 const char kCouldNotSetOutOfBandPairingData[] = 49 const char kCouldNotSetOutOfBandPairingData[] =
50 "Could not set Out Of Band Pairing Data"; 50 "Could not set Out Of Band Pairing Data";
51 const char kFailedToConnect[] = "Connection failed"; 51 const char kFailedToConnect[] = "Connection failed";
52 const char kInvalidDevice[] = "Invalid device"; 52 const char kInvalidDevice[] = "Invalid device";
53 const char kServiceDiscoveryFailed[] = "Service discovery failed"; 53 const char kServiceDiscoveryFailed[] = "Service discovery failed";
54 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; 54 const char kSocketNotFoundError[] = "Socket not found: invalid socket id";
55 const char kStartDiscoveryFailed[] = 55 const char kStartDiscoveryFailed[] = "Starting discovery failed";
56 "Starting discovery failed, or already discovering";
57 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; 56 const char kStopDiscoveryFailed[] = "Failed to stop discovery";
58 57
59 } // namespace 58 } // namespace
60 59
61 namespace Connect = extensions::api::experimental_bluetooth::Connect; 60 namespace Connect = extensions::api::experimental_bluetooth::Connect;
62 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; 61 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect;
63 namespace GetDevices = extensions::api::experimental_bluetooth::GetDevices; 62 namespace GetDevices = extensions::api::experimental_bluetooth::GetDevices;
64 namespace GetServices = extensions::api::experimental_bluetooth::GetServices; 63 namespace GetServices = extensions::api::experimental_bluetooth::GetServices;
65 namespace Read = extensions::api::experimental_bluetooth::Read; 64 namespace Read = extensions::api::experimental_bluetooth::Read;
66 namespace SetOutOfBandPairingData = 65 namespace SetOutOfBandPairingData =
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() { 437 bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() {
439 GetMutableAdapter(profile())->ReadLocalOutOfBandPairingData( 438 GetMutableAdapter(profile())->ReadLocalOutOfBandPairingData(
440 base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback, 439 base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ReadCallback,
441 this), 440 this),
442 base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback, 441 base::Bind(&BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback,
443 this)); 442 this));
444 return true; 443 return true;
445 } 444 }
446 445
447 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { 446 void BluetoothStartDiscoveryFunction::OnSuccessCallback() {
447 GetEventRouter(profile())->SetResponsibleForDiscovery(true);
448 SendResponse(true); 448 SendResponse(true);
449 } 449 }
450 450
451 void BluetoothStartDiscoveryFunction::OnErrorCallback() { 451 void BluetoothStartDiscoveryFunction::OnErrorCallback() {
452 SetError(kStartDiscoveryFailed); 452 SetError(kStartDiscoveryFailed);
453 SendResponse(false); 453 SendResponse(false);
454 } 454 }
455 455
456 bool BluetoothStartDiscoveryFunction::RunImpl() { 456 bool BluetoothStartDiscoveryFunction::RunImpl() {
457 GetEventRouter(profile())->SetSendDiscoveryEvents(true); 457 GetEventRouter(profile())->SetSendDiscoveryEvents(true);
458 458
459 // BluetoothAdapter will throw an error if we SetDiscovering(true) when 459 // If the adapter is already discovering, there is nothing else to do.
460 // discovery is already in progress
461 if (GetMutableAdapter(profile())->IsDiscovering()) { 460 if (GetMutableAdapter(profile())->IsDiscovering()) {
462 SendResponse(true); 461 SendResponse(true);
463 return true; 462 return true;
464 } 463 }
465 464
466 GetMutableAdapter(profile())->SetDiscovering(true, 465 GetMutableAdapter(profile())->SetDiscovering(true,
467 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), 466 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this),
468 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); 467 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this));
469 return true; 468 return true;
470 } 469 }
471 470
472 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { 471 void BluetoothStopDiscoveryFunction::OnSuccessCallback() {
473 SendResponse(true); 472 SendResponse(true);
474 } 473 }
475 474
476 void BluetoothStopDiscoveryFunction::OnErrorCallback() { 475 void BluetoothStopDiscoveryFunction::OnErrorCallback() {
477 SetError(kStopDiscoveryFailed); 476 SetError(kStopDiscoveryFailed);
478 SendResponse(false); 477 SendResponse(false);
479 } 478 }
480 479
481 bool BluetoothStopDiscoveryFunction::RunImpl() { 480 bool BluetoothStopDiscoveryFunction::RunImpl() {
482 GetEventRouter(profile())->SetSendDiscoveryEvents(false); 481 GetEventRouter(profile())->SetSendDiscoveryEvents(false);
483 GetMutableAdapter(profile())->SetDiscovering(false, 482 if (GetEventRouter(profile())->IsResponsibleForDiscovery()) {
484 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), 483 GetMutableAdapter(profile())->SetDiscovering(false,
485 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); 484 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this),
485 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this));
486 }
486 return true; 487 return true;
487 } 488 }
488 489
489 #else 490 #else
490 491
491 // ----------------------------------------------------------------------------- 492 // -----------------------------------------------------------------------------
492 // NIY stubs 493 // NIY stubs
493 // ----------------------------------------------------------------------------- 494 // -----------------------------------------------------------------------------
494 bool BluetoothIsAvailableFunction::RunImpl() { 495 bool BluetoothIsAvailableFunction::RunImpl() {
495 NOTREACHED() << "Not implemented yet"; 496 NOTREACHED() << "Not implemented yet";
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 #endif 574 #endif
574 575
575 BluetoothReadFunction::BluetoothReadFunction() {} 576 BluetoothReadFunction::BluetoothReadFunction() {}
576 BluetoothReadFunction::~BluetoothReadFunction() {} 577 BluetoothReadFunction::~BluetoothReadFunction() {}
577 578
578 BluetoothWriteFunction::BluetoothWriteFunction() {} 579 BluetoothWriteFunction::BluetoothWriteFunction() {}
579 BluetoothWriteFunction::~BluetoothWriteFunction() {} 580 BluetoothWriteFunction::~BluetoothWriteFunction() {}
580 581
581 } // namespace api 582 } // namespace api
582 } // namespace extensions 583 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698