Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40bc4269 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Use a weak pointer to deliver updates to AVRCP devices."

parents 0418394f 4674b273
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -352,9 +352,8 @@ void AvrcpService::SendMediaUpdate(bool track_changed, bool play_state,
  // device update happens on the main thread.
  for (const auto& device :
       instance_->connection_handler_->GetListOfDevices()) {
    do_in_main_thread(FROM_HERE, base::Bind(&Device::SendMediaUpdate,
                                            base::Unretained(device.get()),
                                            track_changed, play_state, queue));
    do_in_main_thread(FROM_HERE,
                      base::Bind(&Device::SendMediaUpdate, device.get()->Get(), track_changed, play_state, queue));
  }
}

@@ -368,10 +367,8 @@ void AvrcpService::SendFolderUpdate(bool available_players,
  // Ensure that the update is posted to the correct thread
  for (const auto& device :
       instance_->connection_handler_->GetListOfDevices()) {
    do_in_main_thread(
        FROM_HERE,
        base::Bind(&Device::SendFolderUpdate, base::Unretained(device.get()),
                   available_players, addressed_players, uids));
    do_in_main_thread(FROM_HERE, base::Bind(&Device::SendFolderUpdate, device.get()->Get(), available_players,
                                            addressed_players, uids));
  }
}

+4 −0
Original line number Diff line number Diff line
@@ -58,6 +58,10 @@ void Device::RegisterInterfaces(MediaInterface* media_interface,
  volume_interface_ = volume_interface;
}

base::WeakPtr<Device> Device::Get() {
  return weak_ptr_factory_.GetWeakPtr();
}

void Device::SetBrowseMtu(uint16_t browse_mtu) {
  DEVICE_LOG(INFO) << __PRETTY_FUNCTION__ << ": browse_mtu = " << browse_mtu;
  browse_mtu_ = browse_mtu;
+6 −0
Original line number Diff line number Diff line
@@ -67,6 +67,12 @@ class Device {
      uint16_t ctrl_mtu, uint16_t browse_mtu);
  virtual ~Device() = default;

  /**
   * Gets a weak pointer to this device that is invalidated when the device is
   * disconnected.
   */
  base::WeakPtr<Device> Get();

  const RawAddress& GetAddress() const { return address_; };

  /**