Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_NETWORK_SERVICE_INSTANCE_IMPL_H_ |
| 6 | #define CONTENT_BROWSER_NETWORK_SERVICE_INSTANCE_IMPL_H_ |
| 7 | |
Dan McArdle | 0c085b2 | 2024-07-12 14:15:23 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 10 | #include "base/callback_list.h" |
Dan McArdle | 0c085b2 | 2024-07-12 14:15:23 | [diff] [blame] | 11 | #include "base/command_line.h" |
Will Harris | 4c686ec | 2025-08-01 10:51:47 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 13 | #include "base/functional/callback.h" |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 14 | #include "content/common/content_export.h" |
Matt Mueller | f783962 | 2023-11-13 20:23:15 | [diff] [blame] | 15 | #include "mojo/public/cpp/bindings/remote.h" |
| 16 | #include "services/cert_verifier/public/mojom/cert_verifier_service_factory.mojom-forward.h" |
John Abd-El-Malek | f2592db | 2024-02-12 07:20:23 | [diff] [blame] | 17 | #include "services/network/public/mojom/cert_verifier_service_updater.mojom-forward.h" |
Matt Mueller | f783962 | 2023-11-13 20:23:15 | [diff] [blame] | 18 | #include "services/network/public/mojom/network_context.mojom-forward.h" |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 19 | |
| 20 | namespace content { |
| 21 | |
Will Harris | 4c686ec | 2025-08-01 10:51:47 | [diff] [blame] | 22 | // A directory name that is created below the http cache path and passed to the |
| 23 | // network context when creating a network context with cache enabled. |
| 24 | // This must be a directory below the main cache path so operations such as |
| 25 | // resetting the cache via HttpCacheParams.reset_cache can function correctly |
| 26 | // as they rely on having access to the parent directory of the cache. |
| 27 | inline constexpr base::FilePath::CharType kCacheDataDirectoryName[] = |
| 28 | FILE_PATH_LITERAL("Cache_Data"); |
| 29 | |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 30 | // Creates the network::NetworkService object on the IO thread directly instead |
| 31 | // of trying to go through the ServiceManager. |
Matthew Denton | 09b7b4b5 | 2023-03-28 09:02:49 | [diff] [blame] | 32 | // This also calls ForceInProcessNetworkService(). |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 33 | CONTENT_EXPORT void ForceCreateNetworkServiceDirectlyForTesting(); |
| 34 | |
Will Harris | 66b7f8a | 2025-07-18 17:56:43 | [diff] [blame] | 35 | // Sets whether or not the network service process will crash early in process |
| 36 | // bootstrap, on the next launch, for testing. |
| 37 | CONTENT_EXPORT void SetNetworkServiceCrashOnNextStartupImplForTesting(); |
| 38 | |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 39 | // Resets the interface ptr to the network service. |
| 40 | CONTENT_EXPORT void ResetNetworkServiceForTesting(); |
| 41 | |
Matthew Denton | 095b697 | 2023-11-02 21:56:17 | [diff] [blame] | 42 | using NetworkServiceProcessGoneHandler = |
| 43 | base::RepeatingCallback<void(bool crashed)>; |
| 44 | |
Julie Jeongeun Kim | a3471c6 | 2019-10-15 07:09:24 | [diff] [blame] | 45 | // Registers |handler| to run (on UI thread) after mojo::Remote<NetworkService> |
Matthew Denton | 095b697 | 2023-11-02 21:56:17 | [diff] [blame] | 46 | // encounters an error, in which case `crashed` will be true, or after the |
| 47 | // NetworkService is purposely restarted by the browser, in which case `crashed` |
| 48 | // will be false. Note that there are no ordering guarantees wrt error |
Julie Jeongeun Kim | a3471c6 | 2019-10-15 07:09:24 | [diff] [blame] | 49 | // handlers for other interfaces (e.g. mojo::Remote<NetworkContext> and/or |
Julie Jeongeun Kim | 2811b95 | 2019-10-24 00:36:12 | [diff] [blame] | 50 | // mojo::Remote<URLLoaderFactory>). |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 51 | // |
| 52 | // Can only be called on the UI thread. No-op if NetworkService is disabled. |
Peter Kasting | 7ba9440c | 2020-11-22 01:49:02 | [diff] [blame] | 53 | CONTENT_EXPORT base::CallbackListSubscription |
Matthew Denton | 095b697 | 2023-11-02 21:56:17 | [diff] [blame] | 54 | RegisterNetworkServiceProcessGoneHandler( |
| 55 | NetworkServiceProcessGoneHandler handler); |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 56 | |
Christopher Thompson | 2a4c69e9 | 2019-08-21 16:29:11 | [diff] [blame] | 57 | constexpr char kSSLKeyLogFileHistogram[] = "Net.SSLKeyLogFileUse"; |
| 58 | |
| 59 | // These values are persisted to logs. Entries should not be renumbered and |
| 60 | // numeric values should never be reused. |
| 61 | enum class SSLKeyLogFileAction { |
| 62 | kLogFileEnabled = 0, |
| 63 | kSwitchFound = 1, |
| 64 | kEnvVarFound = 2, |
| 65 | kMaxValue = kEnvVarFound, |
| 66 | }; |
| 67 | |
Ken Rockot | 91216c0f | 2019-10-11 20:38:11 | [diff] [blame] | 68 | // Shuts down the in-process network service or disconnects from the out-of- |
| 69 | // process one, allowing it to shut down. |
| 70 | CONTENT_EXPORT void ShutDownNetworkService(); |
| 71 | |
Matthew Denton | 542c43c | 2023-08-18 07:32:17 | [diff] [blame] | 72 | // `on_restart` will be called at the end of every RestartNetworkService(). |
| 73 | CONTENT_EXPORT void OnRestartNetworkServiceForTesting( |
| 74 | base::RepeatingClosure on_restart); |
| 75 | |
Matt Mueller | f783962 | 2023-11-13 20:23:15 | [diff] [blame] | 76 | // Returns a CertVerifierParams that can be placed into a new |
| 77 | // network::mojom::NetworkContextParams. |
| 78 | // |
| 79 | // Like |GetCertVerifierParams| but the |cert_verifier_updater_remote| pipe |
| 80 | // passed in can be used to update the returned CertVerifierService with new |
| 81 | // verification parameters. |
| 82 | CONTENT_EXPORT network::mojom::CertVerifierServiceRemoteParamsPtr |
| 83 | GetCertVerifierParamsWithUpdater( |
| 84 | cert_verifier::mojom::CertVerifierCreationParamsPtr |
| 85 | cert_verifier_creation_params, |
| 86 | mojo::PendingReceiver<cert_verifier::mojom::CertVerifierServiceUpdater> |
| 87 | cert_verifier_updater_remote); |
| 88 | |
Dan McArdle | 0c085b2 | 2024-07-12 14:15:23 | [diff] [blame] | 89 | CONTENT_EXPORT uint64_t GetNetLogMaximumFileSizeFromCommandLineForTesting( |
| 90 | const base::CommandLine& command_line); |
John Abd-El-Malek | 984dc00 | 2019-05-29 01:26:59 | [diff] [blame] | 91 | } // namespace content |
| 92 | |
| 93 | #endif // CONTENT_BROWSER_NETWORK_SERVICE_INSTANCE_IMPL_H_ |