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