| 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/containers/scoped_ptr_hash_map.h" | 17 #include "base/containers/scoped_ptr_hash_map.h" |
| 18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 21 #include "base/time/time.h" |
| 21 #include "device/bluetooth/bluetooth_export.h" | 22 #include "device/bluetooth/bluetooth_export.h" |
| 22 #include "device/bluetooth/bluetooth_uuid.h" | 23 #include "device/bluetooth/bluetooth_uuid.h" |
| 23 #include "net/log/net_log.h" | 24 #include "net/log/net_log.h" |
| 24 | 25 |
| 25 namespace base { | 26 namespace base { |
| 26 class BinaryValue; | 27 class BinaryValue; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace device { | 30 namespace device { |
| 30 | 31 |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const; | 462 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const; |
| 462 | 463 |
| 463 // Returns the list UUIDs of services that have service data. | 464 // Returns the list UUIDs of services that have service data. |
| 464 virtual UUIDList GetServiceDataUUIDs() const; | 465 virtual UUIDList GetServiceDataUUIDs() const; |
| 465 | 466 |
| 466 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where | 467 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where |
| 467 // each 'X' is a hex digit. If the input |address| is invalid, returns an | 468 // each 'X' is a hex digit. If the input |address| is invalid, returns an |
| 468 // empty string. | 469 // empty string. |
| 469 static std::string CanonicalizeAddress(const std::string& address); | 470 static std::string CanonicalizeAddress(const std::string& address); |
| 470 | 471 |
| 472 // Return the timestamp for when this device was last seen. |
| 473 base::Time GetLastUpdateTime() const { return last_update_time_; } |
| 474 |
| 475 // Update the last time this device was seen. |
| 476 void UpdateTimestamp(); |
| 477 |
| 471 // Return associated BluetoothAdapter. | 478 // Return associated BluetoothAdapter. |
| 472 BluetoothAdapter* GetAdapter() { return adapter_; } | 479 BluetoothAdapter* GetAdapter() { return adapter_; } |
| 473 | 480 |
| 474 protected: | 481 protected: |
| 475 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. | 482 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. |
| 476 friend BluetoothGattConnection; | 483 friend BluetoothGattConnection; |
| 477 FRIEND_TEST_ALL_PREFIXES( | 484 FRIEND_TEST_ALL_PREFIXES( |
| 478 BluetoothTest, | 485 BluetoothTest, |
| 479 BluetoothGattConnection_DisconnectGatt_SimulateConnect); | 486 BluetoothGattConnection_DisconnectGatt_SimulateConnect); |
| 480 FRIEND_TEST_ALL_PREFIXES( | 487 FRIEND_TEST_ALL_PREFIXES( |
| 481 BluetoothTest, | 488 BluetoothTest, |
| 482 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect); | 489 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect); |
| 483 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, | 490 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, |
| 484 BluetoothGattConnection_ErrorAfterConnection); | 491 BluetoothGattConnection_ErrorAfterConnection); |
| 485 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, | 492 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, |
| 486 BluetoothGattConnection_DisconnectGatt_Cleanup); | 493 BluetoothGattConnection_DisconnectGatt_Cleanup); |
| 487 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, GetDeviceName_NullName); | 494 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, GetDeviceName_NullName); |
| 495 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDevices); |
| 488 | 496 |
| 489 BluetoothDevice(BluetoothAdapter* adapter); | 497 BluetoothDevice(BluetoothAdapter* adapter); |
| 490 | 498 |
| 491 // Returns the internal name of the Bluetooth device, used by | 499 // Returns the internal name of the Bluetooth device, used by |
| 492 // GetNameForDisplay(). | 500 // GetNameForDisplay(). |
| 493 virtual std::string GetDeviceName() const = 0; | 501 virtual std::string GetDeviceName() const = 0; |
| 494 | 502 |
| 495 // Implements platform specific operations to initiate a GATT connection. | 503 // Implements platform specific operations to initiate a GATT connection. |
| 496 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or | 504 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or |
| 497 // DidDisconnectGatt immediately or asynchronously as the connection state | 505 // DidDisconnectGatt immediately or asynchronously as the connection state |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 std::unique_ptr<BluetoothRemoteGattService>> | 552 std::unique_ptr<BluetoothRemoteGattService>> |
| 545 GattServiceMap; | 553 GattServiceMap; |
| 546 GattServiceMap gatt_services_; | 554 GattServiceMap gatt_services_; |
| 547 bool gatt_services_discovery_complete_; | 555 bool gatt_services_discovery_complete_; |
| 548 | 556 |
| 549 // Mapping from service UUID represented as a std::string of a bluetooth | 557 // Mapping from service UUID represented as a std::string of a bluetooth |
| 550 // service to | 558 // service to |
| 551 // the specific data. The data is stored as BinaryValue. | 559 // the specific data. The data is stored as BinaryValue. |
| 552 std::unique_ptr<base::DictionaryValue> services_data_; | 560 std::unique_ptr<base::DictionaryValue> services_data_; |
| 553 | 561 |
| 562 // Timestamp for when an advertisement was last seen. |
| 563 base::Time last_update_time_; |
| 564 |
| 554 private: | 565 private: |
| 555 // Returns a localized string containing the device's bluetooth address and | 566 // Returns a localized string containing the device's bluetooth address and |
| 556 // a device type for display when |name_| is empty. | 567 // a device type for display when |name_| is empty. |
| 557 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 568 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
| 558 }; | 569 }; |
| 559 | 570 |
| 560 } // namespace device | 571 } // namespace device |
| 561 | 572 |
| 562 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 573 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| OLD | NEW |