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

Unified Diff: extensions/browser/api/cast_channel/cast_channel_api.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_api.cc
diff --git a/extensions/browser/api/cast_channel/cast_channel_api.cc b/extensions/browser/api/cast_channel/cast_channel_api.cc
index 7f64f24d24dd63d99ea3624fde9096a4438823e3..2e832b57d2a807fcfb4acb02701ad8efaee2c140 100644
--- a/extensions/browser/api/cast_channel/cast_channel_api.cc
+++ b/extensions/browser/api/cast_channel/cast_channel_api.cc
@@ -19,6 +19,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "content/public/browser/browser_thread.h"
+#include "extensions/browser/api/cast_channel/cast_channel_service.h"
+#include "extensions/browser/api/cast_channel/cast_channel_service_factory.h"
#include "extensions/browser/api/cast_channel/cast_message_util.h"
#include "extensions/browser/api/cast_channel/cast_socket.h"
#include "extensions/browser/api/cast_channel/keep_alive_delegate.h"
@@ -165,15 +167,16 @@ std::unique_ptr<base::Timer> CastChannelAPI::GetInjectedTimeoutTimerForTest() {
CastChannelAPI::~CastChannelAPI() {}
-CastChannelAsyncApiFunction::CastChannelAsyncApiFunction() {
-}
+CastChannelAsyncApiFunction::CastChannelAsyncApiFunction()
+ : cast_channel_service_(nullptr) {}
CastChannelAsyncApiFunction::~CastChannelAsyncApiFunction() { }
bool CastChannelAsyncApiFunction::PrePrepare() {
- DCHECK(ApiResourceManager<CastSocket>::Get(browser_context()));
- sockets_ = ApiResourceManager<CastSocket>::Get(browser_context())->data_;
- DCHECK(sockets_);
+ cast_channel_service_ =
+ api::cast_channel::CastChannelServiceFactory::GetInstance()
+ ->GetForBrowserContext(browser_context());
+ DCHECK(cast_channel_service_);
return true;
}
@@ -193,16 +196,13 @@ CastSocket* CastChannelAsyncApiFunction::GetSocketOrCompleteWithError(
}
int CastChannelAsyncApiFunction::AddSocket(CastSocket* socket) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- DCHECK(socket);
- const int id = sockets_->Add(socket);
- socket->set_id(id);
- return id;
+ auto* sockets = cast_channel_service_->GetOrCreateSocketData();
+ return sockets->AddSocket(socket);
}
void CastChannelAsyncApiFunction::RemoveSocket(int channel_id) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- sockets_->Remove(extension_->id(), channel_id);
+ auto* sockets = cast_channel_service_->GetOrCreateSocketData();
+ sockets->RemoveSocket(channel_id);
}
void CastChannelAsyncApiFunction::SetResultFromSocket(
@@ -230,8 +230,8 @@ void CastChannelAsyncApiFunction::SetResultFromError(int channel_id,
}
CastSocket* CastChannelAsyncApiFunction::GetSocket(int channel_id) const {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- return sockets_->Get(extension_->id(), channel_id);
+ auto* sockets = cast_channel_service_->GetOrCreateSocketData();
+ return sockets->GetSocket(channel_id);
}
void CastChannelAsyncApiFunction::SetResultFromChannelInfo(

Powered by Google App Engine
This is Rietveld 408576698