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 content { | |
14 | |
15 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.
| |
16 | |
17 StreamContext::StreamContext() {} | |
18 | |
19 StreamContext* StreamContext::GetFor(BrowserContext* context) { | |
20 if (!context->GetUserData(kStreamContextKeyName)) { | |
21 scoped_refptr<StreamContext> stream = new StreamContext(); | |
22 context->SetUserData(kStreamContextKeyName, | |
23 new UserDataAdapter<StreamContext>(stream)); | |
24 // Check first to avoid memory leak in unittests. | |
25 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | |
26 BrowserThread::PostTask( | |
27 BrowserThread::IO, FROM_HERE, | |
28 base::Bind(&StreamContext::InitializeOnIOThread, stream)); | |
29 } | |
30 } | |
31 | |
32 return UserDataAdapter<StreamContext>::Get(context, kStreamContextKeyName); | |
33 } | |
34 | |
35 void StreamContext::InitializeOnIOThread() { | |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
37 registry_.reset(new StreamRegistry()); | |
38 } | |
39 | |
40 StreamContext::~StreamContext() {} | |
41 | |
42 } // namespace content | |
OLD | NEW |