Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mojo / services / network / network_context.h
blob07a99cf30a9a3970231a4d2993f104ca019fb71d
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/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/sequenced_task_runner.h"
15 namespace base {
16 class FilePath;
19 namespace net {
20 class URLRequestContext;
23 namespace mojo {
24 class URLLoader;
25 class URLLoaderImpl;
26 class NetworkServiceDelegate;
28 class NetworkContext {
29 public:
30 explicit NetworkContext(
31 scoped_ptr<net::URLRequestContext> url_request_context);
32 NetworkContext(
33 const base::FilePath& base_path,
34 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
35 NetworkServiceDelegate* delegate);
36 ~NetworkContext();
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
43 // destroyed.
44 void RegisterURLLoader(URLLoaderImpl* url_loader);
45 void DeregisterURLLoader(URLLoaderImpl* url_loader);
47 private:
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);
56 class MojoNetLog;
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()).
68 bool in_shutdown_;
70 DISALLOW_COPY_AND_ASSIGN(NetworkContext);
73 } // namespace mojo
75 #endif // MOJO_SERVICES_NETWORK_NETWORK_CONTEXT_H_