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

Unified Diff: components/cast_channel/cast_socket_service.cc

Issue 2974523002: [cast_channel] Make CastSocketService a global leaky singleton (Closed)
Patch Set: merge with master Created 3 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 side-by-side diff with in-line comments
Download patch
Index: components/cast_channel/cast_socket_service.cc
diff --git a/components/cast_channel/cast_socket_service.cc b/components/cast_channel/cast_socket_service.cc
index 6bdeae3ac790dfa5f61d36cdd14df15a774c0e8f..79323957445926079336efca16d7c33357b0e4e6 100644
--- a/components/cast_channel/cast_socket_service.cc
+++ b/components/cast_channel/cast_socket_service.cc
@@ -28,15 +28,17 @@ namespace cast_channel {
int CastSocketService::last_channel_id_ = 0;
-CastSocketService::CastSocketService()
- : RefcountedKeyedService(
- BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)),
- logger_(new Logger()) {
+CastSocketService::CastSocketService() : logger_(new Logger()) {
DETACH_FROM_THREAD(thread_checker_);
}
-CastSocketService::~CastSocketService() {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+// This is a leaky singleton and the dtor won't be called.
+CastSocketService::~CastSocketService() = default;
+
+// static
+CastSocketService* CastSocketService::GetInstance() {
+ return base::Singleton<CastSocketService,
+ base::LeakySingletonTraits<CastSocketService>>::get();
}
scoped_refptr<Logger> CastSocketService::GetLogger() {
@@ -128,17 +130,9 @@ int CastSocketService::OpenSocket(const net::IPEndPoint& ip_endpoint,
observer);
}
-CastSocket::Observer* CastSocketService::GetObserver(const std::string& id) {
- auto it = socket_observer_map_.find(id);
- return it == socket_observer_map_.end() ? nullptr : it->second.get();
-}
-
-CastSocket::Observer* CastSocketService::AddObserver(
- const std::string& id,
- std::unique_ptr<CastSocket::Observer> observer) {
- CastSocket::Observer* observer_ptr = observer.get();
- socket_observer_map_.insert(std::make_pair(id, std::move(observer)));
- return observer_ptr;
+void CastSocketService::RemoveObserver(CastSocket::Observer* observer) {
+ for (auto& socket_it : sockets_)
+ socket_it.second->RemoveObserver(observer);
}
void CastSocketService::SetSocketForTest(
@@ -146,6 +140,4 @@ void CastSocketService::SetSocketForTest(
socket_for_test_ = std::move(socket_for_test);
}
-void CastSocketService::ShutdownOnUIThread() {}
-
} // namespace cast_channel
« no previous file with comments | « components/cast_channel/cast_socket_service.h ('k') | components/cast_channel/cast_socket_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698