1 // Copyright 2020 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 CHROME_BROWSER_CHROMEOS_NET_NETWORK_DIAGNOSTICS_DNS_RESOLVER_PRESENT_ROUTINE_H_
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_DIAGNOSTICS_DNS_RESOLVER_PRESENT_ROUTINE_H_
7 
8 #include <vector>
9 
10 #include "base/callback.h"
11 #include "chrome/browser/chromeos/net/network_diagnostics/network_diagnostics_routine.h"
12 #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
13 #include "mojo/public/cpp/bindings/remote.h"
14 
15 namespace chromeos {
16 namespace network_diagnostics {
17 
18 // Tests whether the current network is set up correctly for performing DNS
19 // resolution.
20 class DnsResolverPresentRoutine : public NetworkDiagnosticsRoutine {
21  public:
22   using DnsResolverPresentRoutineCallback =
23       mojom::NetworkDiagnosticsRoutines::DnsResolverPresentCallback;
24 
25   DnsResolverPresentRoutine();
26   DnsResolverPresentRoutine(const DnsResolverPresentRoutine&) = delete;
27   DnsResolverPresentRoutine& operator=(const DnsResolverPresentRoutine&) =
28       delete;
29   ~DnsResolverPresentRoutine() override;
30 
31   // NetworkDiagnosticsRoutine:
32   bool CanRun() override;
33   void AnalyzeResultsAndExecuteCallback() override;
34 
35   // Run the core logic of this routine. Set |callback| to
36   // |routine_completed_callback_|, which is to be executed in
37   // AnalyzeResultsAndExecuteCallback().
38   void RunRoutine(DnsResolverPresentRoutineCallback callback);
39 
40  private:
41   void FetchActiveNetworks();
42   void FetchManagedProperties(const std::string& guid);
43   void OnManagedPropertiesReceived(
44       chromeos::network_config::mojom::ManagedPropertiesPtr managed_properties);
45   void OnNetworkStateListReceived(
46       std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
47           networks);
48 
49   bool name_servers_found_ = false;
50   bool non_empty_name_servers_ = false;
51   bool well_formed_name_servers_ = false;
52   std::vector<mojom::DnsResolverPresentProblem> problems_;
53   mojo::Remote<chromeos::network_config::mojom::CrosNetworkConfig>
54       remote_cros_network_config_;
55   DnsResolverPresentRoutineCallback routine_completed_callback_;
56 };
57 
58 }  // namespace network_diagnostics
59 }  // namespace chromeos
60 
61 #endif  // CHROME_BROWSER_CHROMEOS_NET_NETWORK_DIAGNOSTICS_DNS_RESOLVER_PRESENT_ROUTINE_H_
62