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

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: Reverted two small unnecessary changes. Created 4 years, 5 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
« no previous file with comments | « device/bluetooth/bluetooth_classic_device_mac.mm ('k') | device/bluetooth/bluetooth_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_common.h" 22 #include "device/bluetooth/bluetooth_common.h"
22 #include "device/bluetooth/bluetooth_export.h" 23 #include "device/bluetooth/bluetooth_export.h"
23 #include "device/bluetooth/bluetooth_uuid.h" 24 #include "device/bluetooth/bluetooth_uuid.h"
24 #include "net/log/net_log.h" 25 #include "net/log/net_log.h"
25 26
26 namespace base { 27 namespace base {
27 class BinaryValue; 28 class BinaryValue;
28 } 29 }
29 30
30 namespace device { 31 namespace device {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const; 469 virtual base::BinaryValue* GetServiceData(BluetoothUUID serviceUUID) const;
469 470
470 // Returns the list UUIDs of services that have service data. 471 // Returns the list UUIDs of services that have service data.
471 virtual UUIDList GetServiceDataUUIDs() const; 472 virtual UUIDList GetServiceDataUUIDs() const;
472 473
473 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where 474 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where
474 // each 'X' is a hex digit. If the input |address| is invalid, returns an 475 // each 'X' is a hex digit. If the input |address| is invalid, returns an
475 // empty string. 476 // empty string.
476 static std::string CanonicalizeAddress(const std::string& address); 477 static std::string CanonicalizeAddress(const std::string& address);
477 478
479 // Return the timestamp for when this device was last seen.
480 base::Time GetLastUpdateTime() const { return last_update_time_; }
481
482 // Update the last time this device was seen.
483 void UpdateTimestamp();
484
478 // Return associated BluetoothAdapter. 485 // Return associated BluetoothAdapter.
479 BluetoothAdapter* GetAdapter() { return adapter_; } 486 BluetoothAdapter* GetAdapter() { return adapter_; }
480 487
481 protected: 488 protected:
482 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. 489 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection.
483 friend BluetoothGattConnection; 490 friend BluetoothGattConnection;
484 FRIEND_TEST_ALL_PREFIXES( 491 FRIEND_TEST_ALL_PREFIXES(
485 BluetoothTest, 492 BluetoothTest,
486 BluetoothGattConnection_DisconnectGatt_SimulateConnect); 493 BluetoothGattConnection_DisconnectGatt_SimulateConnect);
487 FRIEND_TEST_ALL_PREFIXES( 494 FRIEND_TEST_ALL_PREFIXES(
488 BluetoothTest, 495 BluetoothTest,
489 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect); 496 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect);
490 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, 497 FRIEND_TEST_ALL_PREFIXES(BluetoothTest,
491 BluetoothGattConnection_ErrorAfterConnection); 498 BluetoothGattConnection_ErrorAfterConnection);
492 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, 499 FRIEND_TEST_ALL_PREFIXES(BluetoothTest,
493 BluetoothGattConnection_DisconnectGatt_Cleanup); 500 BluetoothGattConnection_DisconnectGatt_Cleanup);
494 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, GetDeviceName_NullName); 501 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, GetDeviceName_NullName);
502 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDevices);
503 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDeviceGattConnect);
495 504
496 BluetoothDevice(BluetoothAdapter* adapter); 505 BluetoothDevice(BluetoothAdapter* adapter);
497 506
498 // Returns the internal name of the Bluetooth device, used by 507 // Returns the internal name of the Bluetooth device, used by
499 // GetNameForDisplay(). 508 // GetNameForDisplay().
500 virtual std::string GetDeviceName() const = 0; 509 virtual std::string GetDeviceName() const = 0;
501 510
502 // Implements platform specific operations to initiate a GATT connection. 511 // Implements platform specific operations to initiate a GATT connection.
503 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or 512 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or
504 // DidDisconnectGatt immediately or asynchronously as the connection state 513 // DidDisconnectGatt immediately or asynchronously as the connection state
(...skipping 22 matching lines...) Expand all
527 void AddGattConnection(BluetoothGattConnection*); 536 void AddGattConnection(BluetoothGattConnection*);
528 void RemoveGattConnection(BluetoothGattConnection*); 537 void RemoveGattConnection(BluetoothGattConnection*);
529 538
530 // Clears the list of service data. 539 // Clears the list of service data.
531 void ClearServiceData(); 540 void ClearServiceData();
532 541
533 // Set the data of a given service designated by its UUID. 542 // Set the data of a given service designated by its UUID.
534 void SetServiceData(BluetoothUUID serviceUUID, const char* buffer, 543 void SetServiceData(BluetoothUUID serviceUUID, const char* buffer,
535 size_t size); 544 size_t size);
536 545
546 // Update last_update_time_ so that the device appears as expired.
547 void SetAsExpiredForTesting();
548
537 // Raw pointer to adapter owning this device object. Subclasses use platform 549 // Raw pointer to adapter owning this device object. Subclasses use platform
538 // specific pointers via adapter_. 550 // specific pointers via adapter_.
539 BluetoothAdapter* adapter_; 551 BluetoothAdapter* adapter_;
540 552
541 // Callbacks for pending success and error result of CreateGattConnection. 553 // Callbacks for pending success and error result of CreateGattConnection.
542 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; 554 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_;
543 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; 555 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_;
544 556
545 // BluetoothGattConnection objects keeping the GATT connection alive. 557 // BluetoothGattConnection objects keeping the GATT connection alive.
546 std::set<BluetoothGattConnection*> gatt_connections_; 558 std::set<BluetoothGattConnection*> gatt_connections_;
547 559
548 // Mapping from the platform-specific GATT service identifiers to 560 // Mapping from the platform-specific GATT service identifiers to
549 // BluetoothRemoteGattService objects. 561 // BluetoothRemoteGattService objects.
550 typedef base::ScopedPtrHashMap<std::string, 562 typedef base::ScopedPtrHashMap<std::string,
551 std::unique_ptr<BluetoothRemoteGattService>> 563 std::unique_ptr<BluetoothRemoteGattService>>
552 GattServiceMap; 564 GattServiceMap;
553 GattServiceMap gatt_services_; 565 GattServiceMap gatt_services_;
554 bool gatt_services_discovery_complete_; 566 bool gatt_services_discovery_complete_;
555 567
556 // Mapping from service UUID represented as a std::string of a bluetooth 568 // Mapping from service UUID represented as a std::string of a bluetooth
557 // service to 569 // service to
558 // the specific data. The data is stored as BinaryValue. 570 // the specific data. The data is stored as BinaryValue.
559 std::unique_ptr<base::DictionaryValue> services_data_; 571 std::unique_ptr<base::DictionaryValue> services_data_;
560 572
573 // Timestamp for when an advertisement was last seen.
574 base::Time last_update_time_;
575
561 private: 576 private:
562 // Returns a localized string containing the device's bluetooth address and 577 // Returns a localized string containing the device's bluetooth address and
563 // a device type for display when |name_| is empty. 578 // a device type for display when |name_| is empty.
564 base::string16 GetAddressWithLocalizedDeviceTypeName() const; 579 base::string16 GetAddressWithLocalizedDeviceTypeName() const;
565 }; 580 };
566 581
567 } // namespace device 582 } // namespace device
568 583
569 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 584 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_classic_device_mac.mm ('k') | device/bluetooth/bluetooth_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698