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; |
| 26 class NetworkServiceDelegate; |
24 | 27 |
25 class NetworkContext { | 28 class NetworkContext { |
26 public: | 29 public: |
27 explicit NetworkContext( | 30 explicit NetworkContext( |
28 scoped_ptr<net::URLRequestContext> url_request_context); | 31 scoped_ptr<net::URLRequestContext> url_request_context); |
29 explicit NetworkContext(const base::FilePath& base_path); | 32 NetworkContext( |
| 33 const base::FilePath& base_path, |
| 34 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, |
| 35 NetworkServiceDelegate* delegate); |
30 ~NetworkContext(); | 36 ~NetworkContext(); |
31 | 37 |
32 net::URLRequestContext* url_request_context() { | 38 net::URLRequestContext* url_request_context() { |
33 return url_request_context_.get(); | 39 return url_request_context_.get(); |
34 } | 40 } |
35 | 41 |
36 // These are called by individual url loaders as they are being created and | 42 // These are called by individual url loaders as they are being created and |
37 // destroyed. | 43 // destroyed. |
38 void RegisterURLLoader(URLLoaderImpl* url_loader); | 44 void RegisterURLLoader(URLLoaderImpl* url_loader); |
39 void DeregisterURLLoader(URLLoaderImpl* url_loader); | 45 void DeregisterURLLoader(URLLoaderImpl* url_loader); |
40 | 46 |
41 private: | 47 private: |
42 friend class UrlLoaderImplTest; | 48 friend class UrlLoaderImplTest; |
43 size_t GetURLLoaderCountForTesting(); | 49 size_t GetURLLoaderCountForTesting(); |
44 | 50 |
45 static scoped_ptr<net::URLRequestContext> MakeURLRequestContext( | 51 static scoped_ptr<net::URLRequestContext> MakeURLRequestContext( |
46 const base::FilePath& base_path); | 52 const base::FilePath& base_path, |
| 53 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, |
| 54 NetworkServiceDelegate* delegate); |
47 | 55 |
48 class MojoNetLog; | 56 class MojoNetLog; |
49 scoped_ptr<class MojoNetLog> net_log_; | 57 scoped_ptr<class MojoNetLog> net_log_; |
50 | 58 |
51 scoped_ptr<net::URLRequestContext> url_request_context_; | 59 scoped_ptr<net::URLRequestContext> url_request_context_; |
52 // URLLoaderImpls register themselves with the NetworkContext so that they can | 60 // URLLoaderImpls register themselves with the NetworkContext so that they can |
53 // be cleaned up when the NetworkContext goes away. This is needed as | 61 // be cleaned up when the NetworkContext goes away. This is needed as |
54 // net::URLRequests held by URLLoaderImpls have to be gone when | 62 // net::URLRequests held by URLLoaderImpls have to be gone when |
55 // net::URLRequestContext (held by NetworkContext) is destroyed. | 63 // net::URLRequestContext (held by NetworkContext) is destroyed. |
56 std::set<URLLoaderImpl*> url_loaders_; | 64 std::set<URLLoaderImpl*> url_loaders_; |
57 | 65 |
58 // Set when entering the destructor, in order to avoid manipulations of the | 66 // Set when entering the destructor, in order to avoid manipulations of the |
59 // |url_loaders_| (as a url_loader might delete itself in Cleanup()). | 67 // |url_loaders_| (as a url_loader might delete itself in Cleanup()). |
60 bool in_shutdown_; | 68 bool in_shutdown_; |
61 | 69 |
62 DISALLOW_COPY_AND_ASSIGN(NetworkContext); | 70 DISALLOW_COPY_AND_ASSIGN(NetworkContext); |
63 }; | 71 }; |
64 | 72 |
65 } // namespace mojo | 73 } // namespace mojo |
66 | 74 |
67 #endif // MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_ | 75 #endif // MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_ |
OLD | NEW |