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

Side by Side Diff: extensions/browser/api/cast_channel/cast_channel_service.cc

Issue 2891023002: [cast_channel] Make CastSocket not inherit from ApiResource (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(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 #include "extensions/browser/api/cast_channel/cast_channel_service.h"
6
7 #include "base/memory/ptr_util.h"
8
9 namespace extensions {
10 namespace api {
11 namespace cast_channel {
12
13 CastSocketData::CastSocketData() = default;
14
15 CastSocketData::~CastSocketData() {
16 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
17 }
18
19 int CastSocketData::AddSocket(CastSocket* socket) {
20 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
21 DCHECK(socket);
22 int id = sockets_.size() + 1;
mark a. foltz 2017/05/18 18:02:26 This will assign duplicate ids as the size of sock
zhaobin 2017/05/24 01:51:39 Done.
23 sockets_.insert(std::make_pair(id, base::WrapUnique(socket)));
24 socket->set_id(id);
25 return id;
26 }
27
28 void CastSocketData::RemoveSocket(int channel_id) {
29 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
mark a. foltz 2017/05/18 18:02:26 DCHECK(channel_id > 0)
zhaobin 2017/05/24 01:51:39 Done.
30 sockets_.erase(channel_id);
31 }
32
33 CastSocket* CastSocketData::GetSocket(int channel_id) const {
34 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
mark a. foltz 2017/05/18 19:12:04 DCHECK(channel_id > 0)
zhaobin 2017/05/24 01:51:39 Done.
35 const auto& socket_it = sockets_.find(channel_id);
36 return socket_it == sockets_.end() ? nullptr : socket_it->second.get();
37 }
38
39 CastChannelService::CastChannelService() = default;
40 CastChannelService::~CastChannelService() = default;
41
42 CastSocketData* CastChannelService::GetOrCreateSocketData() {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
mark a. foltz 2017/05/18 18:02:26 Since sockets_ is created on the IO thread it foll
zhaobin 2017/05/24 01:51:39 Seems unable to use |thread_checker_| here. CastCh
mark a. foltz 2017/05/24 17:44:10 This should be called out in the comments.
zhaobin 2017/05/24 18:12:57 Done.
44 if (!sockets_)
45 sockets_.reset(new CastSocketData());
46 return sockets_.get();
47 }
48
49 } // namespace cast_channel
50 } // namespace api
51 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698