summaryrefslogtreecommitdiffstats
path: root/content/browser/streams/stream_context.cc
diff options
context:
space:
mode:
authorzork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-11 03:43:16 +0000
committerzork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-11 03:43:16 +0000
commit2ebbb66ffd2591311ec4b4049b03310ee7fefb21 (patch)
treed92eb1d34828baee002ea26dccf868139eb5bf6c /content/browser/streams/stream_context.cc
parent9997d2396ff1cb7eea3cdaca6c9f204b02d8ca21 (diff)
downloadchromium_src-2ebbb66ffd2591311ec4b4049b03310ee7fefb21.zip
chromium_src-2ebbb66ffd2591311ec4b4049b03310ee7fefb21.tar.gz
chromium_src-2ebbb66ffd2591311ec4b4049b03310ee7fefb21.tar.bz2
Implement the Stream registry in content
This is the first part of the content side of the Streams api. See: https://bugs.webkit.org/show_bug.cgi?id=110194 https://dvcs.w3.org/hg/streams-api/raw-file/tip/Overview.htm BUG=171585 Review URL: https://chromiumcodereview.appspot.com/12335087 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187230 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/streams/stream_context.cc')
-rw-r--r--content/browser/streams/stream_context.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/content/browser/streams/stream_context.cc b/content/browser/streams/stream_context.cc
new file mode 100644
index 0000000..ca77df1
--- /dev/null
+++ b/content/browser/streams/stream_context.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2013 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 "content/browser/streams/stream_context.h"
+
+#include "base/bind.h"
+#include "content/browser/streams/stream_registry.h"
+#include "content/public/browser/browser_context.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));
+ // Check first to avoid memory leak in unittests.
+ 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() {}
+
+} // namespace content