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

Unified Diff: components/cast_channel/cast_socket_service.h

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
« no previous file with comments | « components/cast_channel/cast_socket.cc ('k') | components/cast_channel/cast_socket_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cast_channel/cast_socket_service.h
diff --git a/components/cast_channel/cast_socket_service.h b/components/cast_channel/cast_socket_service.h
index bb465e920dc1f654035c25d6705c8136ceb391f3..d7dc8c29c98be27f3475eb72ef6810412fbb38b2 100644
--- a/components/cast_channel/cast_socket_service.h
+++ b/components/cast_channel/cast_socket_service.h
@@ -9,9 +9,9 @@
#include <memory>
#include "base/macros.h"
+#include "base/memory/singleton.h"
#include "base/threading/thread_checker.h"
#include "components/cast_channel/cast_socket.h"
-#include "components/keyed_service/core/refcounted_keyed_service.h"
#include "content/public/browser/browser_thread.h"
namespace cast_channel {
@@ -20,9 +20,9 @@ namespace cast_channel {
// to underlying storage.
// Instance of this class is created on the UI thread and destroyed on the IO
// thread. All public API must be called from the IO thread.
-class CastSocketService : public RefcountedKeyedService {
+class CastSocketService {
public:
- CastSocketService();
+ static CastSocketService* GetInstance();
// Returns a pointer to the Logger member variable.
scoped_refptr<cast_channel::Logger> GetLogger();
@@ -77,24 +77,20 @@ class CastSocketService : public RefcountedKeyedService {
const CastSocket::OnOpenCallback& open_cb,
CastSocket::Observer* observer);
- // Returns an observer corresponding to |id|.
- CastSocket::Observer* GetObserver(const std::string& id);
-
- // Adds |observer| to |socket_observer_map_| keyed by |id|. Return raw pointer
- // of the newly added observer.
- CastSocket::Observer* AddObserver(
- const std::string& id,
- std::unique_ptr<CastSocket::Observer> observer);
+ // Remove |observer| from each socket in |sockets_|
+ void RemoveObserver(CastSocket::Observer* observer);
// Allow test to inject a mock cast socket.
void SetSocketForTest(std::unique_ptr<CastSocket> socket_for_test);
- protected:
- ~CastSocketService() override;
-
private:
- // RefcountedKeyedService implementation.
- void ShutdownOnUIThread() override;
+ friend class CastSocketServiceTest;
+ friend class MockCastSocketService;
+ friend struct base::DefaultSingletonTraits<CastSocketService>;
+ friend struct std::default_delete<CastSocketService>;
+
+ CastSocketService();
+ virtual ~CastSocketService();
// Used to generate CastSocket id.
static int last_channel_id_;
@@ -102,13 +98,7 @@ class CastSocketService : public RefcountedKeyedService {
// The collection of CastSocket keyed by channel_id.
std::map<int, std::unique_ptr<CastSocket>> sockets_;
- // Map of CastSocket::Observer keyed by observer id. For extension side
- // observers, id is extension_id; For browser side observers, id is a hard
- // coded string.
- std::map<std::string, std::unique_ptr<CastSocket::Observer>>
- socket_observer_map_;
-
- scoped_refptr<cast_channel::Logger> logger_;
+ scoped_refptr<Logger> logger_;
std::unique_ptr<CastSocket> socket_for_test_;
« no previous file with comments | « components/cast_channel/cast_socket.cc ('k') | components/cast_channel/cast_socket_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698