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

Unified Diff: content/browser/streams/stream_context.cc

Issue 12335087: Implement the Stream registry in content (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Code review fixes Created 7 years, 9 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
« no previous file with comments | « content/browser/streams/stream_context.h ('k') | content/browser/streams/stream_read_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/streams/stream_context.cc
diff --git a/content/browser/streams/stream_context.cc b/content/browser/streams/stream_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca77df1722ce3692f489f9474ebd5751bbe41e8a
--- /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
« no previous file with comments | « content/browser/streams/stream_context.h ('k') | content/browser/streams/stream_read_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698