This source file includes following definitions.
- GetFor
- InitializeOnIOThread
- DeleteOnCorrectThread
#include "content/browser/streams/stream_context.h"
#include "base/bind.h"
#include "content/browser/streams/stream_registry.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
using base::UserDataAdapter;
namespace {
const char* kStreamContextKeyName = "content_stream_context";
}
namespace content {
StreamContext::StreamContext() {}
StreamContext* StreamContext::GetFor(BrowserContext* context) {
if (!context->GetUserData(kStreamContextKeyName)) {
scoped_refptr<StreamContext> stream = new StreamContext();
context->SetUserData(kStreamContextKeyName,
new UserDataAdapter<StreamContext>(stream.get()));
if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&StreamContext::InitializeOnIOThread, stream));
}
}
return UserDataAdapter<StreamContext>::Get(context, kStreamContextKeyName);
}
void StreamContext::InitializeOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
registry_.reset(new StreamRegistry());
}
StreamContext::~StreamContext() {}
void StreamContext::DeleteOnCorrectThread() const {
if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) &&
!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
return;
}
delete this;
}
}