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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(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 #include "content/public/browser/browser_thread.h"
11
12 using base::UserDataAdapter;
13
14 namespace content {
15
16 static const char* kStreamContextKeyName = "content_stream_context";
17
18 StreamContext::StreamContext() {}
19
20 StreamContext* StreamContext::GetFor(BrowserContext* context) {
21 if (!context->GetUserData(kStreamContextKeyName)) {
22 scoped_refptr<StreamContext> stream = new StreamContext();
23 context->SetUserData(kStreamContextKeyName,
24 new UserDataAdapter<StreamContext>(stream));
25 // Check first to avoid memory leak in unittests.
26 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
27 BrowserThread::PostTask(
28 BrowserThread::IO, FROM_HERE,
29 base::Bind(&StreamContext::InitializeOnIOThread, stream));
30 }
31 }
32
33 return UserDataAdapter<StreamContext>::Get(context, kStreamContextKeyName);
34 }
35
36 void StreamContext::InitializeOnIOThread() {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
38 registry_.reset(new StreamRegistry());
39 }
40
41 StreamContext::~StreamContext() {}
42
43 void StreamContext::DeleteOnCorrectThread() const {
44 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) &&
45 !BrowserThread::CurrentlyOn(BrowserThread::IO)) {
46 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
47 return;
48 }
49 delete this;
50 }
51
52 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698