Decouple Cache Storage messaging from Service Worker/Embedded Worker
[chromium-blink-merge.git] / content / browser / streams / stream_context.h
blobad8f65cb6383a2cc0c9663b35c99135f54985cd2
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"
13 namespace content {
14 class BrowserContext;
15 class StreamRegistry;
16 struct StreamContextDeleter;
18 // A context class that keeps track of StreamRegistry used by the chrome.
19 // There is an instance associated with each BrowserContext. There could be
20 // multiple URLRequestContexts in the same browser context that refers to the
21 // same instance.
23 // All methods, except the ctor, are expected to be called on
24 // the IO thread (unless specifically called out in doc comments).
25 class StreamContext
26 : public base::RefCountedThreadSafe<StreamContext,
27 StreamContextDeleter> {
28 public:
29 StreamContext();
31 CONTENT_EXPORT static StreamContext* GetFor(BrowserContext* browser_context);
33 void InitializeOnIOThread();
35 StreamRegistry* registry() const { return registry_.get(); }
37 protected:
38 virtual ~StreamContext();
40 private:
41 friend class base::DeleteHelper<StreamContext>;
42 friend class base::RefCountedThreadSafe<StreamContext,
43 StreamContextDeleter>;
44 friend struct StreamContextDeleter;
46 void DeleteOnCorrectThread() const;
48 scoped_ptr<StreamRegistry> registry_;
51 struct StreamContextDeleter {
52 static void Destruct(const StreamContext* context) {
53 context->DeleteOnCorrectThread();
57 } // namespace content
59 #endif // CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_