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
3 // found in the LICENSE file.
5 #ifndef MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_
6 #define MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
18 class URLRequestContext
;
25 class NetworkContext
{
27 explicit NetworkContext(
28 scoped_ptr
<net::URLRequestContext
> url_request_context
);
29 explicit NetworkContext(const base::FilePath
& base_path
);
32 net::URLRequestContext
* url_request_context() {
33 return url_request_context_
.get();
36 // These are called by individual url loaders as they are being created and
38 void RegisterURLLoader(URLLoaderImpl
* url_loader
);
39 void DeregisterURLLoader(URLLoaderImpl
* url_loader
);
42 friend class UrlLoaderImplTest
;
43 size_t GetURLLoaderCountForTesting();
45 static scoped_ptr
<net::URLRequestContext
> MakeURLRequestContext(
46 const base::FilePath
& base_path
);
48 scoped_ptr
<net::URLRequestContext
> url_request_context_
;
49 // URLLoaderImpls register themselves with the NetworkContext so that they can
50 // be cleaned up when the NetworkContext goes away. This is needed as
51 // net::URLRequests held by URLLoaderImpls have to be gone when
52 // net::URLRequestContext (held by NetworkContext) is destroyed.
53 std::set
<URLLoaderImpl
*> url_loaders_
;
55 // Set when entering the destructor, in order to avoid manipulations of the
56 // |url_loaders_| (as a url_loader might delete itself in Cleanup()).
59 DISALLOW_COPY_AND_ASSIGN(NetworkContext
);
64 #endif // MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_