| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | |
| 6 #define COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/threading/thread_checker.h" | |
| 13 #include "components/cast_channel/cast_socket.h" | |
| 14 #include "components/keyed_service/core/refcounted_keyed_service.h" | |
| 15 #include "content/public/browser/browser_thread.h" | |
| 16 | |
| 17 namespace cast_channel { | |
| 18 | |
| 19 // This class adds, removes, and returns cast sockets created by CastChannelAPI | |
| 20 // to underlying storage. | |
| 21 // Instance of this class is created on the UI thread and destroyed on the IO | |
| 22 // thread. All public API must be called from the IO thread. | |
| 23 class CastSocketService : public RefcountedKeyedService { | |
| 24 public: | |
| 25 CastSocketService(); | |
| 26 | |
| 27 // Adds |socket| to |sockets_| and returns the new channel_id. Takes ownership | |
| 28 // of |socket|. | |
| 29 int AddSocket(std::unique_ptr<CastSocket> socket); | |
| 30 | |
| 31 // Removes the CastSocket corresponding to |channel_id| from the | |
| 32 // CastSocketRegistry. Returns nullptr if no such CastSocket exists. | |
| 33 std::unique_ptr<CastSocket> RemoveSocket(int channel_id); | |
| 34 | |
| 35 // Returns the socket corresponding to |channel_id| if one exists, or nullptr | |
| 36 // otherwise. | |
| 37 CastSocket* GetSocket(int channel_id) const; | |
| 38 | |
| 39 private: | |
| 40 ~CastSocketService() override; | |
| 41 | |
| 42 // RefcountedKeyedService implementation. | |
| 43 void ShutdownOnUIThread() override; | |
| 44 | |
| 45 // Used to generate CastSocket id. | |
| 46 static int last_channel_id_; | |
| 47 | |
| 48 // The collection of CastSocket keyed by channel_id. | |
| 49 std::map<int, std::unique_ptr<CastSocket>> sockets_; | |
| 50 | |
| 51 THREAD_CHECKER(thread_checker_); | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(CastSocketService); | |
| 54 }; | |
| 55 | |
| 56 } // namespace cast_channel | |
| 57 | |
| 58 #endif // COMPONENTS_CAST_CHANNEL_CAST_CHANNEL_SERVICE_H_ | |
| OLD | NEW |