| OLD | NEW |
| 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/common/content_export.h" |
| 11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 class BrowserContext; | 15 class BrowserContext; |
| 15 class StreamRegistry; | 16 class StreamRegistry; |
| 16 struct StreamContextDeleter; | 17 struct StreamContextDeleter; |
| 17 | 18 |
| 18 // A context class that keeps track of StreamRegistry used by the chrome. | 19 // 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 // There is an instance associated with each BrowserContext. There could be |
| 20 // multiple URLRequestContexts in the same browser context that refers to the | 21 // multiple URLRequestContexts in the same browser context that refers to the |
| 21 // same instance. | 22 // same instance. |
| 22 // | 23 // |
| 23 // All methods, except the ctor, are expected to be called on | 24 // All methods, except the ctor, are expected to be called on |
| 24 // the IO thread (unless specifically called out in doc comments). | 25 // the IO thread (unless specifically called out in doc comments). |
| 25 class StreamContext | 26 class StreamContext |
| 26 : public base::RefCountedThreadSafe<StreamContext, | 27 : public base::RefCountedThreadSafe<StreamContext, |
| 27 StreamContextDeleter> { | 28 StreamContextDeleter> { |
| 28 public: | 29 public: |
| 29 StreamContext(); | 30 StreamContext(); |
| 30 | 31 |
| 31 static StreamContext* GetFor(BrowserContext* browser_context); | 32 CONTENT_EXPORT static StreamContext* GetFor(BrowserContext* browser_context); |
| 32 | 33 |
| 33 void InitializeOnIOThread(); | 34 void InitializeOnIOThread(); |
| 34 | 35 |
| 35 StreamRegistry* registry() const { return registry_.get(); } | 36 StreamRegistry* registry() const { return registry_.get(); } |
| 36 | 37 |
| 37 protected: | 38 protected: |
| 38 virtual ~StreamContext(); | 39 virtual ~StreamContext(); |
| 39 | 40 |
| 40 private: | 41 private: |
| 41 friend class base::DeleteHelper<StreamContext>; | 42 friend class base::DeleteHelper<StreamContext>; |
| 42 friend class base::RefCountedThreadSafe<StreamContext, | 43 friend class base::RefCountedThreadSafe<StreamContext, |
| 43 StreamContextDeleter>; | 44 StreamContextDeleter>; |
| 44 friend struct StreamContextDeleter; | 45 friend struct StreamContextDeleter; |
| 45 | 46 |
| 46 void DeleteOnCorrectThread() const; | 47 void DeleteOnCorrectThread() const; |
| 47 | 48 |
| 48 scoped_ptr<StreamRegistry> registry_; | 49 scoped_ptr<StreamRegistry> registry_; |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 struct StreamContextDeleter { | 52 struct StreamContextDeleter { |
| 52 static void Destruct(const StreamContext* context) { | 53 static void Destruct(const StreamContext* context) { |
| 53 context->DeleteOnCorrectThread(); | 54 context->DeleteOnCorrectThread(); |
| 54 } | 55 } |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 } // namespace content | 58 } // namespace content |
| 58 | 59 |
| 59 #endif // CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_ | 60 #endif // CONTENT_BROWSER_STREAMS_STREAM_CONTEXT_H_ |
| 60 | |
| OLD | NEW |