File: profile_network_context_service.h

package info (click to toggle)
chromium 73.0.3683.75-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,792,156 kB
  • sloc: cpp: 13,473,466; ansic: 1,577,080; python: 898,539; javascript: 655,737; xml: 341,883; asm: 306,070; java: 289,969; perl: 80,911; objc: 67,198; sh: 43,184; cs: 27,853; makefile: 12,092; php: 11,064; yacc: 10,373; tcl: 8,875; ruby: 3,941; lex: 1,800; pascal: 1,473; lisp: 812; awk: 41; jsp: 39; sed: 19; sql: 3
file content (158 lines) | stat: -rw-r--r-- 6,534 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_NET_PROFILE_NETWORK_CONTEXT_SERVICE_H_
#define CHROME_BROWSER_NET_PROFILE_NETWORK_CONTEXT_SERVICE_H_

#include <utility>

#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/timer/timer.h"
#include "chrome/browser/net/proxy_config_monitor.h"
#include "components/content_settings/core/browser/content_settings_observer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_member.h"
#include "services/network/public/mojom/network_context.mojom.h"

class Profile;

namespace user_prefs {
class PrefRegistrySyncable;
}

// KeyedService that initializes and provides access to the NetworkContexts for
// a Profile. This will eventually replace ProfileIOData.
class ProfileNetworkContextService : public KeyedService,
                                     public content_settings::Observer {
 public:
  explicit ProfileNetworkContextService(Profile* profile);
  ~ProfileNetworkContextService() override;

  // Creates a NetworkContext for the BrowserContext, using the specified
  // parameters. An empty |relative_partition_path| corresponds to the main
  // network context.
  //
  // Uses the network service if enabled. Otherwise creates one that will use
  // the IOThread's NetworkService. This may be called either before or after
  // SetUpProfileIODataNetworkContext.
  network::mojom::NetworkContextPtr CreateNetworkContext(
      bool in_memory,
      const base::FilePath& relative_partition_path);

  // Initializes |*network_context_params| to set up the ProfileIOData's
  // main URLRequestContext and |*network_context_request| to be one end of a
  // Mojo pipe to be bound to the NetworkContext for that URLRequestContext.
  // The caller will need to send these parameters to the IOThread's in-process
  // NetworkService.
  //
  // If the network service is disabled, CreateNetworkContext(), which is called
  // first, will return the other end of the pipe.  In this case, all requests
  // associated with this Profile will use the associated URLRequestContext
  // (either accessed through the StoragePartition's GetURLRequestContext() or
  // directly).
  //
  // If the network service is enabled, CreateNetworkContext() will instead
  // return a NetworkContext vended by the network service's NetworkService
  // (Instead of the IOThread's in-process one).  In this case, the
  // ProfileIOData's URLRequest context will be configured not to use on-disk
  // storage (so as not to conflict with the network service vended context),
  // and will only be used for legacy requests that use it directly.
  void SetUpProfileIODataNetworkContext(
      bool in_memory,
      const base::FilePath& relative_partition_path,
      network::mojom::NetworkContextRequest* network_context_request,
      network::mojom::NetworkContextParamsPtr* network_context_params);

#if defined(OS_CHROMEOS)
  void UpdateAdditionalCertificates(
      const net::CertificateList& all_additional_certificates,
      const net::CertificateList& trust_anchors);
#endif

  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);

  // Flushes all pending proxy configuration changes.
  void FlushProxyConfigMonitorForTesting();

  static void SetDiscardDomainReliabilityUploadsForTesting(bool value);

 private:
  // Checks |quic_allowed_|, and disables QUIC if needed.
  void DisableQuicIfNotAllowed();

  // Forwards changes to |pref_accept_language_| to the NetworkContext, after
  // formatting them as appropriate.
  void UpdateAcceptLanguage();

  // Forwards changes to |block_third_party_cookies_| to the NetworkContext.
  void UpdateBlockThirdPartyCookies();

  // Computes appropriate value of Accept-Language header based on
  // |pref_accept_language_|
  std::string ComputeAcceptLanguage() const;

  void UpdateReferrersEnabled();

  // Update the CTPolicy for the given NetworkContexts.
  void UpdateCTPolicyForContexts(
      const std::vector<network::mojom::NetworkContext*>& contexts);

  // Update the CTPolicy for the all of profiles_'s NetworkContexts.
  void UpdateCTPolicy();

  void ScheduleUpdateCTPolicy();

  // Creates parameters for the NetworkContext. Use |in_memory| instead of
  // |profile_->IsOffTheRecord()| because sometimes normal profiles want off the
  // record partitions (e.g. for webview tag).
  network::mojom::NetworkContextParamsPtr CreateNetworkContextParams(
      bool in_memory,
      const base::FilePath& relative_partition_path);

  // Returns the path for a given storage partition.
  base::FilePath GetPartitionPath(
      const base::FilePath& relative_partition_path);

  // content_settings::Observer:
  void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern,
                               const ContentSettingsPattern& secondary_pattern,
                               ContentSettingsType content_type,
                               const std::string& resource_identifier) override;

  Profile* const profile_;

  ProxyConfigMonitor proxy_config_monitor_;

  // The |in_memory| / |relative_partition_path| corresponding to the values
  // passed into CreateNetworkContext.
  using PartitionInfo = std::pair<bool, base::FilePath>;

  // These are the NetworkContext interfaces that use the ProfileIOData's
  // NetworkContexts. If the network service is disabled, ownership is passed to
  // StoragePartition when CreateNetworkContext is called.  Otherwise, retains
  // ownership, though nothing uses these after construction.
  std::map<PartitionInfo, network::mojom::NetworkContextPtr>
      profile_io_data_network_contexts_;

  // Request corresponding to |profile_io_data_main_network_context_|. Ownership
  // is passed to ProfileIOData when SetUpProfileIODataNetworkContext() is
  // called.
  std::map<PartitionInfo, network::mojom::NetworkContextRequest>
      profile_io_data_context_requests_;

  BooleanPrefMember quic_allowed_;
  StringPrefMember pref_accept_language_;
  BooleanPrefMember block_third_party_cookies_;
  BooleanPrefMember enable_referrers_;
  PrefChangeRegistrar pref_change_registrar_;

  // Used to post schedule CT policy updates
  base::OneShotTimer ct_policy_update_timer_;

  DISALLOW_COPY_AND_ASSIGN(ProfileNetworkContextService);
};

#endif  // CHROME_BROWSER_NET_PROFILE_NETWORK_CONTEXT_SERVICE_H_