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

Side by Side Diff: content/browser/streams/stream_context.cc

Issue 2815913005: Switch to using scoped_ptr with UserData (Closed)
Patch Set: fixes Created 3 years, 8 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/streams/stream_context.h" 5 #include "content/browser/streams/stream_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h"
8 #include "content/browser/streams/stream_registry.h" 9 #include "content/browser/streams/stream_registry.h"
9 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 12
12 using base::UserDataAdapter; 13 using base::UserDataAdapter;
13 14
14 namespace { 15 namespace {
15 16
16 const char kStreamContextKeyName[] = "content_stream_context"; 17 const char kStreamContextKeyName[] = "content_stream_context";
17 18
18 } // namespace 19 } // namespace
19 20
20 namespace content { 21 namespace content {
21 22
22 StreamContext::StreamContext() {} 23 StreamContext::StreamContext() {}
23 24
24 StreamContext* StreamContext::GetFor(BrowserContext* context) { 25 StreamContext* StreamContext::GetFor(BrowserContext* context) {
25 if (!context->GetUserData(kStreamContextKeyName)) { 26 if (!context->GetUserData(kStreamContextKeyName)) {
26 scoped_refptr<StreamContext> stream = new StreamContext(); 27 scoped_refptr<StreamContext> stream = new StreamContext();
27 context->SetUserData(kStreamContextKeyName, 28 context->SetUserData(
28 new UserDataAdapter<StreamContext>(stream.get())); 29 kStreamContextKeyName,
30 base::MakeUnique<UserDataAdapter<StreamContext>>(stream.get()));
29 // Check first to avoid memory leak in unittests. 31 // Check first to avoid memory leak in unittests.
30 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { 32 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
31 BrowserThread::PostTask( 33 BrowserThread::PostTask(
32 BrowserThread::IO, FROM_HERE, 34 BrowserThread::IO, FROM_HERE,
33 base::Bind(&StreamContext::InitializeOnIOThread, stream)); 35 base::Bind(&StreamContext::InitializeOnIOThread, stream));
34 } 36 }
35 } 37 }
36 38
37 return UserDataAdapter<StreamContext>::Get(context, kStreamContextKeyName); 39 return UserDataAdapter<StreamContext>::Get(context, kStreamContextKeyName);
38 } 40 }
(...skipping 12 matching lines...) Expand all
51 // tests. 53 // tests.
52 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && 54 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) &&
53 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { 55 !BrowserThread::CurrentlyOn(BrowserThread::IO)) {
54 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); 56 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
55 return; 57 return;
56 } 58 }
57 delete this; 59 delete this;
58 } 60 }
59 61
60 } // namespace content 62 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698