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

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

Issue 12212031: Add support for redirecting ResourceHandlers to a blob: URL (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 10 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: content/browser/streams/chrome_stream_context.cc
diff --git a/content/browser/streams/chrome_stream_context.cc b/content/browser/streams/chrome_stream_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bd8807c254e15b344f06ef47e81834b357b2d5d5
--- /dev/null
+++ b/content/browser/streams/chrome_stream_context.cc
@@ -0,0 +1,55 @@
+// 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/chrome_stream_context.h"
+
+#include "base/bind.h"
+#include "content/browser/streams/chrome_stream_registry.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+
+using base::UserDataAdapter;
+
+namespace content {
+
+static const char* kStreamContextKeyName = "content_stream_context";
+
+ChromeStreamContext::ChromeStreamContext() {}
+
+ChromeStreamContext* ChromeStreamContext::GetFor(
+ BrowserContext* context) {
+ if (!context->GetUserData(kStreamContextKeyName)) {
+ scoped_refptr<ChromeStreamContext> blob =
+ new ChromeStreamContext();
+ context->SetUserData(kStreamContextKeyName,
+ new UserDataAdapter<ChromeStreamContext>(blob));
+ // Check first to avoid memory leak in unittests.
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ChromeStreamContext::InitializeOnIOThread, blob));
+ }
+ }
+
+ return UserDataAdapter<ChromeStreamContext>::Get(
+ context, kStreamContextKeyName);
+}
+
+void ChromeStreamContext::InitializeOnIOThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ registry_.reset(new ChromeStreamRegistry());
+}
+
+ChromeStreamContext::~ChromeStreamContext() {}
+
+void ChromeStreamContext::DeleteOnCorrectThread() const {
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) &&
+ !BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
+ return;
+ }
+ delete this;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698