[codehealth] raw_ptr migration: final cleanup and roll fixes

This migrates remaining raw pointer class members and containers to use
raw_ptr<T>, addressing issues exposed during the latest Chromium roll.
This includes fixes across cast/, discovery/, osp/, and platform/
targets.

Implementation files were updated to match the new raw_ptr types,
including using .get() where required for explicit pointer access.

Bug: 520101123
Change-Id: Id1111b8b35866dd0e5439c89b7ba43da6edae3c5
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/7988896
Reviewed-by: Muyao Xu <muyaoxu@google.com>
Commit-Queue: Jordan Bayles <jophba@chromium.org>
diff --git a/cast/common/channel/namespace_router.h b/cast/common/channel/namespace_router.h
index 88caf4e..392bb38 100644
--- a/cast/common/channel/namespace_router.h
+++ b/cast/common/channel/namespace_router.h
@@ -10,6 +10,7 @@
 
 #include "cast/common/channel/cast_message_handler.h"
 #include "cast/common/channel/proto/cast_channel.pb.h"
+#include "util/raw_ptr.h"
 
 namespace openscreen::cast {
 
@@ -27,7 +28,7 @@
                  proto::CastMessage message) override;
 
  private:
-  std::map<std::string /* namespace */, CastMessageHandler*> handlers_;
+  std::map<std::string /* namespace */, raw_ptr<CastMessageHandler>> handlers_;
 };
 
 }  // namespace openscreen::cast
diff --git a/cast/receiver/application_agent.h b/cast/receiver/application_agent.h
index 889189b..31e3621 100644
--- a/cast/receiver/application_agent.h
+++ b/cast/receiver/application_agent.h
@@ -174,7 +174,7 @@
   VirtualConnectionRouter router_;
   ConnectionNamespaceHandler connection_handler_;
 
-  std::map<std::string, Application*> registered_applications_;
+  std::map<std::string, raw_ptr<Application>> registered_applications_;
   raw_ptr<Application> idle_screen_app_ = nullptr;
 
   CastSocketMessagePort message_port_;
diff --git a/cast/standalone_sender/bindings/python/sender_bridge.h b/cast/standalone_sender/bindings/python/sender_bridge.h
index 0b73aeb..21d8d4c 100644
--- a/cast/standalone_sender/bindings/python/sender_bridge.h
+++ b/cast/standalone_sender/bindings/python/sender_bridge.h
@@ -11,6 +11,7 @@
 #include <string_view>
 
 #include "platform/base/ip_address.h"
+#include "util/raw_ptr.h"
 #include "util/thread_annotations.h"
 
 namespace openscreen {
@@ -77,7 +78,7 @@
   int port_;
   std::string cert_path_;
   std::mutex mutex_;
-  TaskRunner* const task_runner_;
+  const raw_ptr<TaskRunner> task_runner_;
   std::unique_ptr<LoopingFileCastAgent> cast_agent_ OSP_GUARDED_BY(mutex_);
 };
 
diff --git a/cast/standalone_sender/looping_file_sender.h b/cast/standalone_sender/looping_file_sender.h
index 2a016da..910a611 100644
--- a/cast/standalone_sender/looping_file_sender.h
+++ b/cast/standalone_sender/looping_file_sender.h
@@ -17,6 +17,7 @@
 #include "cast/standalone_sender/streaming_opus_encoder.h"
 #include "cast/standalone_sender/streaming_video_encoder.h"
 #include "cast/streaming/public/sender_session.h"
