Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / mojo / services / network / network_context.h
blob19e8e5ab42bf9856dafad15a6def5841ffc116e2
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_
8 #include <set>
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
13 namespace base {
14 class FilePath;
17 namespace net {
18 class URLRequestContext;
21 namespace mojo {
22 class URLLoader;
23 class URLLoaderImpl;
25 class NetworkContext {
26 public:
27 explicit NetworkContext(
28 scoped_ptr<net::URLRequestContext> url_request_context);
29 explicit NetworkContext(const base::FilePath& base_path);
30 ~NetworkContext();
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
37 // destroyed.
38 void RegisterURLLoader(URLLoaderImpl* url_loader);
39 void DeregisterURLLoader(URLLoaderImpl* url_loader);
41 private:
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()).
57 bool in_shutdown_;
59 DISALLOW_COPY_AND_ASSIGN(NetworkContext);
62 } // namespace mojo
64 #endif // MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_