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

Side by Side Diff: device/bluetooth/bluetooth_device.h

Issue 1842223003: Remove outdated devices from Android device chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed naming and type so that it follows C++ style guide. Created 4 years, 6 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
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 #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
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);
496 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDeviceGattConnect);
488 497
489 BluetoothDevice(BluetoothAdapter* adapter); 498 BluetoothDevice(BluetoothAdapter* adapter);
490 499
491 // Returns the internal name of the Bluetooth device, used by 500 // Returns the internal name of the Bluetooth device, used by
492 // GetNameForDisplay(). 501 // GetNameForDisplay().
493 virtual std::string GetDeviceName() const = 0; 502 virtual std::string GetDeviceName() const = 0;
494 503
495 // Implements platform specific operations to initiate a GATT connection. 504 // Implements platform specific operations to initiate a GATT connection.
496 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or 505 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or
497 // DidDisconnectGatt immediately or asynchronously as the connection state 506 // DidDisconnectGatt immediately or asynchronously as the connection state
(...skipping 22 matching lines...) Expand all
520 void AddGattConnection(BluetoothGattConnection*); 529 void AddGattConnection(BluetoothGattConnection*);
521 void RemoveGattConnection(BluetoothGattConnection*); 530 void RemoveGattConnection(BluetoothGattConnection*);
522 531
523 // Clears the list of service data. 532 // Clears the list of service data.
524 void ClearServiceData(); 533 void ClearServiceData();
525 534
526 // Set the data of a given service designated by its UUID. 535 // Set the data of a given service designated by its UUID.
527 void SetServiceData(BluetoothUUID serviceUUID, const char* buffer, 536 void SetServiceData(BluetoothUUID serviceUUID, const char* buffer,
528 size_t size); 537 size_t size);
529 538
539 // Update last_update_time_ so that the device appears as expired.
540 void SetAsExpiredForTesting();
541
530 // Raw pointer to adapter owning this device object. Subclasses use platform 542 // Raw pointer to adapter owning this device object. Subclasses use platform
531 // specific pointers via adapter_. 543 // specific pointers via adapter_.
532 BluetoothAdapter* adapter_; 544 BluetoothAdapter* adapter_;
533 545
534 // Callbacks for pending success and error result of CreateGattConnection. 546 // Callbacks for pending success and error result of CreateGattConnection.
535 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; 547 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_;
536 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; 548 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_;
537 549
538 // BluetoothGattConnection objects keeping the GATT connection alive. 550 // BluetoothGattConnection objects keeping the GATT connection alive.
539 std::set<BluetoothGattConnection*> gatt_connections_; 551 std::set<BluetoothGattConnection*> gatt_connections_;
540 552
541 // Mapping from the platform-specific GATT service identifiers to 553 // Mapping from the platform-specific GATT service identifiers to
542 // BluetoothRemoteGattService objects. 554 // BluetoothRemoteGattService objects.
543 typedef base::ScopedPtrHashMap<std::string, 555 typedef base::ScopedPtrHashMap<std::string,
544 std::unique_ptr<BluetoothRemoteGattService>> 556 std::unique_ptr<BluetoothRemoteGattService>>
545 GattServiceMap; 557 GattServiceMap;
546 GattServiceMap gatt_services_; 558 GattServiceMap gatt_services_;
547 bool gatt_services_discovery_complete_; 559 bool gatt_services_discovery_complete_;
548 560
549 // Mapping from service UUID represented as a std::string of a bluetooth 561 // Mapping from service UUID represented as a std::string of a bluetooth
550 // service to 562 // service to
551 // the specific data. The data is stored as BinaryValue. 563 // the specific data. The data is stored as BinaryValue.
552 std::unique_ptr<base::DictionaryValue> services_data_; 564 std::unique_ptr<base::DictionaryValue> services_data_;
553 565
566 // Timestamp for when an advertisement was last seen.
567 base::Time last_update_time_;
568
554 private: 569 private:
555 // Returns a localized string containing the device's bluetooth address and 570 // Returns a localized string containing the device's bluetooth address and
556 // a device type for display when |name_| is empty. 571 // a device type for display when |name_| is empty.
557 base::string16 GetAddressWithLocalizedDeviceTypeName() const; 572 base::string16 GetAddressWithLocalizedDeviceTypeName() const;
558 }; 573 };
559 574
560 } // namespace device 575 } // namespace device
561 576
562 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 577 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698