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..0c01fe288fbf0a86c65375462a8495ce1fa0dab5 |
--- /dev/null |
+++ b/content/browser/streams/stream_context.cc |
@@ -0,0 +1,42 @@ |
+// 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 content { |
+ |
+static const char* kStreamContextKeyName = "content_stream_context"; |
kinuko
2013/03/07 09:35:12
nit: maybe put this line in an anonymous namespace
Zachary Kuznia
2013/03/08 06:44:52
Done.
|
+ |
+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 |