1 // Copyright 2019 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.
4 
5 #ifndef CONTENT_BROWSER_NETWORK_SERVICE_INSTANCE_IMPL_H_
6 #define CONTENT_BROWSER_NETWORK_SERVICE_INSTANCE_IMPL_H_
7 
8 #include "base/callback.h"
9 #include "base/callback_list.h"
10 #include "content/common/content_export.h"
11 
12 namespace content {
13 
14 // Creates the network::NetworkService object on the IO thread directly instead
15 // of trying to go through the ServiceManager.
16 CONTENT_EXPORT void ForceCreateNetworkServiceDirectlyForTesting();
17 
18 // Resets the interface ptr to the network service.
19 CONTENT_EXPORT void ResetNetworkServiceForTesting();
20 
21 // Registers |handler| to run (on UI thread) after mojo::Remote<NetworkService>
22 // encounters an error.  Note that there are no ordering guarantees wrt error
23 // handlers for other interfaces (e.g. mojo::Remote<NetworkContext> and/or
24 // mojo::Remote<URLLoaderFactory>).
25 //
26 // Can only be called on the UI thread.  No-op if NetworkService is disabled.
27 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void()>::Subscription>
28 RegisterNetworkServiceCrashHandler(base::RepeatingClosure handler);
29 
30 // Corresponds to the "NetworkServiceAvailability" histogram enumeration type in
31 // src/tools/metrics/histograms/enums.xml.
32 //
33 // DO NOT REORDER OR CHANGE THE MEANING OF THESE VALUES.
34 enum class NetworkServiceAvailability {
35   AVAILABLE = 0,
36   NOT_CREATED = 1,
37   NOT_BOUND = 2,
38   ENCOUNTERED_ERROR = 3,
39   NOT_RESPONDING = 4,
40   kMaxValue = NOT_RESPONDING
41 };
42 
43 constexpr char kSSLKeyLogFileHistogram[] = "Net.SSLKeyLogFileUse";
44 
45 // These values are persisted to logs. Entries should not be renumbered and
46 // numeric values should never be reused.
47 enum class SSLKeyLogFileAction {
48   kLogFileEnabled = 0,
49   kSwitchFound = 1,
50   kEnvVarFound = 2,
51   kMaxValue = kEnvVarFound,
52 };
53 
54 // TODO(http://crbug.com/934317): Remove these when done debugging renderer
55 // hangs.
56 CONTENT_EXPORT NetworkServiceAvailability GetNetworkServiceAvailability();
57 CONTENT_EXPORT base::TimeDelta GetTimeSinceLastNetworkServiceCrash();
58 CONTENT_EXPORT void PingNetworkService(base::OnceClosure closure);
59 
60 // Shuts down the in-process network service or disconnects from the out-of-
61 // process one, allowing it to shut down.
62 CONTENT_EXPORT void ShutDownNetworkService();
63 
64 }  // namespace content
65 
66 #endif  // CONTENT_BROWSER_NETWORK_SERVICE_INSTANCE_IMPL_H_
67