+#include "util/raw_ptr.h"
 
 namespace openscreen::cast {
 
@@ -84,7 +85,7 @@
   const ConnectionSettings settings_;
 
   // Session to query for bandwidth information.
-  const SenderSession* session_;
+  const raw_ptr<const SenderSession> session_;
 
   // Callback for tearing down the sender process.
   ShutdownCallback shutdown_callback_;
diff --git a/cast/standalone_sender/remoting_sender.h b/cast/standalone_sender/remoting_sender.h
index acb0d6a..8283a35 100644
--- a/cast/standalone_sender/remoting_sender.h
+++ b/cast/standalone_sender/remoting_sender.h
@@ -9,6 +9,7 @@
 
 #include "cast/streaming/public/constants.h"
 #include "cast/streaming/public/rpc_messenger.h"
+#include "util/raw_ptr.h"
 
 namespace openscreen::cast {
 
@@ -61,7 +62,7 @@
   const AudioCodec audio_codec_;
   const VideoCodec video_codec_;
 
-  Client* client_;
+  raw_ptr<Client> client_;
 
   // The initialization message from the receiver contains the handle the
   // callback should go to.
diff --git a/cast/streaming/impl/receiver_packet_router.h b/cast/streaming/impl/receiver_packet_router.h
index a87d946..c86cb15 100644
--- a/cast/streaming/impl/receiver_packet_router.h
+++ b/cast/streaming/impl/receiver_packet_router.h
@@ -14,6 +14,7 @@
 #include "cast/streaming/ssrc.h"
 #include "platform/base/span.h"
 #include "util/flat_map.h"
+#include "util/raw_ptr.h"
 #include "util/raw_ref.h"
 
 namespace openscreen::cast {
@@ -60,7 +61,7 @@
 
   const raw_ref<Environment> environment_;
 
-  FlatMap<Ssrc, PacketConsumer*> receivers_;
+  FlatMap<Ssrc, raw_ptr<PacketConsumer>> receivers_;
 };
 
 }  // namespace openscreen::cast
diff --git a/discovery/dnssd/impl/publisher_impl.cc b/discovery/dnssd/impl/publisher_impl.cc
index 7597ac4..a225656 100644
--- a/discovery/dnssd/impl/publisher_impl.cc
+++ b/discovery/dnssd/impl/publisher_impl.cc
@@ -266,7 +266,7 @@
   DnsSdInstance requested_instance = std::move(it->first);
   DnsSdInstanceEndpoint endpoint =
       CreateEndpoint(requested_instance, *network_config_);
-  Client* const client = it->second;
+  Client* client = it->second;
   pending_instances_.erase(it);
 
   if (requested_name != confirmed_name) {
diff --git a/discovery/dnssd/impl/publisher_impl.h b/discovery/dnssd/impl/publisher_impl.h
index e5bdbfb..d165264 100644
--- a/discovery/dnssd/impl/publisher_impl.h
+++ b/discovery/dnssd/impl/publisher_impl.h
@@ -13,6 +13,7 @@
 #include "discovery/dnssd/public/dns_sd_publisher.h"
 #include "discovery/mdns/public/mdns_domain_confirmed_provider.h"
 #include "discovery/mdns/public/mdns_service.h"
+#include "util/raw_ptr.h"
 #include "util/raw_ref.h"
 
 namespace openscreen::discovery {
@@ -43,7 +44,7 @@
 
   // The set of instances which will be published once the mDNS Probe phase
   // completes.
-  std::map<DnsSdInstance, Client* const> pending_instances_;
+  std::map<DnsSdInstance, const raw_ptr<Client>> pending_instances_;
 
   // Maps from the requested instance to the endpoint which was published after
   // the mDNS Probe phase was completed. The only difference between these
diff --git a/discovery/dnssd/impl/querier_impl.cc b/discovery/dnssd/impl/querier_impl.cc
index 9bfac43..04ddc82 100644
--- a/discovery/dnssd/impl/querier_impl.cc
+++ b/discovery/dnssd/impl/querier_impl.cc
@@ -222,7 +222,7 @@
 
   // Start tracking the new callback
   const ServiceKey key(service, kLocalDomain);
-  auto it = callback_map_.emplace(key, std::vector<Callback*>{}).first;
+  auto it = callback_map_.emplace(key, std::vector<raw_ptr<Callback>>{}).first;
   it->second.push_back(callback);
 
   const DomainName domain = key.GetName();
@@ -262,7 +262,7 @@
     return;
   }
 
-  std::vector<Callback*>& callbacks = callbacks_it->second;
+  std::vector<raw_ptr<Callback>>& callbacks = callbacks_it->second;
   const auto it = std::find(callbacks.begin(), callbacks.end(), callback);
   if (it == callbacks.end()) {
     return;
@@ -415,7 +415,7 @@
   }
 
   // Call relevant callbacks.
-  std::vector<Callback*>& callbacks = it->second;
+  std::vector<raw_ptr<Callback>>& callbacks = it->second;
   for (Callback* callback : callbacks) {
     for (const DnsSdInstanceEndpoint& endpoint : created) {
       callback->OnEndpointCreated(endpoint);
diff --git a/discovery/dnssd/impl/querier_impl.h b/discovery/dnssd/impl/querier_impl.h
index ee6181e..ba2801a 100644
--- a/discovery/dnssd/impl/querier_impl.h
+++ b/discovery/dnssd/impl/querier_impl.h
@@ -21,6 +21,7 @@
 #include "discovery/mdns/public/mdns_record_changed_callback.h"
 #include "discovery/mdns/public/mdns_records.h"
 #include "discovery/mdns/public/mdns_service.h"
+#include "util/raw_ptr.h"
 #include "util/raw_ref.h"
 
 namespace openscreen::discovery {
@@ -68,7 +69,7 @@
 
   // Map from the (service, domain) pairs currently being queried for to the
   // callbacks to call when new InstanceEndpoints are available.
-  std::map<ServiceKey, std::vector<Callback*>> callback_map_;
+  std::map<ServiceKey, std::vector<raw_ptr<Callback>>> callback_map_;
 
   const raw_ref<MdnsService> mdns_querier_;
   const raw_ref<TaskRunner> task_runner_;
diff --git a/discovery/mdns/impl/mdns_receiver.h b/discovery/mdns/impl/mdns_receiver.h
index c1f0a90..7da4b31 100644
--- a/discovery/mdns/impl/mdns_receiver.h
+++ b/discovery/mdns/impl/mdns_receiver.h
@@ -12,6 +12,7 @@
 #include "platform/api/udp_socket.h"
 #include "platform/base/error.h"
 #include "platform/base/udp_packet.h"
+#include "util/raw_ptr.h"
 
 namespace openscreen::discovery {
 
@@ -60,7 +61,7 @@
       query_callback_;
   State state_ = State::kStopped;
 
-  std::vector<ResponseClient*> response_clients_;
+  std::vector<raw_ptr<ResponseClient>> response_clients_;
 
   Config config_;
 };
diff --git a/discovery/mdns/impl/mdns_trackers.cc b/discovery/mdns/impl/mdns_trackers.cc
index 1c13333..49794d6 100644
--- a/discovery/mdns/impl/mdns_trackers.cc
+++ b/discovery/mdns/impl/mdns_trackers.cc
@@ -371,7 +371,7 @@
     OSP_CHECK((*it)->tracker_type() == TrackerType::kRecordTracker);
 
     const MdnsRecordTracker* record_tracker =
-        static_cast<const MdnsRecordTracker*>(*it);
+        static_cast<const MdnsRecordTracker*>((*it).get());
     if (record_tracker->IsNearingExpiry()) {
       it++;
       continue;
diff --git a/discovery/mdns/impl/mdns_trackers.h b/discovery/mdns/impl/mdns_trackers.h
index 952b894..6947e15 100644
--- a/discovery/mdns/impl/mdns_trackers.h
+++ b/discovery/mdns/impl/mdns_trackers.h
@@ -13,6 +13,7 @@
 #include "platform/base/error.h"
 #include "platform/base/trivial_clock_traits.h"
 #include "util/alarm.h"
+#include "util/raw_ptr.h"
 #include "util/raw_ref.h"
 
 namespace openscreen::discovery {
@@ -74,7 +75,7 @@
   bool AddAdjacentNode(const MdnsTracker* tracker) const;
   bool RemoveAdjacentNode(const MdnsTracker* tracker) const;
 
-  const std::vector<const MdnsTracker*>& adjacent_nodes() const {
+  const std::vector<raw_ptr<const MdnsTracker>>& adjacent_nodes() const {
     return adjacent_nodes_;
   }
 
@@ -91,7 +92,7 @@
   void RemovedReverseAdjacency(const MdnsTracker* tracker) const;
 
   // Adjacency list for this graph node.
-  mutable std::vector<const MdnsTracker*> adjacent_nodes_;
+  mutable std::vector<raw_ptr<const MdnsTracker>> adjacent_nodes_;
 };
 
 class MdnsQuestionTracker;
diff --git a/osp/impl/presentation/presentation_controller.cc b/osp/impl/presentation/presentation_controller.cc
index acdd3b9..10b029b 100644
--- a/osp/impl/presentation/presentation_controller.cc
+++ b/osp/impl/presentation/presentation_controller.cc
@@ -365,7 +365,7 @@
   auto presentation_entry =
       controller_->presentations_by_id_.find(event.presentation_id);
   if (presentation_entry != controller_->presentations_by_id_.end()) {
-    for (auto* connection : presentation_entry->second.connections) {
+    for (auto connection : presentation_entry->second.connections) {
       connection->OnTerminated();
     }
     controller_->presentations_by_id_.erase(presentation_entry);
@@ -530,7 +530,7 @@
   }
 
   ControlledPresentation& presentation = presentation_entry->second;
-  for (auto* connection : presentation.connections) {
+  for (auto connection : presentation.connections) {
     connection->OnTerminated();
   }
 
@@ -551,7 +551,7 @@
     return;
   }
 
-  std::vector<Connection*>& connections =
+  std::vector<raw_ptr<Connection>>& connections =
       presentation_entry->second.connections;
   connections.erase(
       std::remove(connections.begin(), connections.end(), connection),
@@ -789,7 +789,7 @@
 void Controller::TerminatePresentationById(const std::string& presentation_id) {
   auto presentation_entry = presentations_by_id_.find(presentation_id);
   if (presentation_entry != presentations_by_id_.end()) {
-    for (auto* connection : presentation_entry->second.connections) {
+    for (auto connection : presentation_entry->second.connections) {
       connection->OnTerminated();
     }
     presentations_by_id_.erase(presentation_entry);
diff --git a/osp/impl/presentation/presentation_receiver.cc b/osp/impl/presentation/presentation_receiver.cc
index 0a4e327..a4cab93 100644
--- a/osp/impl/presentation/presentation_receiver.cc
+++ b/osp/impl/presentation/presentation_receiver.cc
@@ -57,7 +57,7 @@
     return Error::Code::kNoActiveConnection;
   }
 
-  for (auto* connection : presentation.connections) {
+  for (auto connection : presentation.connections) {
     connection->OnTerminated();
   }
 
@@ -87,7 +87,7 @@
     return;
   }
 
-  std::vector<Connection*>& connections =
+  std::vector<raw_ptr<Connection>>& connections =
       presentation_entry->second.connections;
   connections.erase(
       std::remove(connections.begin(), connections.end(), connection),
diff --git a/osp/impl/presentation/url_availability_requester.cc b/osp/impl/presentation/url_availability_requester.cc
index 369ad80..3d877d6 100644
--- a/osp/impl/presentation/url_availability_requester.cc
+++ b/osp/impl/presentation/url_availability_requester.cc
@@ -111,7 +111,7 @@
 void UrlAvailabilityRequester::RemoveObserver(ReceiverObserver* observer) {
   std::set<std::string> unobserved_urls;
   for (auto& entry : observers_by_url_) {
-    auto& observer_list = entry.second;
+    std::vector<raw_ptr<ReceiverObserver>>& observer_list = entry.second;
     auto it = std::remove(observer_list.begin(), observer_list.end(), observer);
     if (it != observer_list.end()) {
       observer_list.erase(it);
@@ -308,7 +308,7 @@
       continue;
     }
 
-    std::vector<ReceiverObserver*>& observers = observer_entry->second;
+    std::vector<raw_ptr<ReceiverObserver>>& observers = observer_entry->second;
     auto result = known_availability_by_url_.emplace(url, *availability_it);
     auto entry = result.first;
     bool inserted = result.second;
@@ -316,7 +316,7 @@
     if (inserted || updated) {
       switch (*availability_it) {
         case msgs::UrlAvailability::kAvailable: {
-          for (auto* observer : observers) {
+          for (auto observer : observers) {
             observer->OnReceiverAvailable(url, instance_name_);
           }
           break;
@@ -324,7 +324,7 @@
 
         case msgs::UrlAvailability::kUnavailable:  // fallthrough
         case msgs::UrlAvailability::kInvalid: {
-          for (auto* observer : observers) {
+          for (auto observer : observers) {
             observer->OnReceiverUnavailable(url, instance_name_);
           }
           break;
diff --git a/osp/impl/presentation/url_availability_requester.h b/osp/impl/presentation/url_availability_requester.h
index 2f5813f..1fb1608 100644
--- a/osp/impl/presentation/url_availability_requester.h
+++ b/osp/impl/presentation/url_availability_requester.h
@@ -19,6 +19,7 @@
 #include "osp/public/service_info.h"
 #include "platform/api/time.h"
 #include "platform/base/error.h"
+#include "util/raw_ptr.h"
 #include "util/raw_ref.h"
 
 namespace openscreen::osp {
@@ -150,7 +151,8 @@
 
   const ClockNowFunctionPtr now_function_;
 
-  std::map<std::string, std::vector<ReceiverObserver*>> observers_by_url_;
+  std::map<std::string, std::vector<raw_ptr<ReceiverObserver>>>
+      observers_by_url_;
   std::map<std::string, std::unique_ptr<ReceiverRequester>>
       receiver_by_instance_name_;
 };
diff --git a/osp/impl/quic/quic_stream_manager.cc b/osp/impl/quic/quic_stream_manager.cc
index aad19d9..a4c9947 100644
--- a/osp/impl/quic/quic_stream_manager.cc
+++ b/osp/impl/quic/quic_stream_manager.cc
@@ -38,7 +38,7 @@
   }
 
   delegate_->OnClose(quic_connection_->instance_id(), stream_id);
-  auto* protocol_connection = stream_entry->second;
+  auto protocol_connection = stream_entry->second;
   if (protocol_connection) {
     protocol_connection->OnClose();
   }
diff --git a/osp/impl/quic/quic_stream_manager.h b/osp/impl/quic/quic_stream_manager.h
index b60c699..16942f1 100644
--- a/osp/impl/quic/quic_stream_manager.h
+++ b/osp/impl/quic/quic_stream_manager.h
@@ -60,7 +60,7 @@
   const raw_ref<Delegate> delegate_;
   // This class manages all QuicStreams for `quic_connection_`;
   raw_ptr<QuicConnection> quic_connection_ = nullptr;
-  std::map<uint64_t, QuicProtocolConnection*> streams_by_id_;
+  std::map<uint64_t, raw_ptr<QuicProtocolConnection>> streams_by_id_;
 };
 
 }  // namespace openscreen::osp
diff --git a/osp/public/message_demuxer.cc b/osp/public/message_demuxer.cc
index 68e75d3..a82a393 100644
--- a/osp/public/message_demuxer.cc
+++ b/osp/public/message_demuxer.cc
@@ -145,7 +145,8 @@
   if (callbacks_entry == message_callbacks_.end()) {
     callbacks_entry =
         message_callbacks_
-            .emplace(instance_id, std::map<msgs::Type, MessageCallback*>{})
+            .emplace(instance_id,
+                     std::map<msgs::Type, raw_ptr<MessageCallback>>{})
             .first;
   }
 
@@ -240,7 +241,7 @@
 MessageDemuxer::HandleStreamBufferResult MessageDemuxer::HandleStreamBufferLoop(
     uint64_t instance_id,
     uint64_t connection_id,
-    std::map<uint64_t, std::map<msgs::Type, MessageCallback*>>::iterator
+    std::map<uint64_t, std::map<msgs::Type, raw_ptr<MessageCallback>>>::iterator
         callbacks_entry,
     std::vector<uint8_t>& buffer) {
   HandleStreamBufferResult result;
@@ -280,7 +281,7 @@
 MessageDemuxer::HandleStreamBufferResult MessageDemuxer::HandleStreamBuffer(
     uint64_t instance_id,
     uint64_t connection_id,
-    std::map<msgs::Type, MessageCallback*>* message_callbacks,
+    std::map<msgs::Type, raw_ptr<MessageCallback>>* message_callbacks,
     std::vector<uint8_t>& buffer) {
   size_t msg_type_byte_length;
   ErrorOr<msgs::Type> message_type =
diff --git a/osp/public/message_demuxer.h b/osp/public/message_demuxer.h
index 9f57abc..60f33df 100644
--- a/osp/public/message_demuxer.h
+++ b/osp/public/message_demuxer.h
@@ -115,20 +115,22 @@
   HandleStreamBufferResult HandleStreamBufferLoop(
       uint64_t instance_id,
       uint64_t connection_id,
-      std::map<uint64_t, std::map<msgs::Type, MessageCallback*>>::iterator
+      std::map<uint64_t,
+               std::map<msgs::Type, raw_ptr<MessageCallback>>>::iterator
           instance_entry,
       std::vector<uint8_t>& buffer);
 
   HandleStreamBufferResult HandleStreamBuffer(
       uint64_t instance_id,
       uint64_t connection_id,
-      std::map<msgs::Type, MessageCallback*>* message_callbacks,
+      std::map<msgs::Type, raw_ptr<MessageCallback>>* message_callbacks,
       std::vector<uint8_t>& buffer);
 
   const ClockNowFunctionPtr now_function_;
   const size_t buffer_limit_;
-  std::map<uint64_t, std::map<msgs::Type, MessageCallback*>> message_callbacks_;
-  std::map<msgs::Type, MessageCallback*> default_callbacks_;
+  std::map<uint64_t, std::map<msgs::Type, raw_ptr<MessageCallback>>>
+      message_callbacks_;
+  std::map<msgs::Type, raw_ptr<MessageCallback>> default_callbacks_;
 
   // Map<instance_id, Map<connection_id, data_buffer>>
   std::map<uint64_t, std::map<uint64_t, std::vector<uint8_t>>> buffers_;
diff --git a/osp/public/presentation/presentation_connection.h b/osp/public/presentation/presentation_connection.h
index 189b872..8591591 100644
--- a/osp/public/presentation/presentation_connection.h
+++ b/osp/public/presentation/presentation_connection.h
@@ -206,7 +206,7 @@
   // TODO(btolsch): Connection IDs were changed to be per-instance, but this
   // table then needs to be <instance id, connection id> since connection id
   // is still not unique globally.
-  std::map<uint64_t, Connection*> connections_;
+  std::map<uint64_t, raw_ptr<Connection>> connections_;
 
   MessageDemuxer::MessageWatch message_watch_;
   MessageDemuxer::MessageWatch close_event_watch_;
diff --git a/osp/public/presentation/presentation_controller.h b/osp/public/presentation/presentation_controller.h
index 45267cd..fbde00d 100644
--- a/osp/public/presentation/presentation_controller.h
+++ b/osp/public/presentation/presentation_controller.h
@@ -191,7 +191,7 @@
   struct ControlledPresentation {
     std::string instance_name;
     std::string url;
-    std::vector<Connection*> connections;
+    std::vector<raw_ptr<Connection>> connections;
   };
 
   // ServiceListener::Observer overrides.
diff --git a/osp/public/presentation/presentation_receiver.h b/osp/public/presentation/presentation_receiver.h
index fd623cc..1dae8fe 100644
--- a/osp/public/presentation/presentation_receiver.h
+++ b/osp/public/presentation/presentation_receiver.h
@@ -113,7 +113,7 @@
     uint64_t instance_id = 0u;
     MessageDemuxer::MessageWatch terminate_watch;
     uint64_t terminate_request_id = 0u;
-    std::vector<Connection*> connections;
+    std::vector<raw_ptr<Connection>> connections;
   };
 
   using QueuedResponseIterator = std::vector<QueuedResponse>::const_iterator;
diff --git a/osp/public/service_listener.cc b/osp/public/service_listener.cc
index 033c99d..5a0b1f5 100644
--- a/osp/public/service_listener.cc
+++ b/osp/public/service_listener.cc
@@ -184,7 +184,7 @@
 
 void ServiceListener::OnError(const Error& error) {
   last_error_ = error;
-  for (auto* observer : observers_) {
+  for (auto observer : observers_) {
     observer->OnError(error);
   }
 }
@@ -192,7 +192,7 @@
 void ServiceListener::OnReceiverAdded(const ServiceInfo& info) {
   OSP_VLOG << __func__ << ": new receiver added=" << info;
   receiver_list_.OnReceiverAdded(info);
-  for (auto* observer : observers_) {
+  for (auto observer : observers_) {
     observer->OnReceiverAdded(info);
   }
 }
@@ -201,7 +201,7 @@
   OSP_VLOG << __func__ << ": receiver changed=" << info;
   const Error changed_error = receiver_list_.OnReceiverChanged(info);
   if (changed_error.ok()) {
-    for (auto* observer : observers_) {
+    for (auto observer : observers_) {
       observer->OnReceiverChanged(info);
     }
   }
@@ -212,7 +212,7 @@
   const ErrorOr<ServiceInfo> removed_or_error =
       receiver_list_.OnReceiverRemoved(info);
   if (removed_or_error.is_value()) {
-    for (auto* observer : observers_) {
+    for (auto observer : observers_) {
       observer->OnReceiverRemoved(removed_or_error.value());
     }
   }
@@ -222,7 +222,7 @@
   OSP_VLOG << __func__ << ": all receivers removed.";
   const Error removed_all_error = receiver_list_.OnAllReceiversRemoved();
   if (removed_all_error.ok()) {
-    for (auto* observer : observers_) {
+    for (auto observer : observers_) {
       observer->OnAllReceiversRemoved();
     }
   }
@@ -231,28 +231,28 @@
 void ServiceListener::MaybeNotifyObservers() {
   switch (state_) {
     case State::kRunning: {
-      for (auto* observer : observers_) {
+      for (auto observer : observers_) {
         observer->OnStarted();
       }
       break;
     }
 
     case State::kStopped: {
-      for (auto* observer : observers_) {
+      for (auto observer : observers_) {
         observer->OnStopped();
       }
       break;
     }
 
     case State::kSuspended: {
-      for (auto* observer : observers_) {
+      for (auto observer : observers_) {
         observer->OnSuspended();
       }
       break;
     }
 
     case State::kSearching: {
-      for (auto* observer : observers_) {
+      for (auto observer : observers_) {
         observer->OnSearching();
       }
       break;
diff --git a/osp/public/service_listener.h b/osp/public/service_listener.h
index 984d5df..598513b 100644
--- a/osp/public/service_listener.h
+++ b/osp/public/service_listener.h
@@ -173,7 +173,7 @@
   Error last_error_;
   Config config_;
   std::unique_ptr<Delegate> delegate_;
-  std::vector<Observer*> observers_;
+  std::vector<raw_ptr<Observer>> observers_;
   ReceiverList receiver_list_;
 };
 
diff --git a/osp/public/service_publisher.cc b/osp/public/service_publisher.cc
index d6a3ae0..72dc43e 100644
--- a/osp/public/service_publisher.cc
+++ b/osp/public/service_publisher.cc
@@ -135,7 +135,7 @@
 
 void ServicePublisher::OnError(const Error& error) {
   last_error_ = error;
-  for (auto* observer : observers_) {
+  for (auto observer : observers_) {
     observer->OnError(error);
   }
 }
@@ -143,21 +143,21 @@
 void ServicePublisher::MaybeNotifyObserver() {
   switch (state_) {
     case State::kRunning: {
-      for (auto* observer : observers_) {
+      for (auto observer : observers_) {
         observer->OnStarted();
       }
       break;
     }
 
     case State::kStopped: {
-      for (auto* observer : observers_) {
+      for (auto observer : observers_) {
         observer->OnStopped();
       }
       break;
     }
 
     case State::kSuspended: {
-      for (auto* observer : observers_) {
+      for (auto observer : observers_) {
         observer->OnSuspended();
       }
       break;
diff --git a/osp/public/service_publisher.h b/osp/public/service_publisher.h
index edd3db8..8c260f6 100644
--- a/osp/public/service_publisher.h
+++ b/osp/public/service_publisher.h
@@ -157,7 +157,7 @@
   Error last_error_;
   Config config_;
   std::unique_ptr<Delegate> delegate_;
-  std::vector<Observer*> observers_;
+  std::vector<raw_ptr<Observer>> observers_;
 };
 
 }  // namespace openscreen::osp
diff --git a/platform/impl/tls_data_router_posix.h b/platform/impl/tls_data_router_posix.h
index 40dfe16..845461b 100644
--- a/platform/impl/tls_data_router_posix.h
+++ b/platform/impl/tls_data_router_posix.h
@@ -102,11 +102,12 @@
 
   // Mapping from all sockets to the observer that should be called when the
   // socket recognizes an incoming connection.
-  std::unordered_map<StreamSocketPosix*, SocketObserver*>
+  std::unordered_map<raw_ptr<StreamSocketPosix>, raw_ptr<SocketObserver>>
       accept_socket_mappings_ OSP_GUARDED_BY(accept_socket_mutex_);
 
   // Set of all TlsConnectionPosix objects currently registered.
-  std::vector<TlsConnectionPosix*> connections_ OSP_GUARDED_BY(connections_mutex_);
+  std::vector<raw_ptr<TlsConnectionPosix>> connections_
+      OSP_GUARDED_BY(connections_mutex_);
 
   // StreamSockets currently owned by this object, being watched for
   std::vector<std::unique_ptr<StreamSocketPosix>> accept_stream_sockets_;
diff --git a/platform/impl/udp_socket_reader_posix.h b/platform/impl/udp_socket_reader_posix.h
index 0b7fd60..31daf81 100644
--- a/platform/impl/udp_socket_reader_posix.h
+++ b/platform/impl/udp_socket_reader_posix.h
@@ -14,6 +14,7 @@
 #include "platform/impl/socket_handle.h"
 #include "platform/impl/socket_handle_waiter.h"
 #include "platform/impl/udp_socket_posix.h"
+#include "util/raw_ptr.h"
 #include "util/raw_ref.h"
 #include "util/thread_annotations.h"
 
@@ -65,7 +66,7 @@
                 bool disable_locking_for_testing = false);
 
   // The set of all sockets that are being read from
-  std::vector<UdpSocketPosix*> sockets_ OSP_GUARDED_BY(mutex_);
+  std::vector<raw_ptr<UdpSocketPosix>> sockets_ OSP_GUARDED_BY(mutex_);
 
   // Mutex to protect against concurrent modification of socket info.
   mutable std::mutex mutex_;