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/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/sequenced_task_runner.h"
20 class URLRequestContext
;
26 class NetworkServiceDelegate
;
28 class NetworkContext
{
30 explicit NetworkContext(
31 scoped_ptr
<net::URLRequestContext
> url_request_context
);
33 const base::FilePath
& base_path
,
34 const scoped_refptr
<base::SequencedTaskRunner
>& background_task_runner
,
35 NetworkServiceDelegate
* delegate
);
38 net::URLRequestContext
* url_request_context() {
39 return url_request_context_
.get();
42 // These are called by individual url loaders as they are being created and
44 void RegisterURLLoader(URLLoaderImpl
* url_loader
);
45 void DeregisterURLLoader(URLLoaderImpl
* url_loader
);
48 friend class UrlLoaderImplTest
;
49 size_t GetURLLoaderCountForTesting();
51 static scoped_ptr
<net::URLRequestContext
> MakeURLRequestContext(
52 const base::FilePath
& base_path
,
53 const scoped_refptr
<base::SequencedTaskRunner
>& background_task_runner
,
54 NetworkServiceDelegate
* delegate
);
57 scoped_ptr
<class MojoNetLog
> net_log_
;
59 scoped_ptr
<net::URLRequestContext
> url_request_context_
;
60 // URLLoaderImpls register themselves with the NetworkContext so that they can
61 // be cleaned up when the NetworkContext goes away. This is needed as
62 // net::URLRequests held by URLLoaderImpls have to be gone when
63 // net::URLRequestContext (held by NetworkContext) is destroyed.
64 std::set
<URLLoaderImpl
*> url_loaders_
;
66 // Set when entering the destructor, in order to avoid manipulations of the
67 // |url_loaders_| (as a url_loader might delete itself in Cleanup()).
70 DISALLOW_COPY_AND_ASSIGN(NetworkContext
);
75 #endif // MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_