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.
5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_
6 #define CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/sequenced_task_runner_helpers.h"
11 #include "content/common/content_export.h"
12 #include "content/public/browser/browser_thread.h"
17 struct StreamContextDeleter;
19 // A context class that keeps track of StreamRegistry used by the chrome.
20 // There is an instance associated with each BrowserContext. There could be
21 // multiple URLRequestContexts in the same browser context that refers to the
24 // All methods, except the ctor, are expected to be called on
25 // the IO thread (unless specifically called out in doc comments).
27 : public base::RefCountedThreadSafe<StreamContext,
28 StreamContextDeleter> {
32 CONTENT_EXPORT static StreamContext* GetFor(BrowserContext* browser_context);
34 void InitializeOnIOThread();
36 StreamRegistry* registry() const { return registry_.get(); }
39 virtual ~StreamContext();
42 friend class base::DeleteHelper<StreamContext>;
43 friend class base::RefCountedThreadSafe<StreamContext,
44 StreamContextDeleter>;
45 friend struct StreamContextDeleter;
47 void DeleteOnCorrectThread() const;
49 scoped_ptr<StreamRegistry> registry_;
52 struct StreamContextDeleter {
53 static void Destruct(const StreamContext* context) {
54 context->DeleteOnCorrectThread();
58 } // namespace content
60 #endif // CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_