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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/cast_channel/cast_channel_service.cc
diff --git a/extensions/browser/api/cast_channel/cast_channel_service.cc b/extensions/browser/api/cast_channel/cast_channel_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2efabb119cd43ea5ec67fbfeb471c21f9c8c7055
--- /dev/null
+++ b/extensions/browser/api/cast_channel/cast_channel_service.cc
@@ -0,0 +1,51 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/browser/api/cast_channel/cast_channel_service.h"
+
+#include "base/memory/ptr_util.h"
+
+namespace extensions {
+namespace api {
+namespace cast_channel {
+
+CastSocketData::CastSocketData() = default;
+
+CastSocketData::~CastSocketData() {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+}
+
+int CastSocketData::AddSocket(CastSocket* socket) {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK(socket);
+ 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.
+ sockets_.insert(std::make_pair(id, base::WrapUnique(socket)));
+ socket->set_id(id);
+ return id;
+}
+
+void CastSocketData::RemoveSocket(int channel_id) {
+ 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.
+ sockets_.erase(channel_id);
+}
+
+CastSocket* CastSocketData::GetSocket(int channel_id) const {
+ 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.
+ const auto& socket_it = sockets_.find(channel_id);
+ return socket_it == sockets_.end() ? nullptr : socket_it->second.get();
+}
+
+CastChannelService::CastChannelService() = default;
+CastChannelService::~CastChannelService() = default;
+
+CastSocketData* CastChannelService::GetOrCreateSocketData() {
+ 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.
+ if (!sockets_)
+ sockets_.reset(new CastSocketData());
+ return sockets_.get();
+}
+
+} // namespace cast_channel
+} // namespace api
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698