OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/cast_channel/cast_socket_service.h" | 5 #include "components/cast_channel/cast_socket_service.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 | 9 |
10 using content::BrowserThread; | 10 using content::BrowserThread; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 return socket; | 45 return socket; |
46 } | 46 } |
47 | 47 |
48 CastSocket* CastSocketService::GetSocket(int channel_id) const { | 48 CastSocket* CastSocketService::GetSocket(int channel_id) const { |
49 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | 49 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
50 DCHECK(channel_id > 0); | 50 DCHECK(channel_id > 0); |
51 const auto& socket_it = sockets_.find(channel_id); | 51 const auto& socket_it = sockets_.find(channel_id); |
52 return socket_it == sockets_.end() ? nullptr : socket_it->second.get(); | 52 return socket_it == sockets_.end() ? nullptr : socket_it->second.get(); |
53 } | 53 } |
54 | 54 |
55 CastSocket::Observer* CastSocketService::GetObserver(const std::string& id) { | |
56 auto it = std::find_if( | |
imcheng
2017/06/21 01:22:52
It seems sufficient to just use socket_observer_ma
zhaobin
2017/06/21 17:48:13
Done.
| |
57 socket_observer_map_.begin(), socket_observer_map_.end(), | |
58 [id](const std::pair<const std::string, | |
59 std::unique_ptr<CastSocket::Observer>>& entry) { | |
60 return entry.first == id; | |
61 }); | |
62 return it == socket_observer_map_.end() ? nullptr : it->second.get(); | |
63 } | |
64 | |
65 CastSocket::Observer* CastSocketService::AddObserver( | |
66 const std::string& id, | |
67 std::unique_ptr<CastSocket::Observer> observer) { | |
68 CastSocket::Observer* observer_ptr = observer.get(); | |
69 socket_observer_map_.insert(std::make_pair(id, std::move(observer))); | |
70 return observer_ptr; | |
71 } | |
72 | |
55 void CastSocketService::ShutdownOnUIThread() {} | 73 void CastSocketService::ShutdownOnUIThread() {} |
56 | 74 |
57 } // namespace cast_channel | 75 } // namespace cast_channel |
OLD | NEW |