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

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

Issue 12615004: Fix heapcheck errors (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add comment Created 7 years, 9 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 #ifndef CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_ 5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_
6 #define CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_ 6 #define CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/sequenced_task_runner_helpers.h" 10 #include "base/sequenced_task_runner_helpers.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 12
13 namespace content { 13 namespace content {
14 class BrowserContext; 14 class BrowserContext;
15 class StreamRegistry; 15 class StreamRegistry;
16 struct StreamContextDeleter;
16 17
17 // A context class that keeps track of StreamRegistry used by the chrome. 18 // A context class that keeps track of StreamRegistry used by the chrome.
18 // There is an instance associated with each BrowserContext. There could be 19 // There is an instance associated with each BrowserContext. There could be
19 // multiple URLRequestContexts in the same browser context that refers to the 20 // multiple URLRequestContexts in the same browser context that refers to the
20 // same instance. 21 // same instance.
21 // 22 //
22 // All methods, except the ctor, are expected to be called on 23 // All methods, except the ctor, are expected to be called on
23 // the IO thread (unless specifically called out in doc comments). 24 // the IO thread (unless specifically called out in doc comments).
24 class StreamContext 25 class StreamContext
25 : public base::RefCountedThreadSafe<StreamContext, 26 : public base::RefCountedThreadSafe<StreamContext,
26 BrowserThread::DeleteOnIOThread> { 27 StreamContextDeleter> {
27 public: 28 public:
28 StreamContext(); 29 StreamContext();
29 30
30 static StreamContext* GetFor(BrowserContext* browser_context); 31 static StreamContext* GetFor(BrowserContext* browser_context);
31 32
32 void InitializeOnIOThread(); 33 void InitializeOnIOThread();
33 34
34 StreamRegistry* registry() const { return registry_.get(); } 35 StreamRegistry* registry() const { return registry_.get(); }
35 36
36 protected: 37 protected:
37 virtual ~StreamContext(); 38 virtual ~StreamContext();
38 39
39 private: 40 private:
40 friend class base::DeleteHelper<StreamContext>; 41 friend class base::DeleteHelper<StreamContext>;
41 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; 42 friend class base::RefCountedThreadSafe<StreamContext,
43 StreamContextDeleter>;
44 friend struct StreamContextDeleter;
45
46 void DeleteOnCorrectThread() const;
42 47
43 scoped_ptr<StreamRegistry> registry_; 48 scoped_ptr<StreamRegistry> registry_;
44 }; 49 };
45 50
51 struct StreamContextDeleter {
52 static void Destruct(const StreamContext* context) {
53 context->DeleteOnCorrectThread();
54 }
55 };
56
46 } // namespace content 57 } // namespace content
47 58
48 #endif // CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_ 59 #endif // CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_
49 60
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698