Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_ |
| 6 #define MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_ | 6 #define MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/sequenced_task_runner.h" | |
| 12 | 14 |
| 13 namespace base { | 15 namespace base { |
| 14 class FilePath; | 16 class FilePath; |
| 15 } | 17 } |
| 16 | 18 |
| 17 namespace net { | 19 namespace net { |
| 18 class URLRequestContext; | 20 class URLRequestContext; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace mojo { | 23 namespace mojo { |
| 22 class URLLoader; | 24 class URLLoader; |
| 23 class URLLoaderImpl; | 25 class URLLoaderImpl; |
| 24 | 26 |
| 25 class NetworkContext { | 27 class NetworkContext { |
| 26 public: | 28 public: |
| 27 explicit NetworkContext( | 29 explicit NetworkContext( |
| 28 scoped_ptr<net::URLRequestContext> url_request_context); | 30 scoped_ptr<net::URLRequestContext> url_request_context); |
| 29 explicit NetworkContext(const base::FilePath& base_path); | 31 explicit NetworkContext( |
|
jam
2015/06/25 15:28:24
nit: no explicit
| |
| 32 const base::FilePath& base_path, | |
| 33 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); | |
| 30 ~NetworkContext(); | 34 ~NetworkContext(); |
| 31 | 35 |
| 32 net::URLRequestContext* url_request_context() { | 36 net::URLRequestContext* url_request_context() { |
| 33 return url_request_context_.get(); | 37 return url_request_context_.get(); |
| 34 } | 38 } |
| 35 | 39 |
| 36 // These are called by individual url loaders as they are being created and | 40 // These are called by individual url loaders as they are being created and |
| 37 // destroyed. | 41 // destroyed. |
| 38 void RegisterURLLoader(URLLoaderImpl* url_loader); | 42 void RegisterURLLoader(URLLoaderImpl* url_loader); |
| 39 void DeregisterURLLoader(URLLoaderImpl* url_loader); | 43 void DeregisterURLLoader(URLLoaderImpl* url_loader); |
| 40 | 44 |
| 41 private: | 45 private: |
| 42 friend class UrlLoaderImplTest; | 46 friend class UrlLoaderImplTest; |
| 43 size_t GetURLLoaderCountForTesting(); | 47 size_t GetURLLoaderCountForTesting(); |
| 44 | 48 |
| 45 static scoped_ptr<net::URLRequestContext> MakeURLRequestContext( | 49 static scoped_ptr<net::URLRequestContext> MakeURLRequestContext( |
| 46 const base::FilePath& base_path); | 50 const base::FilePath& base_path, |
| 51 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); | |
| 47 | 52 |
| 48 class MojoNetLog; | 53 class MojoNetLog; |
| 49 scoped_ptr<class MojoNetLog> net_log_; | 54 scoped_ptr<class MojoNetLog> net_log_; |
| 50 | 55 |
| 51 scoped_ptr<net::URLRequestContext> url_request_context_; | 56 scoped_ptr<net::URLRequestContext> url_request_context_; |
| 52 // URLLoaderImpls register themselves with the NetworkContext so that they can | 57 // URLLoaderImpls register themselves with the NetworkContext so that they can |
| 53 // be cleaned up when the NetworkContext goes away. This is needed as | 58 // be cleaned up when the NetworkContext goes away. This is needed as |
| 54 // net::URLRequests held by URLLoaderImpls have to be gone when | 59 // net::URLRequests held by URLLoaderImpls have to be gone when |
| 55 // net::URLRequestContext (held by NetworkContext) is destroyed. | 60 // net::URLRequestContext (held by NetworkContext) is destroyed. |
| 56 std::set<URLLoaderImpl*> url_loaders_; | 61 std::set<URLLoaderImpl*> url_loaders_; |
| 57 | 62 |
| 58 // Set when entering the destructor, in order to avoid manipulations of the | 63 // Set when entering the destructor, in order to avoid manipulations of the |
| 59 // |url_loaders_| (as a url_loader might delete itself in Cleanup()). | 64 // |url_loaders_| (as a url_loader might delete itself in Cleanup()). |
| 60 bool in_shutdown_; | 65 bool in_shutdown_; |
| 61 | 66 |
| 62 DISALLOW_COPY_AND_ASSIGN(NetworkContext); | 67 DISALLOW_COPY_AND_ASSIGN(NetworkContext); |
| 63 }; | 68 }; |
| 64 | 69 |
| 65 } // namespace mojo | 70 } // namespace mojo |
| 66 | 71 |
| 67 #endif // MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_ | 72 #endif // MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_ |
| OLD | NEW |