| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/streams/stream_context.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/browser/streams/stream_registry.h" | |
| 9 #include "content/public/browser/browser_context.h" | |
| 10 | |
| 11 using base::UserDataAdapter; | |
| 12 | |
| 13 namespace { | |
| 14 const char* kStreamContextKeyName = "content_stream_context"; | |
| 15 } | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 StreamContext::StreamContext() {} | |
| 20 | |
| 21 StreamContext* StreamContext::GetFor(BrowserContext* context) { | |
| 22 if (!context->GetUserData(kStreamContextKeyName)) { | |
| 23 scoped_refptr<StreamContext> stream = new StreamContext(); | |
| 24 context->SetUserData(kStreamContextKeyName, | |
| 25 new UserDataAdapter<StreamContext>(stream)); | |
| 26 // Check first to avoid memory leak in unittests. | |
| 27 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | |
| 28 BrowserThread::PostTask( | |
| 29 BrowserThread::IO, FROM_HERE, | |
| 30 base::Bind(&StreamContext::InitializeOnIOThread, stream)); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 return UserDataAdapter<StreamContext>::Get(context, kStreamContextKeyName); | |
| 35 } | |
| 36 | |
| 37 void StreamContext::InitializeOnIOThread() { | |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 39 registry_.reset(new StreamRegistry()); | |
| 40 } | |
| 41 | |
| 42 StreamContext::~StreamContext() {} | |
| 43 | |
| 44 } // namespace content | |
| OLD | NEW |